hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.76k stars 9.11k forks source link

aws_launch_template block-device-mappings ebs{} ignores no_device #6433

Open in4mer opened 5 years ago

in4mer commented 5 years ago

Community Note

Terraform Version

Affected Resource(s)

Terraform Configuration Files

data "null_data_source" "ebs_info" {
  inputs = {
    count = "0"
    devices = ""
  }
}

resource "aws_launch_template" "template_name" {
  ...
block_device_mappings {
  device_name = "/dev/xvdf"
  no_device = "${data.null_data_source.ebs_info.inputs.count < 1 ? true : false}"
  ebs {
    volume_size = "123"
    volume_type = "gp2"
  }
}

Debug Output

Here's a section out of the terraform show after the LCT's been created:

aws_launch_template.mongodump-worker:
  id = lt-12345
  arn = arn:aws:ec2:us-west-2:lol-no:launch-template/lt-12345
  block_device_mappings.# = 8
  block_device_mappings.0.device_name = /dev/xvdb
  block_device_mappings.0.ebs.# = 0
  block_device_mappings.0.no_device = false
  block_device_mappings.0.virtual_name = ephemeral0
  block_device_mappings.1.device_name = /dev/xvdc
  block_device_mappings.1.ebs.# = 0
  block_device_mappings.1.no_device = true
  block_device_mappings.1.virtual_name = ephemeral1
  block_device_mappings.2.device_name = /dev/xvdd
  block_device_mappings.2.ebs.# = 0
  block_device_mappings.2.no_device = true
  block_device_mappings.2.virtual_name = ephemeral2
  block_device_mappings.3.device_name = /dev/xvde
  block_device_mappings.3.ebs.# = 0
  block_device_mappings.3.no_device = true
  block_device_mappings.3.virtual_name = ephemeral3
  block_device_mappings.4.device_name = /dev/xvdf
  block_device_mappings.4.ebs.# = 1
  block_device_mappings.4.ebs.0.delete_on_termination = false
  block_device_mappings.4.ebs.0.encrypted = false
  block_device_mappings.4.ebs.0.iops = 0
  block_device_mappings.4.ebs.0.kms_key_id = 
  block_device_mappings.4.ebs.0.snapshot_id = 
  block_device_mappings.4.ebs.0.volume_size = 80
  block_device_mappings.4.ebs.0.volume_type = gp2
  block_device_mappings.4.no_device = false
  block_device_mappings.4.virtual_name = 
  block_device_mappings.5.device_name = /dev/xvdg
  block_device_mappings.5.ebs.# = 1
  block_device_mappings.5.ebs.0.delete_on_termination = false
  block_device_mappings.5.ebs.0.encrypted = false
  block_device_mappings.5.ebs.0.iops = 0
  block_device_mappings.5.ebs.0.kms_key_id = 
  block_device_mappings.5.ebs.0.snapshot_id = 
  block_device_mappings.5.ebs.0.volume_size = 80
  block_device_mappings.5.ebs.0.volume_type = gp2
  block_device_mappings.5.no_device = true
  block_device_mappings.5.virtual_name = 
  block_device_mappings.6.device_name = /dev/xvdh
  block_device_mappings.6.ebs.# = 1
  block_device_mappings.6.ebs.0.delete_on_termination = false
  block_device_mappings.6.ebs.0.encrypted = false
  block_device_mappings.6.ebs.0.iops = 0
  block_device_mappings.6.ebs.0.kms_key_id = 
  block_device_mappings.6.ebs.0.snapshot_id = 
  block_device_mappings.6.ebs.0.volume_size = 80
  block_device_mappings.6.ebs.0.volume_type = gp2
  block_device_mappings.6.no_device = true
  block_device_mappings.6.virtual_name = 
  block_device_mappings.7.device_name = /dev/xvdi
  block_device_mappings.7.ebs.# = 1
  block_device_mappings.7.ebs.0.delete_on_termination = false
  block_device_mappings.7.ebs.0.encrypted = false
  block_device_mappings.7.ebs.0.iops = 0
  block_device_mappings.7.ebs.0.kms_key_id = 
  block_device_mappings.7.ebs.0.snapshot_id = 
  block_device_mappings.7.ebs.0.volume_size = 80
  block_device_mappings.7.ebs.0.volume_type = gp2
  block_device_mappings.7.no_device = true
  block_device_mappings.7.virtual_name = 

Panic Output

no panic

Expected Behavior

According to the documentation of aws_launch_template, block_device_mappings supports no_device, which should not cause an EBS volume to be created at auto-scaling time.

Actual Behavior

auto-scaling time causes an instance with an EBS device to be created & attached to the instance.

Steps to Reproduce

Put a similarly configured launch template into an ASG and scale it up to a single instance, or take an existing auto-scaling group and toss a similar block_device_mappings block in it. Observe.

  1. terraform apply

Important Factoids

The terraform show output is from one launch_template that has eight block_device_mappings blocks, with the first ebs{} device no_device set to false. The other three are set to true. The state output reflects the actual inputs to the ebs blocks, yes.

Results? Four EBS devices created and attached to the instance.

References

github-actions[bot] commented 3 years ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

in4mer commented 3 years ago

This kind of thing is one of the reasons I've stopped submitting bugs for hashicorp products

kylehodgetts commented 1 year ago

I don't believe this is still the case. After specifying no_device in one of my launch templates, I was able to confirm that the EC2 instance(s) that are part of the Auto Scaling Group do not have that EBS volume attached.

krohini1593 commented 1 year ago

Hi @kylehodgetts,

I'm running into exactly the same issue with AWS provider 4.58.0. Can you please share a configuration to show the usage of no_device? Appreciate the help.

Thanks.

df-sloughton commented 6 months ago

resource "aws_launch_template" > no_device doesnt work for me, whether proper bool or string true/"true". Using hashicorp/aws v5.17.0 Terraform v1.5.7 on windows_amd64

Here's a workaround. When var is disabled, Launch Template still has a block device listed but but size and type are empty in AWS console. And new instances wont have the extra volume.

  block_device_mappings {
      device_name = "xvdf"
      no_device = var.extra_windows_data_drive_enabled ? false : true # does nothing

      ebs {
        volume_size           = var.extra_windows_data_drive_enabled ? "200" : null 
        volume_type           = var.extra_windows_data_drive_enabled ? "gp3" : null 
      }
    }