github.com/opentofu/opentofu@v1.7.1/internal/cloud/errors.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package cloud 7 8 import ( 9 "errors" 10 "fmt" 11 "strings" 12 13 "github.com/opentofu/opentofu/internal/tfdiags" 14 "github.com/zclconf/go-cty/cty" 15 ) 16 17 // String based errors 18 var ( 19 errApplyDiscarded = errors.New("Apply discarded.") 20 errDestroyDiscarded = errors.New("Destroy discarded.") 21 errRunApproved = errors.New("approved using the UI or API") 22 errRunDiscarded = errors.New("discarded using the UI or API") 23 errRunOverridden = errors.New("overridden using the UI or API") 24 errApplyNeedsUIConfirmation = errors.New("Cannot confirm apply due to -input=false. Please handle run confirmation in the UI.") 25 errPolicyOverrideNeedsUIConfirmation = errors.New("Cannot override soft failed policy checks when -input=false. Please open the run in the UI to override.") 26 ) 27 28 // Diagnostic error messages 29 var ( 30 invalidWorkspaceConfigMissingValues = tfdiags.AttributeValue( 31 tfdiags.Error, 32 "Invalid workspaces configuration", 33 fmt.Sprintf("Missing workspace mapping strategy. Either workspace \"tags\" or \"name\" is required.\n\n%s", workspaceConfigurationHelp), 34 cty.Path{cty.GetAttrStep{Name: "workspaces"}}, 35 ) 36 37 invalidWorkspaceConfigMisconfiguration = tfdiags.AttributeValue( 38 tfdiags.Error, 39 "Invalid workspaces configuration", 40 fmt.Sprintf("Only one of workspace \"tags\" or \"name\" is allowed.\n\n%s", workspaceConfigurationHelp), 41 cty.Path{cty.GetAttrStep{Name: "workspaces"}}, 42 ) 43 44 invalidWorkspaceConfigMisconfigurationEnvVar = tfdiags.AttributeValue( 45 tfdiags.Error, 46 "Invalid workspaces configuration", 47 fmt.Sprintf("The workspace defined using the environment variable \"TF_WORKSPACE\" does not belong to \"tags\".\n\n%s", workspaceConfigurationHelp), 48 cty.Path{cty.GetAttrStep{Name: "workspaces"}}, 49 ) 50 ) 51 52 const ignoreRemoteVersionHelp = "If you're sure you want to upgrade the state, you can force OpenTofu to continue using the -ignore-remote-version flag. This may result in an unusable workspace." 53 54 func missingConfigAttributeAndEnvVar(attribute string, envVar string) tfdiags.Diagnostic { 55 detail := strings.TrimSpace(fmt.Sprintf("\"%s\" must be set in the cloud configuration or as an environment variable: %s.\n", attribute, envVar)) 56 return tfdiags.AttributeValue( 57 tfdiags.Error, 58 "Invalid or missing required argument", 59 detail, 60 cty.Path{cty.GetAttrStep{Name: attribute}}) 61 } 62 63 func incompatibleWorkspaceTerraformVersion(message string, ignoreVersionConflict bool) tfdiags.Diagnostic { 64 severity := tfdiags.Error 65 suggestion := ignoreRemoteVersionHelp 66 if ignoreVersionConflict { 67 severity = tfdiags.Warning 68 suggestion = "" 69 } 70 description := strings.TrimSpace(fmt.Sprintf("%s\n\n%s", message, suggestion)) 71 return tfdiags.Sourceless(severity, "Incompatible TF version", description) 72 }