terraform-aws-ec2-instance icon indicating copy to clipboard operation
terraform-aws-ec2-instance copied to clipboard

Issue handling 'io2' and 'gp3' volume types

Open Nexus357ZA opened this issue 4 years ago • 1 comments

Description

When using provisioned IOPS SSD other than io1 the specified iops value for root_iops and/or ebs_iops get set to 0

Expected Behavior

'io2' and 'gp3' volume types should also set the given iops value when supplied

Steps to Reproduce

Steps to reproduce the behavior:

With a module used

module "instance" {
  source  = "cloudposse/ec2-instance/aws"
  version = "0.39.0"
  
  #Other required parameters

  root_volume_type = "gp3"
  root_iops                = 6000
  
  ...
 }

The instance will be created, however the default value of 0 will be applied on subsequent runs

Screenshots

Example of subsequent runs

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.instance.aws_instance.default[0] will be updated in-place
  ~ resource "aws_instance" "default" {
        id                                   = "i-00000000000000000"
        tags                                 = {
            "Environment" = "xxx"
            "Name"        = "xxx"
            "Namespace"   = "xxx"
        }
        # (30 unchanged attributes hidden)

      ~ root_block_device {
          ~ iops                  = 3000 -> 0
            tags                  = {}
            # (8 unchanged attributes hidden)
        }
        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Nexus357ZA avatar Oct 08 '21 15:10 Nexus357ZA

The issue lies with the following two lines in the locals declaration :

root_iops              = var.root_volume_type == "io1" ? var.root_iops : "0"
ebs_iops               = var.ebs_volume_type == "io1" ? var.ebs_iops : "0"

The root_iops and ebs_iops variables default to 0 already in the variable description, it might be safe to remove these lines from the localsblock and reference the variables directly. This should have no impact on other volume types unless the variables get set to any other value other than 0 in which case an appropriate error will be displayed anyway.

Nexus357ZA avatar Oct 08 '21 15:10 Nexus357ZA