Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup the env var only provider configs for tfclient #566

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading