Skip to content

Commit

Permalink
Integrate with terraform-client-go for hcl only mode to eliminate `te…
Browse files Browse the repository at this point in the history
…rraform` binary (#381)

* Integrate with terraform-client-go for hcl only mode to eliminate `terraform` binary

Integrate with terraform-client-go for hcl only mode to eliminate `terraform` binary. This improves the performance (quicker speed and lower footprint) of importing.

To use it, users have to explicitly specify a new hidden flag (`--tfclient-plugin-go`). This flag is hidden since it is not supposed for CLI users to use, but is meant to be used by module users who wants to get the benefit of performance improvement.
  • Loading branch information
magodo authored Mar 29, 2023
1 parent 19b00ec commit b794b08
Show file tree
Hide file tree
Showing 11 changed files with 593 additions and 193 deletions.
5 changes: 5 additions & 0 deletions command_before_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func commandBeforeFunc(fset *FlagSet) func(ctx *cli.Context) error {
return fmt.Errorf("`--dev-provider` conflicts with `--provider-version`")
}
}
if fset.hflagTFClientPluginPath != "" {
if !fset.flagHCLOnly {
return fmt.Errorf("`--tfclient-plugin-path` must be used together with `--hcl-only`")
}
}

if flagLogLevel != "" {
if _, err := logLevel(flagLogLevel); err != nil {
Expand Down
11 changes: 7 additions & 4 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ type FlagSet struct {
flagModulePath string

// common flags (hidden)
hflagMockClient bool
hflagPlainUI bool
hflagProfile string
hflagMockClient bool
hflagPlainUI bool
hflagProfile string
hflagTFClientPluginPath string

// Subcommand specific flags
//
Expand Down Expand Up @@ -74,7 +75,6 @@ func (flag FlagSet) DescribeCLI(mode string) string {
if flag.flagEnv != "" {
args = append(args, "--env="+flag.flagEnv)
}

if flag.flagOverwrite {
args = append(args, "--overwrite=true")
}
Expand Down Expand Up @@ -105,6 +105,9 @@ func (flag FlagSet) DescribeCLI(mode string) string {
if flag.flagHCLOnly {
args = append(args, "--hcl-only=true")
}
if flag.hflagTFClientPluginPath != "" {
args = append(args, "--tfclient-plugin-path=%s", flag.hflagTFClientPluginPath)
}
if flag.flagModulePath != "" {
args = append(args, "--module-path="+flag.flagModulePath)
}
Expand Down
35 changes: 25 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ require (
github.com/hashicorp/hcl/v2 v2.13.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20221020162138-81db043ad408
github.com/hashicorp/terraform-exec v0.17.2
github.com/hashicorp/terraform-json v0.16.0
github.com/hexops/gotextdiff v1.0.3
github.com/magodo/armid v0.0.0-20220923023118-aec41eaf7370
github.com/magodo/azlist v0.0.0-20230129022211-862464772b00
github.com/magodo/aztft v0.3.1-0.20230303055806-23bd5ef27605
github.com/magodo/spinner v0.0.0-20220720073946-50f31b2dc5a6
github.com/magodo/terraform-client-go v0.0.0-20230323074119-02ceb732dd25
github.com/magodo/textinput v0.0.0-20210913072708-7d24f2b4b0c0
github.com/magodo/tfadd v0.10.1-0.20230303033832-99f935d1f92e
github.com/magodo/tfadd v0.10.1-0.20230323091655-a101eda67724
github.com/magodo/tfmerge v0.0.0-20221214062955-f52e46d03402
github.com/magodo/tfstate v0.0.0-20220409052014-9b9568dda918
github.com/magodo/workerpool v0.0.0-20230119025400-40192d2716ea
github.com/microsoft/ApplicationInsights-Go v0.4.4
github.com/mitchellh/go-wordwrap v1.0.0
Expand All @@ -34,7 +37,7 @@ require (
github.com/tidwall/gjson v1.14.2
github.com/tidwall/sjson v1.2.5
github.com/urfave/cli/v2 v2.24.1
github.com/zclconf/go-cty v1.11.0
github.com/zclconf/go-cty v1.13.0
)

require (
Expand Down Expand Up @@ -84,36 +87,48 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.8 // indirect
github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.14.3 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magodo/tfpluginschema v0.0.0-20220905090502-2d6a05ebaefd // indirect
github.com/magodo/tfstate v0.0.0-20220409052014-9b9568dda918 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b794b08

Please sign in to comment.