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

Read iops only when volume type is io1 #1573

Merged
merged 1 commit into from
Sep 21, 2017
Merged
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
28 changes: 19 additions & 9 deletions aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ func resourceAwsInstance() *schema.Resource {
},

"iops": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: iopsDiffSuppressFunc,
},

"snapshot_id": {
Expand Down Expand Up @@ -387,10 +388,11 @@ func resourceAwsInstance() *schema.Resource {
},

"iops": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: iopsDiffSuppressFunc,
},

"volume_size": {
Expand All @@ -413,6 +415,14 @@ func resourceAwsInstance() *schema.Resource {
}
}

func iopsDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
// Suppress diff if volume_type is not io1
i := strings.LastIndexByte(k, '.')
vt := k[:i+1] + "volume_type"
v := d.Get(vt).(string)
return strings.ToLower(v) != ec2.VolumeTypeIo1
}

func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

Expand Down Expand Up @@ -1326,7 +1336,7 @@ func readBlockDeviceMappingsFromConfig(

if v, ok := bd["volume_type"].(string); ok && v != "" {
ebs.VolumeType = aws.String(v)
if "io1" == strings.ToLower(v) {
if ec2.VolumeTypeIo1 == strings.ToLower(v) {
// Condition: This parameter is required for requests to create io1
// volumes; it is not used in requests to create gp2, st1, sc1, or
// standard volumes.
Expand Down