From f20b055618f74a4893b4c4aaf58d71eec6b96afa Mon Sep 17 00:00:00 2001 From: Craig Sloggett Date: Mon, 25 Mar 2024 10:57:00 -0400 Subject: [PATCH] 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. --- .../command/cliconfig/provider_installation.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/command/cliconfig/provider_installation.go b/internal/command/cliconfig/provider_installation.go index 40a407d1ec..fb3d2dec27 100644 --- a/internal/command/cliconfig/provider_installation.go +++ b/internal/command/cliconfig/provider_installation.go @@ -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 "" } })