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

aws_ami: gp3 volume scalable throughtput #16631

Merged
merged 8 commits into from
Jan 19, 2021
1 change: 1 addition & 0 deletions aws/data_source_aws_ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func amiBlockDeviceMappings(m []*ec2.BlockDeviceMapping) *schema.Set {
"delete_on_termination": fmt.Sprintf("%t", aws.BoolValue(v.Ebs.DeleteOnTermination)),
"encrypted": fmt.Sprintf("%t", aws.BoolValue(v.Ebs.Encrypted)),
"iops": fmt.Sprintf("%d", aws.Int64Value(v.Ebs.Iops)),
"throughput": fmt.Sprintf("%d", aws.Int64Value(v.Ebs.Throughput)),
"volume_size": fmt.Sprintf("%d", aws.Int64Value(v.Ebs.VolumeSize)),
"snapshot_id": aws.StringValue(v.Ebs.SnapshotId),
"volume_type": aws.StringValue(v.Ebs.VolumeType),
Expand Down
50 changes: 50 additions & 0 deletions aws/data_source_aws_ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand Down Expand Up @@ -55,6 +56,7 @@ func TestAccAWSAmiDataSource_natInstance(t *testing.T) {
},
})
}

func TestAccAWSAmiDataSource_windowsInstance(t *testing.T) {
resourceName := "data.aws_ami.windows_ami"
resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -147,6 +149,37 @@ func TestAccAWSAmiDataSource_localNameFilter(t *testing.T) {
})
}

func TestAccAWSAmiDataSource_Gp3BlockDevice(t *testing.T) {
resourceName := "aws_ami.test"
datasourceName := "data.aws_ami.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAmiDataSourceConfigGp3BlockDevice(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsAmiDataSourceID(datasourceName),
resource.TestCheckResourceAttrPair(datasourceName, "architecture", resourceName, "architecture"),
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(datasourceName, "block_device_mappings.#", resourceName, "ebs_block_device.#"),
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(datasourceName, "image_id", resourceName, "id"),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
resource.TestCheckResourceAttrPair(datasourceName, "root_device_name", resourceName, "root_device_name"),
resource.TestCheckResourceAttr(datasourceName, "root_device_type", "ebs"),
resource.TestCheckResourceAttrPair(datasourceName, "root_snapshot_id", resourceName, "root_snapshot_id"),
resource.TestCheckResourceAttrPair(datasourceName, "sriov_net_support", resourceName, "sriov_net_support"),
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(datasourceName, "virtualization_type", resourceName, "virtualization_type"),
),
},
},
})
}

func testAccCheckAwsAmiDataSourceID(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -234,3 +267,20 @@ data "aws_ami" "name_regex_filtered_ami" {
name_regex = "^amzn-ami-min[a-z]{4}-hvm"
}
`

func testAccAmiDataSourceConfigGp3BlockDevice(rName string) string {
return composeConfig(
testAccAmiConfigGp3BlockDevice(rName),
`
data "aws_caller_identity" "current" {}

data "aws_ami" "test" {
owners = [data.aws_caller_identity.current.account_id]

filter {
name = "image-id"
values = [aws_ami.test.id]
}
}
`)
}
Loading