Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aws_lightsail_instance name validation #29903

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/29903.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lightsail_instance: Fix `name` validation to allow instances to start with a numeric character
```
2 changes: 1 addition & 1 deletion internal/service/lightsail/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ResourceInstance() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.All(
validation.StringLenBetween(2, 255),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z]`), "must begin with an alphabetic character"),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9]`), "must begin with an alphanumeric character"),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9_\-.]+[^._\-]$`), "must contain only alphanumeric characters, underscores, hyphens, and dots"),
),
},
Expand Down
25 changes: 18 additions & 7 deletions internal/service/lightsail/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestAccLightsailInstance_name(t *testing.T) {
resourceName := "aws_lightsail_instance.test"
rNameWithSpaces := fmt.Sprint(rName, "string with spaces")
rNameWithStartingDigit := fmt.Sprintf("01-%s", rName)
rNameWithStartingHyphen := fmt.Sprintf("-%s", rName)
rNameWithUnderscore := fmt.Sprintf("%s_123456", rName)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -75,8 +76,18 @@ func TestAccLightsailInstance_name(t *testing.T) {
ExpectError: regexp.MustCompile(`must contain only alphanumeric characters, underscores, hyphens, and dots`),
},
{
Config: testAccInstanceConfig_basic(rNameWithStartingDigit),
ExpectError: regexp.MustCompile(`must begin with an alphabetic character`),
Config: testAccInstanceConfig_basic(rNameWithStartingHyphen),
ExpectError: regexp.MustCompile(`must begin with an alphanumeric character`),
},
{
Config: testAccInstanceConfig_basic(rNameWithStartingDigit),
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckInstanceExists(ctx, resourceName),
resource.TestCheckResourceAttrSet(resourceName, "availability_zone"),
resource.TestCheckResourceAttrSet(resourceName, "blueprint_id"),
resource.TestCheckResourceAttrSet(resourceName, "bundle_id"),
resource.TestCheckResourceAttrSet(resourceName, "key_pair_name"),
),
},
{
Config: testAccInstanceConfig_basic(rName),
Expand Down Expand Up @@ -367,7 +378,7 @@ func testAccInstanceConfig_basic(rName string) string {
resource "aws_lightsail_instance" "test" {
name = "%s"
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
blueprint_id = "amazon_linux_2"
bundle_id = "nano_1_0"
}
`, rName))
Expand All @@ -380,7 +391,7 @@ func testAccInstanceConfig_tags1(rName string) string {
resource "aws_lightsail_instance" "test" {
name = "%s"
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
blueprint_id = "amazon_linux_2"
bundle_id = "nano_1_0"

tags = {
Expand All @@ -398,7 +409,7 @@ func testAccInstanceConfig_tags2(rName string) string {
resource "aws_lightsail_instance" "test" {
name = "%s"
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
blueprint_id = "amazon_linux_2"
bundle_id = "nano_1_0"

tags = {
Expand All @@ -417,7 +428,7 @@ func testAccInstanceConfig_IPAddressType(rName string, rIPAddressType string) st
resource "aws_lightsail_instance" "test" {
name = %[1]q
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
blueprint_id = "amazon_linux_2"
bundle_id = "nano_1_0"
ip_address_type = %[2]q
}
Expand All @@ -431,7 +442,7 @@ func testAccInstanceConfig_addOn(rName string, snapshotTime string, status strin
resource "aws_lightsail_instance" "test" {
name = %[1]q
availability_zone = data.aws_availability_zones.available.names[0]
blueprint_id = "amazon_linux"
blueprint_id = "amazon_linux_2"
bundle_id = "nano_1_0"
add_on {
type = "AutoSnapshot"
Expand Down