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_ebs_volume io2 support #14894

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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: 4 additions & 3 deletions aws/resource_aws_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func resourceAwsEbsVolume() *schema.Resource {
Optional: true,
Computed: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return d.Get("type").(string) != ec2.VolumeTypeIo1 && new == "0"
return (d.Get("type").(string) != ec2.VolumeTypeIo1 && new == "0") ||
(d.Get("type").(string) != ec2.VolumeTypeIo2 && new == "0")
nikhil-goenka marked this conversation as resolved.
Show resolved Hide resolved
},
},
"kms_key_id": {
Expand Down Expand Up @@ -114,7 +115,7 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error
request.OutpostArn = aws.String(value.(string))
}

// IOPs are only valid, and required for, storage type io1. The current minimum
// IOPs are only valid, and required for, storage type io1 and io2. The current minimum
// is 100. Hard validation in place to return an error if IOPs are provided
// for an unsupported storage type.
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/12667
Expand All @@ -125,7 +126,7 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error
}

if iops := d.Get("iops").(int); iops > 0 {
if t != ec2.VolumeTypeIo1 {
if t != ec2.VolumeTypeIo1 && t != ec2.VolumeTypeIo2 {
if t == "" {
// Volume creation would default to gp2
t = ec2.VolumeTypeGp2
Expand Down
87 changes: 82 additions & 5 deletions aws/resource_aws_ebs_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestAccAWSEBSVolume_updateType(t *testing.T) {
})
}

func TestAccAWSEBSVolume_updateIops(t *testing.T) {
func TestAccAWSEBSVolume_updateIops_Io1(t *testing.T) {
var v ec2.Volume
resourceName := "aws_ebs_volume.test"

Expand All @@ -210,7 +210,7 @@ func TestAccAWSEBSVolume_updateIops(t *testing.T) {
CheckDestroy: testAccCheckVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsEbsVolumeConfigWithIops,
Config: testAccAwsEbsVolumeConfigWithIopsIo1,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "iops", "100"),
Expand All @@ -222,7 +222,40 @@ func TestAccAWSEBSVolume_updateIops(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccAwsEbsVolumeConfigWithIopsUpdated,
Config: testAccAwsEbsVolumeConfigWithIopsIo1Updated,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "iops", "200"),
),
},
},
})
}

func TestAccAWSEBSVolume_updateIops_Io2(t *testing.T) {
var v ec2.Volume
resourceName := "aws_ebs_volume.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsEbsVolumeConfigWithIopsIo2,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "iops", "100"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAwsEbsVolumeConfigWithIopsIo2Updated,
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "iops", "200"),
Expand Down Expand Up @@ -646,7 +679,7 @@ resource "aws_ebs_volume" "test" {
}
`

const testAccAwsEbsVolumeConfigWithIops = `
const testAccAwsEbsVolumeConfigWithIopsIo1 = `
data "aws_availability_zones" "available" {
state = "available"

Expand All @@ -668,7 +701,7 @@ resource "aws_ebs_volume" "test" {
}
`

const testAccAwsEbsVolumeConfigWithIopsUpdated = `
const testAccAwsEbsVolumeConfigWithIopsIo1Updated = `
data "aws_availability_zones" "available" {
state = "available"

Expand All @@ -690,6 +723,50 @@ resource "aws_ebs_volume" "test" {
}
`

const testAccAwsEbsVolumeConfigWithIopsIo2 = `
data "aws_availability_zones" "available" {
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

resource "aws_ebs_volume" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
type = "io2"
size = 4
iops = 100

tags = {
Name = "tf-acc-test-ebs-volume-test"
}
}
`

const testAccAwsEbsVolumeConfigWithIopsIo2Updated = `
data "aws_availability_zones" "available" {
state = "available"

filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

resource "aws_ebs_volume" "test" {
availability_zone = data.aws_availability_zones.available.names[0]
type = "io2"
size = 4
iops = 200

tags = {
Name = "tf-acc-test-ebs-volume-test"
}
}
`

const testAccAwsEbsVolumeConfigWithKmsKey = `
resource "aws_kms_key" "test" {
description = "Terraform acc test %d"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/ebs_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The following arguments are supported:
* `size` - (Optional) The size of the drive in GiBs.
* `snapshot_id` (Optional) A snapshot to base the EBS volume off of.
* `outpost_arn` - (Optional) The Amazon Resource Name (ARN) of the Outpost.
* `type` - (Optional) The type of EBS volume. Can be "standard", "gp2", "io1", "sc1" or "st1" (Default: "gp2").
* `type` - (Optional) The type of EBS volume. Can be "standard", "gp2", "io1", "io2", "sc1" or "st1" (Default: "gp2").
* `kms_key_id` - (Optional) The ARN for the KMS encryption key. When specifying `kms_key_id`, `encrypted` needs to be set to true.
* `tags` - (Optional) A map of tags to assign to the resource.

Expand Down