diff --git a/.changelog/33662.txt b/.changelog/33662.txt new file mode 100644 index 00000000000..4854a3c349d --- /dev/null +++ b/.changelog/33662.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_cloud9_environment_ec2: Add `ubuntu-22.04-x86_64` and `resolve:ssm:/aws/service/cloud9/amis/ubuntu-22.04-x86_64` as valid values for `image_id` +``` \ No newline at end of file diff --git a/internal/service/cloud9/environment_ec2.go b/internal/service/cloud9/environment_ec2.go index 882ab28940e..086dad1a758 100644 --- a/internal/service/cloud9/environment_ec2.go +++ b/internal/service/cloud9/environment_ec2.go @@ -67,9 +67,11 @@ func ResourceEnvironmentEC2() *schema.Resource { "amazonlinux-1-x86_64", "amazonlinux-2-x86_64", "ubuntu-18.04-x86_64", + "ubuntu-22.04-x86_64", "resolve:ssm:/aws/service/cloud9/amis/amazonlinux-1-x86_64", "resolve:ssm:/aws/service/cloud9/amis/amazonlinux-2-x86_64", "resolve:ssm:/aws/service/cloud9/amis/ubuntu-18.04-x86_64", + "resolve:ssm:/aws/service/cloud9/amis/ubuntu-22.04-x86_64", }, false), }, "instance_type": { diff --git a/internal/service/cloud9/environment_ec2_test.go b/internal/service/cloud9/environment_ec2_test.go index 15437c0f572..a67847b36f7 100644 --- a/internal/service/cloud9/environment_ec2_test.go +++ b/internal/service/cloud9/environment_ec2_test.go @@ -63,6 +63,7 @@ func TestAccCloud9EnvironmentEC2_allFields(t *testing.T) { name2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description1 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) description2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + imageID := "ubuntu-22.04-x86_64" resourceName := "aws_cloud9_environment_ec2.test" resource.ParallelTest(t, resource.TestCase{ @@ -72,17 +73,17 @@ func TestAccCloud9EnvironmentEC2_allFields(t *testing.T) { CheckDestroy: testAccCheckEnvironmentEC2Destroy(ctx), Steps: []resource.TestStep{ { - Config: testAccEnvironmentEC2Config_allFields(rName, name1, description1), + Config: testAccEnvironmentEC2Config_allFields(rName, name1, description1, imageID), Check: resource.ComposeTestCheckFunc( testAccCheckEnvironmentEC2Exists(ctx, resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "automatic_stop_time_minutes", "60"), resource.TestCheckResourceAttr(resourceName, "connection_type", "CONNECT_SSH"), resource.TestCheckResourceAttr(resourceName, "description", description1), - resource.TestCheckResourceAttr(resourceName, "image_id", "amazonlinux-2-x86_64"), + resource.TestCheckResourceAttr(resourceName, "image_id", imageID), resource.TestCheckResourceAttr(resourceName, "instance_type", "t2.micro"), resource.TestCheckResourceAttr(resourceName, "name", name1), resource.TestCheckResourceAttrPair(resourceName, "owner_arn", "aws_iam_user.test", "arn"), - resource.TestCheckResourceAttrPair(resourceName, "subnet_id", "aws_subnet.test", "id"), + resource.TestCheckResourceAttrPair(resourceName, "subnet_id", "aws_subnet.test.0", "id"), resource.TestCheckResourceAttr(resourceName, "type", "ec2"), ), }, @@ -93,7 +94,7 @@ func TestAccCloud9EnvironmentEC2_allFields(t *testing.T) { ImportStateVerifyIgnore: []string{"automatic_stop_time_minutes", "image_id", "instance_type", "subnet_id"}, }, { - Config: testAccEnvironmentEC2Config_allFields(rName, name2, description2), + Config: testAccEnvironmentEC2Config_allFields(rName, name2, description2, imageID), Check: resource.ComposeTestCheckFunc( testAccCheckEnvironmentEC2Exists(ctx, resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "description", description2), @@ -228,26 +229,8 @@ func testAccCheckEnvironmentEC2Destroy(ctx context.Context) resource.TestCheckFu } } -func testAccEnvironmentEC2BaseConfig(rName string) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptInDefaultExclude(), fmt.Sprintf(` -resource "aws_vpc" "test" { - cidr_block = "10.0.0.0/16" - - tags = { - Name = %[1]q - } -} - -resource "aws_subnet" "test" { - availability_zone = data.aws_availability_zones.available.names[0] - cidr_block = "10.0.0.0/24" - vpc_id = aws_vpc.test.id - - tags = { - Name = %[1]q - } -} - +func testAccEnvironmentEC2Config_base(rName string) string { + return acctest.ConfigCompose(acctest.ConfigVPCWithSubnets(rName, 1), fmt.Sprintf(` resource "aws_internet_gateway" "test" { vpc_id = aws_vpc.test.id @@ -265,40 +248,40 @@ resource "aws_route" "test" { } func testAccEnvironmentEC2Config_basic(rName string) string { - return acctest.ConfigCompose(testAccEnvironmentEC2BaseConfig(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccEnvironmentEC2Config_base(rName), fmt.Sprintf(` resource "aws_cloud9_environment_ec2" "test" { instance_type = "t2.micro" name = %[1]q - subnet_id = aws_subnet.test.id + subnet_id = aws_subnet.test[0].id } `, rName)) } -func testAccEnvironmentEC2Config_allFields(rName, name, description string) string { - return acctest.ConfigCompose(testAccEnvironmentEC2BaseConfig(rName), fmt.Sprintf(` +func testAccEnvironmentEC2Config_allFields(rName, name, description, imageID string) string { + return acctest.ConfigCompose(testAccEnvironmentEC2Config_base(rName), fmt.Sprintf(` resource "aws_cloud9_environment_ec2" "test" { automatic_stop_time_minutes = 60 description = %[2]q instance_type = "t2.micro" name = %[1]q owner_arn = aws_iam_user.test.arn - subnet_id = aws_subnet.test.id + subnet_id = aws_subnet.test[0].id connection_type = "CONNECT_SSH" - image_id = "amazonlinux-2-x86_64" + image_id = %[4]q } resource "aws_iam_user" "test" { name = %[3]q } -`, name, description, rName)) +`, name, description, rName, imageID)) } func testAccEnvironmentEC2Config_tags1(rName, tagKey1, tagValue1 string) string { - return acctest.ConfigCompose(testAccEnvironmentEC2BaseConfig(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccEnvironmentEC2Config_base(rName), fmt.Sprintf(` resource "aws_cloud9_environment_ec2" "test" { instance_type = "t2.micro" name = %[1]q - subnet_id = aws_subnet.test.id + subnet_id = aws_subnet.test[0].id tags = { %[2]q = %[3]q @@ -308,11 +291,11 @@ resource "aws_cloud9_environment_ec2" "test" { } func testAccEnvironmentEC2Config_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return acctest.ConfigCompose(testAccEnvironmentEC2BaseConfig(rName), fmt.Sprintf(` + return acctest.ConfigCompose(testAccEnvironmentEC2Config_base(rName), fmt.Sprintf(` resource "aws_cloud9_environment_ec2" "test" { instance_type = "t2.micro" name = %[1]q - subnet_id = aws_subnet.test.id + subnet_id = aws_subnet.test[0].id tags = { %[2]q = %[3]q diff --git a/website/docs/r/cloud9_environment_ec2.html.markdown b/website/docs/r/cloud9_environment_ec2.html.markdown index 7d4492d35f4..406be47d2df 100644 --- a/website/docs/r/cloud9_environment_ec2.html.markdown +++ b/website/docs/r/cloud9_environment_ec2.html.markdown @@ -79,9 +79,12 @@ This resource supports the following arguments: * `amazonlinux-1-x86_64` * `amazonlinux-2-x86_64` * `ubuntu-18.04-x86_64` + * `ubuntu-22.04-x86_64` * `resolve:ssm:/aws/service/cloud9/amis/amazonlinux-1-x86_64` * `resolve:ssm:/aws/service/cloud9/amis/amazonlinux-2-x86_64` * `resolve:ssm:/aws/service/cloud9/amis/ubuntu-18.04-x86_64` + * `resolve:ssm:/aws/service/cloud9/amis/ubuntu-22.04-x86_64` + * `owner_arn` - (Optional) The ARN of the environment owner. This can be ARN of any AWS IAM principal. Defaults to the environment's creator. * `subnet_id` - (Optional) The ID of the subnet in Amazon VPC that AWS Cloud9 will use to communicate with the Amazon EC2 instance. * `tags` - (Optional) Key-value map of resource tags. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.