Skip to content

Commit 04d0e97

Browse files
authored
Setup the env var only provider configs for tfclient (#566)
1 parent 1c6fc07 commit 04d0e97

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

internal/meta/base_meta.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,6 @@ func NewBaseMeta(cfg config.CommonConfig) (*baseMeta, error) {
173173
return nil, fmt.Errorf("new resource client")
174174
}
175175

176-
// Consider setting below environment variables via `tf.SetEnv()` once issue https://github.com/hashicorp/terraform-exec/issues/337 is resolved.
177-
178-
// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
179-
// #nosec G104
180-
os.Setenv("AZURE_HTTP_USER_AGENT", cfg.AzureSDKClientOption.Telemetry.ApplicationID)
181-
182-
// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
183-
// #nosec G104
184-
os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false")
185-
186176
outputFileNames := cfg.OutputFileNames
187177
if outputFileNames.TerraformFileName == "" {
188178
outputFileNames.TerraformFileName = "terraform.tf"
@@ -664,6 +654,18 @@ func (meta *baseMeta) init_notf(ctx context.Context) error {
664654
}
665655

666656
func (meta *baseMeta) init_tf(ctx context.Context) error {
657+
// Consider setting below environment variables via `tf.SetEnv()` once issue https://github.com/hashicorp/terraform-exec/issues/337 is resolved.
658+
659+
// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
660+
// The setting for notf version is done during the tfclient initialization in main function.
661+
// #nosec G104
662+
os.Setenv("ARM_PROVIDER_ENHANCED_VALIDATION", "false")
663+
664+
// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
665+
// The setting for notf version is done during the tfclient initialization in main function.
666+
// #nosec G104
667+
os.Setenv("AZURE_HTTP_USER_AGENT", meta.azureSDKClientOpt.Telemetry.ApplicationID)
668+
667669
// Create the import directories per parallelism
668670
if err := meta.initImportDirs(); err != nil {
669671
return err

main.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,17 @@ func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI,
705705
// Initialize the TFClient
706706
if tfClientPluginPath != "" {
707707
// #nosec G204
708+
cmd := exec.Command(flagset.hflagTFClientPluginPath)
709+
cmd.Env = append(cmd.Env,
710+
// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
711+
// The setting for with_tf version is done during the init_tf function of meta Init phase.
712+
"ARM_PROVIDER_ENHANCED_VALIDATION=false",
713+
// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
714+
// The setting for with_tf version is done during the init_tf function of meta Init phase.
715+
"AZURE_HTTP_USER_AGENT="+cfg.AzureSDKClientOption.Telemetry.ApplicationID,
716+
)
708717
tfc, err := tfclient.New(tfclient.Option{
709-
Cmd: exec.Command(flagset.hflagTFClientPluginPath),
718+
Cmd: cmd,
710719
Logger: slog2hclog.New(cfg.Logger.WithGroup("provider"), nil),
711720
})
712721
if err != nil {

0 commit comments

Comments
 (0)