2021-09-09 01:02:25 +02:00
package cloud
import (
2021-09-13 21:18:32 +02:00
"fmt"
2021-09-29 23:55:43 +02:00
"strings"
2021-09-13 21:18:32 +02:00
2021-09-09 01:02:25 +02:00
"github.com/hashicorp/terraform/internal/tfdiags"
"github.com/zclconf/go-cty/cty"
)
var (
invalidOrganizationConfigMissingValue = tfdiags . AttributeValue (
tfdiags . Error ,
"Invalid organization value" ,
2021-09-13 21:18:32 +02:00
` The "organization" attribute value must not be empty.\n\n%s ` ,
2021-09-09 01:02:25 +02:00
cty . Path { cty . GetAttrStep { Name : "organization" } } ,
)
invalidWorkspaceConfigMissingValues = tfdiags . AttributeValue (
tfdiags . Error ,
"Invalid workspaces configuration" ,
2021-10-11 23:26:07 +02:00
fmt . Sprintf ( "Missing workspace mapping strategy. Either workspace \"tags\" or \"name\" is required.\n\n%s" , workspaceConfigurationHelp ) ,
2021-09-09 01:02:25 +02:00
cty . Path { cty . GetAttrStep { Name : "workspaces" } } ,
)
invalidWorkspaceConfigMisconfiguration = tfdiags . AttributeValue (
tfdiags . Error ,
"Invalid workspaces configuration" ,
2021-10-11 23:26:07 +02:00
fmt . Sprintf ( "Only one of workspace \"tags\" or \"name\" is allowed.\n\n%s" , workspaceConfigurationHelp ) ,
2021-09-09 01:02:25 +02:00
cty . Path { cty . GetAttrStep { Name : "workspaces" } } ,
)
)
2021-09-29 23:55:43 +02:00
2021-10-13 02:59:56 +02:00
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."
2021-09-29 23:55:43 +02:00
2021-10-13 02:59:56 +02:00
func incompatibleWorkspaceTerraformVersion ( message string , ignoreVersionConflict bool ) tfdiags . Diagnostic {
2021-09-29 23:55:43 +02:00
severity := tfdiags . Error
2021-10-13 02:59:56 +02:00
suggestion := ignoreRemoteVersionHelp
2021-09-29 23:55:43 +02:00
if ignoreVersionConflict {
severity = tfdiags . Warning
suggestion = ""
}
2021-10-13 02:59:56 +02:00
description := strings . TrimSpace ( fmt . Sprintf ( "%s\n\n%s" , message , suggestion ) )
return tfdiags . Sourceless ( severity , "Incompatible Terraform version" , description )
2021-09-29 23:55:43 +02:00
}