mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-17 01:00:39 -05:00
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.
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package cloud
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
var (
|
|
invalidWorkspaceConfigMissingValues = tfdiags.AttributeValue(
|
|
tfdiags.Error,
|
|
"Invalid workspaces configuration",
|
|
fmt.Sprintf("Missing workspace mapping strategy. Either workspace \"tags\" or \"name\" is required.\n\n%s", workspaceConfigurationHelp),
|
|
cty.Path{cty.GetAttrStep{Name: "workspaces"}},
|
|
)
|
|
|
|
invalidWorkspaceConfigMisconfiguration = tfdiags.AttributeValue(
|
|
tfdiags.Error,
|
|
"Invalid workspaces configuration",
|
|
fmt.Sprintf("Only one of workspace \"tags\" or \"name\" is allowed.\n\n%s", workspaceConfigurationHelp),
|
|
cty.Path{cty.GetAttrStep{Name: "workspaces"}},
|
|
)
|
|
)
|
|
|
|
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
|
|
if ignoreVersionConflict {
|
|
severity = tfdiags.Warning
|
|
suggestion = ""
|
|
}
|
|
description := strings.TrimSpace(fmt.Sprintf("%s\n\n%s", message, suggestion))
|
|
return tfdiags.Sourceless(severity, "Incompatible Terraform version", description)
|
|
}
|