Skip to content

Commit

Permalink
migrate terraform provider
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Feb 12, 2024
1 parent 0809aaf commit 8243495
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
7 changes: 2 additions & 5 deletions providers/terraform/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclparse"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
)

type ConnectionType string
Expand All @@ -15,7 +16,7 @@ type ConnectionType string
// - https://www.terraform.io/docs/language/syntax/configuration.html
// - https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md
type Connection struct {
id uint32
plugin.Connection
name string
asset *inventory.Asset
platformID string
Expand Down Expand Up @@ -46,10 +47,6 @@ func (c *Connection) Asset() *inventory.Asset {
return c.asset
}

func (c *Connection) ID() uint32 {
return c.id
}

func (c *Connection) Name() string {
return c.name
}
Expand Down
7 changes: 4 additions & 3 deletions providers/terraform/connection/hcl_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/vault"
)

Expand Down Expand Up @@ -133,9 +134,9 @@ func newHclConnection(id uint32, path string, asset *inventory.Asset) (*Connecti
}

return &Connection{
id: id,
asset: asset,
assetType: assetType,
Connection: plugin.NewConnection(id, asset),
asset: asset,
assetType: assetType,

parsed: loader.GetParser(),
tfVars: tfVars,
Expand Down
7 changes: 4 additions & 3 deletions providers/terraform/connection/tfplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
)

type Plan struct {
Expand Down Expand Up @@ -214,9 +215,9 @@ func NewPlanConnection(id uint32, asset *inventory.Asset) (*Connection, error) {
}

return &Connection{
id: id,
asset: asset,
assetType: assetType,
Connection: plugin.NewConnection(id, asset),
asset: asset,
assetType: assetType,

plan: &tfPlan,
}, nil
Expand Down
7 changes: 4 additions & 3 deletions providers/terraform/connection/tfstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/rs/zerolog/log"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
)

// This is designed around https://www.terraform.io/internals/json-format
Expand Down Expand Up @@ -101,9 +102,9 @@ func NewStateConnection(id uint32, asset *inventory.Asset) (*Connection, error)
}

return &Connection{
id: id,
asset: asset,
assetType: assetType,
Connection: plugin.NewConnection(id, asset),
asset: asset,
assetType: assetType,

state: &tfState,
}, nil
Expand Down
19 changes: 9 additions & 10 deletions providers/terraform/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,15 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba
}

asset.Connections[0].Id = conn.ID()
return &plugin.Runtime{
Connection: conn,
Callback: callback,
HasRecording: req.HasRecording,
CreateResource: resources.CreateResource,
NewResource: resources.NewResource,
GetData: resources.GetData,
SetData: resources.SetData,
Upstream: upstream,
}, nil
return plugin.NewRuntime(
conn,
callback,
req.HasRecording,
resources.CreateResource,
resources.NewResource,
resources.GetData,
resources.SetData,
upstream), nil
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 8243495

Please sign in to comment.