Skip to content

Commit

Permalink
Setup the env var only provider configs for tfclient
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo committed Oct 16, 2024
1 parent 1c6fc07 commit 87965e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
22 changes: 12 additions & 10 deletions internal/meta/base_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,6 @@ func NewBaseMeta(cfg config.CommonConfig) (*baseMeta, error) {
return nil, fmt.Errorf("new resource client")
}

// Consider setting below environment variables via `tf.SetEnv()` once issue https://github.com/hashicorp/terraform-exec/issues/337 is resolved.

// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
// #nosec G104
os.Setenv("AZURE_HTTP_USER_AGENT", cfg.AzureSDKClientOption.Telemetry.ApplicationID)

// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
// #nosec G104
os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false")

outputFileNames := cfg.OutputFileNames
if outputFileNames.TerraformFileName == "" {
outputFileNames.TerraformFileName = "terraform.tf"
Expand Down Expand Up @@ -664,6 +654,18 @@ func (meta *baseMeta) init_notf(ctx context.Context) error {
}

func (meta *baseMeta) init_tf(ctx context.Context) error {
// Consider setting below environment variables via `tf.SetEnv()` once issue https://github.com/hashicorp/terraform-exec/issues/337 is resolved.

// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
// The setting for notf version is done during the tfclient initialization in main function.
// #nosec G104
os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false")

// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
// The setting for notf version is done during the tfclient initialization in main function.
// #nosec G104
os.Setenv("AZURE_HTTP_USER_AGENT", meta.azureSDKClientOpt.Telemetry.ApplicationID)

// Create the import directories per parallelism
if err := meta.initImportDirs(); err != nil {
return err
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,17 @@ func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI,
// Initialize the TFClient
if tfClientPluginPath != "" {
// #nosec G204
cmd := exec.Command(flagset.hflagTFClientPluginPath)
cmd.Env = append(cmd.Env,
// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
// The setting for with_tf version is done during the init_tf function of meta Init phase.
"ARM_PROVIDER_ENHANCED_VALIDATION=false",
// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
// The setting for with_tf version is done during the init_tf function of meta Init phase.
"AZURE_HTTP_USER_AGENT="+cfg.AzureSDKClientOption.Telemetry.ApplicationID,
)
tfc, err := tfclient.New(tfclient.Option{
Cmd: exec.Command(flagset.hflagTFClientPluginPath),
Cmd: cmd,
Logger: slog2hclog.New(cfg.Logger.WithGroup("provider"), nil),
})
if err != nil {
Expand Down

0 comments on commit 87965e4

Please sign in to comment.