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.75k stars 9.11k forks source link

aws_launch_template ignores device_index=0 #4475

Closed joernheissler closed 6 years ago

joernheissler commented 6 years ago

Community Note

Terraform Version

Terraform v0.11.6
+ provider.aws v1.17.0
+ provider.external v1.0.0
+ provider.local v1.1.0
+ provider.template v1.0.0

Affected Resource(s)

Terraform Configuration Files

resource "aws_launch_template" "loadtest" {
    name = "loadtest"
    description = "LoadTest"
    image_id = "${data.aws_ami.ubuntu_xenial.id}"
    instance_initiated_shutdown_behavior = "terminate"
    instance_type = "t2.small"

    placement {
        availability_zone = "eu-central-1a"
    }       

    network_interfaces {
        subnet_id = "${element(aws_subnet.stratus_private.*.id, 0)}"
# ----------------- Problem is here:
        device_index = 0
# -----------------
        delete_on_termination = true
        associate_public_ip_address = false
        security_groups = [
            "${aws_security_group.loadtest.id}",
        ]
    }
}

Expected Behavior

Terraform should submit the device index (0) to AWS.

Actual Behavior

Terraform ignores zero device index. AWS will then complain: You must use a valid fully formed launch template. Each network interface requires a device index.

Steps to Reproduce

  1. Delete default VPC
  2. Create new (non-default) VPC, subnets, etc. etc. etc.
  3. Use above resource and an autoscale group which uses the launch template.

Important Factoids

By deleting the default VPC, AWS will complain No default VPC for this user. So I specified network_interfaces like above and got the problem described above.

I quick fixed the issue in aws/resource_aws_launch_template.go:

    if v, ok := ni["device_index"].(int); ok && v != 0 {
        networkInterface.DeviceIndex = aws.Int64(int64(v))
    }

I removed && v != 0 and when I first destroyed the resource, it got created correctly on next apply. But updates don't work, probably another comparison that needs fixing.

bflad commented 6 years ago

FYI there's already a PR associated with this: #4367

bflad commented 6 years ago

The simple fix of removing the v != 0 check has been merged into master via #4367 and will release with v1.19.0 of the AWS provider, likely middle of next week. If there are other continuing issues after that, please open a new issue. Thanks!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!