Skip to content

Commit

Permalink
service/ec2: AMI throughput handling (#16631)
Browse files Browse the repository at this point in the history
Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAWSAMI_basic (64.21s)
--- PASS: TestAccAWSAMI_description (76.85s)
--- PASS: TestAccAWSAMI_disappears (60.98s)
--- PASS: TestAccAWSAMI_EphemeralBlockDevices (64.91s)
--- PASS: TestAccAWSAMI_Gp3BlockDevice (48.76s)
--- PASS: TestAccAWSAMI_tags (73.71s)

--- PASS: TestAccAWSAMICopy_basic (378.01s)
--- PASS: TestAccAWSAMICopy_Description (391.97s)
--- PASS: TestAccAWSAMICopy_EnaSupport (377.97s)
--- PASS: TestAccAWSAMICopy_tags (404.08s)

--- PASS: TestAccAWSAmiDataSource_Gp3BlockDevice (48.44s)
--- PASS: TestAccAWSAmiDataSource_instanceStore (27.12s)
--- PASS: TestAccAWSAmiDataSource_localNameFilter (30.76s)
--- PASS: TestAccAWSAmiDataSource_natInstance (26.80s)
--- PASS: TestAccAWSAmiDataSource_windowsInstance (28.30s)

--- PASS: TestAccAWSAMIFromInstance_basic (444.76s)
--- PASS: TestAccAWSAMIFromInstance_tags (294.34s)

--- PASS: TestAccAWSAMILaunchPermission_basic (344.81s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_AMI (359.20s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_LaunchPermission (336.46s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_LaunchPermission_Public (348.74s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAWSAMI_basic (68.61s)
--- PASS: TestAccAWSAMI_description (76.31s)
--- PASS: TestAccAWSAMI_disappears (65.32s)
--- PASS: TestAccAWSAMI_EphemeralBlockDevices (69.63s)
--- PASS: TestAccAWSAMI_Gp3BlockDevice (67.43s)
--- PASS: TestAccAWSAMI_tags (99.68s)

--- PASS: TestAccAWSAMICopy_basic (391.97s)
--- PASS: TestAccAWSAMICopy_Description (409.20s)
--- PASS: TestAccAWSAMICopy_EnaSupport (392.72s)
--- PASS: TestAccAWSAMICopy_tags (413.77s)

--- PASS: TestAccAWSAmiDataSource_Gp3BlockDevice (67.39s)
--- PASS: TestAccAWSAmiDataSource_instanceStore (27.26s)
--- PASS: TestAccAWSAmiDataSource_localNameFilter (30.92s)
--- PASS: TestAccAWSAmiDataSource_natInstance (27.50s)
--- PASS: TestAccAWSAmiDataSource_windowsInstance (27.77s)

--- PASS: TestAccAWSAMIFromInstance_basic (255.31s)
--- PASS: TestAccAWSAMIFromInstance_tags (359.49s)

--- PASS: TestAccAWSAMILaunchPermission_basic (356.36s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_AMI (371.79s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_LaunchPermission (354.32s)
--- PASS: TestAccAWSAMILaunchPermission_Disappears_LaunchPermission_Public (353.67s)
```
  • Loading branch information
ewbankkit authored Jan 19, 2021
1 parent 3942716 commit 59d3866
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 194 deletions.
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

0 comments on commit 59d3866

Please sign in to comment.