github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/cloud/errors.go (about) 1 package cloud 2 3 import ( 4 "errors" 5 "fmt" 6 "strings" 7 8 "github.com/hashicorp/terraform/internal/tfdiags" 9 "github.com/zclconf/go-cty/cty" 10 ) 11 12 // String based errors 13 var ( 14 errApplyDiscarded = errors.New("Apply discarded.") 15 errDestroyDiscarded = errors.New("Destroy discarded.") 16 errRunApproved = errors.New("approved using the UI or API") 17 errRunDiscarded = errors.New("discarded using the UI or API") 18 errRunOverridden = errors.New("overridden using the UI or API") 19 errApplyNeedsUIConfirmation = errors.New("Cannot confirm apply due to -input=false. Please handle run confirmation in the UI.") 20 errPolicyOverrideNeedsUIConfirmation = errors.New("Cannot override soft failed policy checks when -input=false. Please open the run in the UI to override.") 21 ) 22 23 // Diagnostic error messages 24 var ( 25 invalidWorkspaceConfigMissingValues = tfdiags.AttributeValue( 26 tfdiags.Error, 27 "Invalid workspaces configuration", 28 fmt.Sprintf("Missing workspace mapping strategy. Either workspace \"tags\" or \"name\" is required.\n\n%s", workspaceConfigurationHelp), 29 cty.Path{cty.GetAttrStep{Name: "workspaces"}}, 30 ) 31 32 invalidWorkspaceConfigMisconfiguration = tfdiags.AttributeValue( 33 tfdiags.Error, 34 "Invalid workspaces configuration", 35 fmt.Sprintf("Only one of workspace \"tags\" or \"name\" is allowed.\n\n%s", workspaceConfigurationHelp), 36 cty.Path{cty.GetAttrStep{Name: "workspaces"}}, 37 ) 38 ) 39 40 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." 41 42 func missingConfigAttributeAndEnvVar(attribute string, envVar string) tfdiags.Diagnostic { 43 detail := strings.TrimSpace(fmt.Sprintf("\"%s\" must be set in the cloud configuration or as an environment variable: %s.\n", attribute, envVar)) 44 return tfdiags.AttributeValue( 45 tfdiags.Error, 46 "Invalid or missing required argument", 47 detail, 48 cty.Path{cty.GetAttrStep{Name: attribute}}) 49 } 50 51 func incompatibleWorkspaceTerraformVersion(message string, ignoreVersionConflict bool) tfdiags.Diagnostic { 52 severity := tfdiags.Error 53 suggestion := ignoreRemoteVersionHelp 54 if ignoreVersionConflict { 55 severity = tfdiags.Warning 56 suggestion = "" 57 } 58 description := strings.TrimSpace(fmt.Sprintf("%s\n\n%s", message, suggestion)) 59 return tfdiags.Sourceless(severity, "Incompatible Terraform version", description) 60 }