diff --git a/cli/internal/terraform/terraform/aws/variables.tf b/cli/internal/terraform/terraform/aws/variables.tf index 584c3ddf7e..b554c601e4 100644 --- a/cli/internal/terraform/terraform/aws/variables.tf +++ b/cli/internal/terraform/terraform/aws/variables.tf @@ -5,6 +5,10 @@ variable "name" { condition = length(var.name) <= 10 error_message = "The length of the name of the Constellation must be <= 10 characters" } + validation { + condition = var.name == lower(var.name) + error_message = "The name of the Constellation must be in lowercase" + } } variable "node_groups" { diff --git a/internal/config/config.go b/internal/config/config.go index 1e5711dbe8..8c896583e9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -728,7 +728,7 @@ func (c *Config) Validate(force bool) error { return err } - if err := validate.RegisterTranslation("valid_name", trans, registerValidateNameError, c.translateValidateNameError); err != nil { + if err := validate.RegisterTranslation("valid_name", trans, c.registerValidateNameError, c.translateValidateNameError); err != nil { return err } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 5def7e9753..678730f71b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -421,6 +421,16 @@ func TestValidate(t *testing.T) { wantErr: true, wantErrCount: awsErrCount, }, + "AWS config with upper case name": { + cnf: func() *Config { + cnf := Default() + cnf.RemoveProviderAndAttestationExcept(cloudprovider.AWS) + cnf.Name = "testAWS" + return cnf + }(), + wantErr: true, + wantErrCount: awsErrCount + 1, + }, "AWS config with correct region and zone format": { cnf: func() *Config { cnf := Default() diff --git a/internal/config/validation.go b/internal/config/validation.go index 54289dee0f..35a55727fd 100644 --- a/internal/config/validation.go +++ b/internal/config/validation.go @@ -711,7 +711,10 @@ func returnsTrue(_ validator.FieldLevel) bool { return true } -func registerValidateNameError(ut ut.Translator) error { +func (c *Config) registerValidateNameError(ut ut.Translator) error { + if c.Provider.AWS != nil { + return ut.Add("validate_name", "{0} must be no more than {1} characters long and contain only lowercase letters", true) + } return ut.Add("validate_name", "{0} must be no more than {1} characters long", true) } @@ -731,7 +734,8 @@ func (c *Config) translateValidateNameError(ut ut.Translator, fe validator.Field // This also allows us to eventually add more validation rules for constellation names if necessary. func (c *Config) validateName(fl validator.FieldLevel) bool { if c.Provider.AWS != nil { - return len(fl.Field().String()) <= constants.AWSConstellationNameLength + name := fl.Field().String() + return strings.ToLower(name) == name && len(name) <= constants.AWSConstellationNameLength } return len(fl.Field().String()) <= constants.ConstellationNameLength }