Commit b1c22d33 authored by Sebastian Rivera's avatar Sebastian Rivera
Browse files

Fix error formatting for missing env and config value

We previously used to throw an error denoting where in the configuration the attribute was missing or invalid.
Considering that organization can be now be omitted from the configuration, our previous error message will be
improperly formatted. This commit also updates the message to mention `TF_ORGANIZATION` as a valid substitute if
organization is missing or invalid in the configuration.
parent b260883a
No related merge requests found
Showing with 12 additions and 10 deletions
+12 -10
......@@ -157,7 +157,7 @@ func (b *Cloud) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
// organization is specified in the config but is invalid, so
// we'll fallback on TF_ORGANIZATION
if val := os.Getenv("TF_ORGANIZATION"); val == "" {
diags = diags.Append(invalidOrganizationConfigMissingValue)
diags = diags.Append(missingConfigAttributeAndEnvVar("organization", "TF_ORGANIZATION"))
}
}
......
......@@ -86,7 +86,7 @@ func TestCloud_PrepareConfig(t *testing.T) {
"tags": cty.NullVal(cty.Set(cty.String)),
}),
}),
expectedErr: `Invalid organization value: The "organization" attribute value must not be empty.`,
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`,
},
"null workspace": {
config: cty.ObjectVal(map[string]cty.Value{
......@@ -173,7 +173,7 @@ func TestCloud_PrepareConfigWithEnvVars(t *testing.T) {
}),
}),
vars: map[string]string{},
expectedErr: `Invalid organization value: The "organization" attribute value must not be empty.`,
expectedErr: `Invalid or missing required argument: "organization" must be set in the cloud configuration or as an environment variable: TF_ORGANIZATION.`,
},
}
......
......@@ -9,13 +9,6 @@ import (
)
var (
invalidOrganizationConfigMissingValue = tfdiags.AttributeValue(
tfdiags.Error,
"Invalid organization value",
`The "organization" attribute value must not be empty.\n\n%s`,
cty.Path{cty.GetAttrStep{Name: "organization"}},
)
invalidWorkspaceConfigMissingValues = tfdiags.AttributeValue(
tfdiags.Error,
"Invalid workspaces configuration",
......@@ -33,6 +26,15 @@ var (
const ignoreRemoteVersionHelp = "If you're sure you want to upgrade the state, you can force Terraform to continue using the -ignore-remote-version flag. This may result in an unusable workspace."
func missingConfigAttributeAndEnvVar(attribute string, envVar string) tfdiags.Diagnostic {
detail := strings.TrimSpace(fmt.Sprintf("\"%s\" must be set in the cloud configuration or as an environment variable: %s.\n", attribute, envVar))
return tfdiags.AttributeValue(
tfdiags.Error,
"Invalid or missing required argument",
detail,
cty.Path{cty.GetAttrStep{Name: attribute}})
}
func incompatibleWorkspaceTerraformVersion(message string, ignoreVersionConflict bool) tfdiags.Diagnostic {
severity := tfdiags.Error
suggestion := ignoreRemoteVersionHelp
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment