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

Adding GP3 support for launch configurations #19632

Merged
merged 4 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .changelog/19632.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_launch_configuration: Add `throughput` argument to `ebs_block_device` and `root_block_device` configuration blocks to support GP3 volumes
```

```release-note:enhancement
data-source/aws_launch_configuration: Add `throughput` attribute to `ebs_block_device` and `root_block_device` configuration blocks to support GP3 volumes
```
22 changes: 16 additions & 6 deletions aws/data_source_aws_launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource {
Computed: true,
},

"no_device": {
"encrypted": {
Type: schema.TypeBool,
Computed: true,
},
Expand All @@ -115,11 +115,21 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource {
Computed: true,
},

"no_device": {
Type: schema.TypeBool,
Computed: true,
},

"snapshot_id": {
Type: schema.TypeString,
Computed: true,
},

"throughput": {
Type: schema.TypeBool,
Computed: true,
},

"volume_size": {
Type: schema.TypeInt,
Computed: true,
Expand All @@ -129,11 +139,6 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"encrypted": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -197,6 +202,11 @@ func dataSourceAwsLaunchConfiguration() *schema.Resource {
Computed: true,
},

"throughput": {
Type: schema.TypeBool,
Computed: true,
},

"volume_size": {
Type: schema.TypeInt,
Computed: true,
Expand Down
8 changes: 8 additions & 0 deletions aws/resource_aws_autoscaling_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ import (
)

func init() {
RegisterServiceErrorCheckFunc(autoscaling.EndpointsID, testAccErrorCheckSkipAutoScaling)

resource.AddTestSweepers("aws_autoscaling_group", &resource.Sweeper{
Name: "aws_autoscaling_group",
F: testSweepAutoscalingGroups,
})
}

func testAccErrorCheckSkipAutoScaling(t *testing.T) resource.ErrorCheckFunc {
return testAccErrorCheckSkipMessagesContaining(t,
"gp3 is invalid",
)
}

func testSweepAutoscalingGroups(region string) error {
client, err := sharedClientForRegion(region)
if err != nil {
Expand Down
37 changes: 31 additions & 6 deletions aws/resource_aws_launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
ForceNew: true,
},

"no_device": {
"encrypted": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},

Expand All @@ -191,29 +192,35 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
ForceNew: true,
},

"no_device": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"snapshot_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"volume_size": {
"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},

"volume_type": {
Type: schema.TypeString,
"volume_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},

"encrypted": {
Type: schema.TypeBool,
"volume_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Expand Down Expand Up @@ -312,6 +319,13 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
ForceNew: true,
},

"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},

"volume_size": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -435,6 +449,10 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
ebs.Iops = aws.Int64(int64(v))
}

if v, ok := bd["throughput"].(int); ok && v > 0 {
ebs.Throughput = aws.Int64(int64(v))
}

if bd["device_name"].(string) == aws.StringValue(rootDeviceName) {
return fmt.Errorf("Root device (%s) declared as an 'ebs_block_device'. Use 'root_block_device' keyword.", *rootDeviceName)
}
Expand Down Expand Up @@ -482,6 +500,10 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
ebs.Iops = aws.Int64(int64(v))
}

if v, ok := bd["throughput"].(int); ok && v > 0 {
ebs.Throughput = aws.Int64(int64(v))
}

if dn, err := fetchRootDeviceName(d.Get("image_id").(string), ec2conn); err == nil {
if dn == nil {
return fmt.Errorf(
Expand Down Expand Up @@ -763,6 +785,9 @@ func readBlockDevicesFromLaunchConfiguration(d *schema.ResourceData, lc *autosca
if bdm.Ebs != nil && bdm.Ebs.Iops != nil {
bd["iops"] = *bdm.Ebs.Iops
}
if bdm.Ebs != nil && bdm.Ebs.Throughput != nil {
bd["throughput"] = *bdm.Ebs.Throughput
}
if bdm.Ebs != nil && bdm.Ebs.Encrypted != nil {
bd["encrypted"] = *bdm.Ebs.Encrypted
}
Expand Down
55 changes: 55 additions & 0 deletions aws/resource_aws_launch_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,38 @@ func TestAccAWSLaunchConfiguration_withEncryption(t *testing.T) {
})
}

func TestAccAWSLaunchConfiguration_withGP3(t *testing.T) {
var conf autoscaling.LaunchConfiguration
resourceName := "aws_launch_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, autoscaling.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLaunchConfigurationWithGP3(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.test", &conf),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "ebs_block_device.*", map[string]string{
"volume_type": "gp3",
}),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "ebs_block_device.*", map[string]string{
"throughput": "150",
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"associate_public_ip_address"},
},
},
})
}

func TestAccAWSLaunchConfiguration_updateEbsBlockDevices(t *testing.T) {
var conf autoscaling.LaunchConfiguration
resourceName := "aws_launch_configuration.test"
Expand Down Expand Up @@ -835,6 +867,29 @@ resource "aws_launch_configuration" "test" {
`)
}

func testAccAWSLaunchConfigurationWithGP3() string {
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), `
resource "aws_launch_configuration" "test" {
image_id = data.aws_ami.amzn-ami-minimal-hvm-ebs.id
instance_type = "t2.micro"
associate_public_ip_address = false

root_block_device {
volume_type = "gp3"
volume_size = 11
}

ebs_block_device {
volume_type = "gp3"
device_name = "/dev/sdb"
volume_size = 9
encrypted = true
throughput = 150
}
}
`)
}

func testAccAWSLaunchConfigurationWithEncryptionUpdated() string {
return composeConfig(testAccLatestAmazonLinuxHvmEbsAmiConfig(), `
resource "aws_launch_configuration" "test" {
Expand Down
6 changes: 4 additions & 2 deletions website/docs/d/launch_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ In addition to all arguments above, the following attributes are exported:
* `delete_on_termination` - Whether the EBS Volume will be deleted on instance termination.
* `encrypted` - Whether the volume is Encrypted.
* `iops` - The provisioned IOPs of the volume.
* `throughput` - The Throughput of the volume.
* `volume_size` - The Size of the volume.
* `volume_type` - The Type of the volume.

`ebs_block_device` is exported with the following attributes:

* `delete_on_termination` - Whether the EBS Volume will be deleted on instance termination.
* `device_name` - The Name of the device.
* `no_device` - Whether the device in the block device mapping of the AMI is suppressed.
* `encrypted` - Whether the volume is Encrypted.
* `iops` - The provisioned IOPs of the volume.
* `no_device` - Whether the device in the block device mapping of the AMI is suppressed.
* `snapshot_id` - The Snapshot ID of the mount.
* `throughput` - The Throughput of the volume.
* `volume_size` - The Size of the volume.
* `volume_type` - The Type of the volume.
* `encrypted` - Whether the volume is Encrypted.

`ephemeral_block_device` is exported with the following attributes:

Expand Down
6 changes: 4 additions & 2 deletions website/docs/r/launch_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,13 @@ to understand the implications of using these attributes.

The `root_block_device` mapping supports the following:

* `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`,
* `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, `"gp3"`, `"st1"`, `"sc1"`
or `"io1"`. (Default: `"standard"`).
* `volume_size` - (Optional) The size of the volume in gigabytes.
* `iops` - (Optional) The amount of provisioned
[IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html).
This must be set with a `volume_type` of `"io1"`.
* `throughput` - (Optional) The throughput (MiBps) to provision for a `gp3` volume.
* `delete_on_termination` - (Optional) Whether the volume should be destroyed
on instance termination (Default: `true`).
* `encrypted` - (Optional) Whether the volume should be encrypted or not. (Default: `false`).
Expand All @@ -193,12 +194,13 @@ Each `ebs_block_device` supports the following:

* `device_name` - (Required) The name of the device to mount.
* `snapshot_id` - (Optional) The Snapshot ID to mount.
* `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`,
* `volume_type` - (Optional) The type of volume. Can be `"standard"`, `"gp2"`, `"gp3"`, `"st1"`, `"sc1"`
or `"io1"`. (Default: `"standard"`).
* `volume_size` - (Optional) The size of the volume in gigabytes.
* `iops` - (Optional) The amount of provisioned
[IOPS](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-io-characteristics.html).
This must be set with a `volume_type` of `"io1"`.
* `throughput` - (Optional) The throughput (MiBps) to provision for a `gp3` volume.
* `delete_on_termination` - (Optional) Whether the volume should be destroyed
on instance termination (Default: `true`).
* `encrypted` - (Optional) Whether the volume should be encrypted or not. Do not use this option if you are using `snapshot_id` as the encrypted flag will be determined by the snapshot. (Default: `false`).
Expand Down