pulumi / pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Apache License 2.0
464 stars 156 forks source link

Changing the throughput property on a volume in `ebsBlockDevices` doesn't result in changes to the volume #3375

Open onlynone opened 9 months ago

onlynone commented 9 months ago

What happened?

I wanted to change the throughput on an EBS volume attached to an EC2 instance from 125 MiB/s to 250 MiB/s. But after making the change in code, running pulumi preview shows no differences. Running pulumi up makes no changes, and pulumi refresh doesn't seem to pull in any differences.

Example

Code was this first:

new aws.ec2.Instance(name, {
  ami: ami.id,
  availabilityZone: "us-east-2a",
  ebsBlockDevices: [
    {
      deviceName: "/dev/sdb",
      volumeSize: 1024,
      volumeType: "gp3",
      iops: 5000,
    },
  ],
  ...
}

Then was changed to:

new aws.ec2.Instance(name, {
  ami: ami.id,
  availabilityZone: "us-east-2a",
  ebsBlockDevices: [
    {
      deviceName: "/dev/sdb",
      volumeSize: 1024,
      volumeType: "gp3",
      iops: 5000,
      throughput: 250,
    },
  ],
  ...
}

Output of pulumi about

$ pulumi about
CLI          
Version      3.102.0
Go Version   go1.21.5
Go Compiler  gc

Plugins
NAME     VERSION
aws      5.18.0
command  0.7.2
gitlab   6.2.0
nodejs   unknown

Host     
OS       darwin
Version  13.6.2
Arch     arm64

[...snip...]

Found no pending operations associated with prod

[...snip...]

Dependencies:
NAME             VERSION
@iarna/toml      2.2.5
@pulumi/aws      5.18.0
@pulumi/command  0.7.2
@pulumi/gitlab   6.2.0
@pulumi/pulumi   3.76.1
handlebars       4.7.8
lodash           4.17.21
typescript       4.9.5
@types/lodash    4.14.196
@types/node      16.18.39

Additional context

If I change the throughput property of the rootBlockDevice, that is updated correctly.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

t0yv0 commented 9 months ago

Thank you very much for reporting this @onlynone , my team will have a look here as soon as we have an opportunity.

t0yv0 commented 3 weeks ago

It appears there is some intentional code to do this in the upstream provider:

https://github.com/hashicorp/terraform-provider-aws/blob/master/internal/service/ec2/ec2_instance.go#L261

names.AttrIOPS: {
    Type:             schema.TypeInt,
    Optional:         true,
    Computed:         true,
    ForceNew:         true,
    DiffSuppressFunc: iopsDiffSuppressFunc
},

https://github.com/hashicorp/terraform-provider-aws/blob/master/internal/service/ec2/ec2_instance.go#L948

func iopsDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
    // Suppress diff if volume_type is not io1, io2, or gp3 and iops is unset or configured as 0
    i := strings.LastIndexByte(k, '.')
    vt := k[:i+1] + names.AttrVolumeType
    v := d.Get(vt).(string)
    return (strings.ToLower(v) != string(awstypes.VolumeTypeIo1) && strings.ToLower(v) != string(awstypes.VolumeTypeIo2) && strings.ToLower(v) != string(awstypes.VolumeTypeGp3)) && new == "0"
}

I think this code is very old and appeared in https://github.com/hashicorp/terraform-provider-aws/commit/3b9f715a3ab1e8b3af1beca4d28db33d7df4c717

We need to file an upstream provider issue and fix it in there.

t0yv0 commented 3 weeks ago

https://github.com/hashicorp/terraform-provider-aws/issues/39866