Prevent duplicate error messages for unset environment variables

Track and report each unset environment variable only once, even if it's
referenced multiple times in the Terraform configuration.
pull/34873/head
Craig Sloggett 2 years ago
parent b53db4ef14
commit f20b055618
No known key found for this signature in database
GPG Key ID: 3D5272A2CA547996

@ -254,15 +254,19 @@ func decodeProviderInstallationFromConfig(hclFile *hclast.File) ([]*ProviderInst
))
continue
}
unsetEnvVars := make(map[string]bool)
interpolatedPath := os.Expand(rawPath, func(envVarName string) string {
if value, ok := os.LookupEnv(envVarName); ok {
return value
} else {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Interpolated environment variable not set",
fmt.Sprintf("The environment variable %s is not set or empty and can result in undesired behavior", envVarName),
))
if _, reported := unsetEnvVars[envVarName]; !reported {
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Interpolated environment variable not set",
fmt.Sprintf("The environment variable %s is not set or empty and can result in undesired behavior", envVarName),
))
unsetEnvVars[envVarName] = true
}
return ""
}
})

Loading…
Cancel
Save