mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-03 20:50:59 -05:00
This will be the central location for everything involving combining environment variables with a `cloud` config block to obtain a final cloud config. It returns a plain Go value (so that nothing downstream of it ever needs to mess with Cty types), and doesn't mutate any fields on the backend, so it has a nice firm boundary of responsibilities. Also, it's quite a bit more pedantic and explicit about HOW the environment variables get consulted, in the hope of reducing future misunderstandings about our UI-level expectations.
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package cloud
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
// String based errors
|
|
var (
|
|
errApplyDiscarded = errors.New("Apply discarded.")
|
|
errDestroyDiscarded = errors.New("Destroy discarded.")
|
|
errRunApproved = errors.New("approved using the UI or API")
|
|
errRunDiscarded = errors.New("discarded using the UI or API")
|
|
errRunOverridden = errors.New("overridden using the UI or API")
|
|
errApplyNeedsUIConfirmation = errors.New("Cannot confirm apply due to -input=false. Please handle run confirmation in the UI.")
|
|
errPolicyOverrideNeedsUIConfirmation = errors.New("Cannot override soft failed policy checks when -input=false. Please open the run in the UI to override.")
|
|
)
|
|
|
|
// Diagnostic error messages
|
|
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"}},
|
|
)
|
|
|
|
invalidWorkspaceConfigNameConflict = tfdiags.AttributeValue(
|
|
tfdiags.Error,
|
|
"Invalid workspaces configuration",
|
|
fmt.Sprintf("Specified workspace \"name\" conflicts with TF_WORKSPACE environment variable.\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)
|
|
}
|