Terraform: aws_launch_configuration root_device

Created on 28 Apr 2016  ·  7Comments  ·  Source: hashicorp/terraform

Terraform version: 0.6.15

Affected Resource(s):

  • aws_launch_configuration

Terraform Configuration File:

resource "aws_launch_configuration" "my_app" {
    iam_instance_profile = "${aws_iam_instance_profile.my_app.name}"
    image_id = "${atlas_artifact.my_app_ami.metadata_full.region-us-east-1}"
    instance_type = "${lookup(var.instance_type, var.env)}"
    key_name = "${var.ec2_key_name}"
    name_prefix = "my_app-"
    security_groups = [ 
        "${aws_security_group.my_app.id}",
        "${var.vpc_default_security_group}"
    ]

    root_block_device {
        delete_on_termination = false
        volume_type = "gp2"
        volume_size = 150
    }

    lifecycle { create_before_destroy = true }
}

Terraform Plan output:

-/+ module.my_app.aws_launch_configuration.my_app
    associate_public_ip_address:               "false" => "0"
    ebs_block_device.#:                        "1" => "<computed>"
    ebs_optimized:                             "false" => "<computed>"
    enable_monitoring:                         "true" => "1"
    iam_instance_profile:                      "my-app" => "my-app"
    image_id:                                  "ami-6687620b" => "ami-6687620b"
    instance_type:                             "t2.medium" => "t2.medium"
    key_name:                                  "mykey" => "mykey"
    name:                                      "myapp-d5ddqen5xfctfawoj7c2j32jpq" => "<computed>"
    name_prefix:                               "myapp-" => "myapp-"
    root_block_device.#:                       "0" => "1"
    root_block_device.0.delete_on_termination: "" => "0" (forces new resource)
    root_block_device.0.iops:                  "" => "<computed>" (forces new resource)
    root_block_device.0.volume_size:           "" => "150" (forces new resource)
    root_block_device.0.volume_type:           "" => "gp2" (forces new resource)
    security_groups.#:                         "2" => "2"
    security_groups.2715815728:                "sg-8e1bb4f6" => "sg-8e1bb4f6"
    security_groups.3652858817:                "sg-e8ef6190" => "sg-e8ef6190"

The root_block_device.#: "0" => "1" part in particular is interesting. It thinks there is no root device currently set in the launch config when there is one set already in AWS.

Expected Behavior:
Terraform shouldn't be trying to do anything with that launch configuration. It already has those settings on it in our AWS account (looking at it in the console) that it's trying to set.

Actual Behavior:
Terraform will destroy the launch_configuration and rebuild it although there are no changes occurring between the old one and the new one.

Steps to Reproduce:

  1. terraform plan

Important Factoids:
It's happening randomly. Yesterday it happened a couple times and then it stopped trying to recreate the launch config for a few terraform runs. This morning it started trying to force the new resource again for the launch config.

The AMI I am using in the launch config was custom built through packer. The packer config looks like:

"builders": [
    {
      "type": "amazon-ebs",
      "access_key": "{{user `aws_access_key`}}",
      "ami_description": "AMI for {{user `role`}} (version {{user `version`}})",
      "ami_name": "{{user `role`}}-v{{user `version`}}",
      "communicator": "winrm",
      "iam_instance_profile": "{{user `iam_instance_profile`}}",
      "instance_type": "c4.xlarge",
      "region": "us-east-1",
      "secret_key": "{{user `aws_secret_key`}}",
      "security_group_id": "{{user `security_group_id`}}",
      "source_ami": "{{user `source_ami`}}",
      "subnet_id": "{{user `subnet_id`}}",
      "user_data_file": "ec2-user-data.txt",
      "vpc_id": "{{user `vpc_id`}}",
      "winrm_username": "Administrator",
      "ami_block_device_mappings": [
        {
          "device_name": "/dev/sda1",
          "volume_size": "150",
          "volume_type": "gp2",
          "delete_on_termination": true
        }
      ],
      "launch_block_device_mappings": [
        {
          "device_name": "/dev/sda1",
          "volume_size": "150",
          "volume_type": "gp2",
          "delete_on_termination": true
        }
      ]
    }
  ],

The output from aws ec2 describe-images --image-ids ami-6687620b for the ami being used in the launch config:

{
    "Images": [
        {
            "VirtualizationType": "hvm",
            "Name": "myapp-v1198",
            "Hypervisor": "xen",
            "SriovNetSupport": "simple",
            "ImageId": "ami-6687620b",
            "Platform": "windows",
            "State": "available",
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/sda1",
                    "Ebs": {
                        "DeleteOnTermination": true,
                        "SnapshotId": "snap-bebb6d5d",
                        "VolumeSize": 150,
                        "VolumeType": "gp2",
                        "Encrypted": false
                    }
                },
                {
                    "DeviceName": "xvdca",
                    "VirtualName": "ephemeral0"
                },
                {
                    "DeviceName": "xvdcb",
                    "VirtualName": "ephemeral1"
                },
                {
                    "DeviceName": "xvdcc",
                    "VirtualName": "ephemeral2"
                },
                {
                    "DeviceName": "xvdcd",
                    "VirtualName": "ephemeral3"
                },
                {
                    "DeviceName": "xvdce",
                    "VirtualName": "ephemeral4"
                },
                {
                    "DeviceName": "xvdcf",
                    "VirtualName": "ephemeral5"
                },
                {
                    "DeviceName": "xvdcg",
                    "VirtualName": "ephemeral6"
                },
                {
                    "DeviceName": "xvdch",
                    "VirtualName": "ephemeral7"
                },
                {
                    "DeviceName": "xvdci",
                    "VirtualName": "ephemeral8"
                },
                {
                    "DeviceName": "xvdcj",
                    "VirtualName": "ephemeral9"
                },
                {
                    "DeviceName": "xvdck",
                    "VirtualName": "ephemeral10"
                },
                {
                    "DeviceName": "xvdcl",
                    "VirtualName": "ephemeral11"
                },
                {
                    "DeviceName": "xvdcm",
                    "VirtualName": "ephemeral12"
                },
                {
                    "DeviceName": "xvdcn",
                    "VirtualName": "ephemeral13"
                },
                {
                    "DeviceName": "xvdco",
                    "VirtualName": "ephemeral14"
                },
                {
                    "DeviceName": "xvdcp",
                    "VirtualName": "ephemeral15"
                },
                {
                    "DeviceName": "xvdcq",
                    "VirtualName": "ephemeral16"
                },
                {
                    "DeviceName": "xvdcr",
                    "VirtualName": "ephemeral17"
                },
                {
                    "DeviceName": "xvdcs",
                    "VirtualName": "ephemeral18"
                },
                {
                    "DeviceName": "xvdct",
                    "VirtualName": "ephemeral19"
                },
                {
                    "DeviceName": "xvdcu",
                    "VirtualName": "ephemeral20"
                },
                {
                    "DeviceName": "xvdcv",
                    "VirtualName": "ephemeral21"
                },
                {
                    "DeviceName": "xvdcw",
                    "VirtualName": "ephemeral22"
                },
                {
                    "DeviceName": "xvdcx",
                    "VirtualName": "ephemeral23"
                },
                {
                    "DeviceName": "xvdcy",
                    "VirtualName": "ephemeral24"
                },
                {
                    "DeviceName": "xvdcz",
                    "VirtualName": "ephemeral25"
                }
            ],
            "Architecture": "x86_64",
            "ImageLocation": "826168981788/myapp-v1198",
            "RootDeviceType": "ebs",
            "OwnerId": "826168981788",
            "RootDeviceName": "/dev/sda1",
            "CreationDate": "2016-04-26T22:56:11.000Z",
            "Public": false,
            "ImageType": "machine",
            "Description": "AMI for myapp (version 1189)"
        }
    ]
}

It seems like everything in block mapping is correct as far as the root device name, type, etc.

References:
It seems similar to this issue...although I've followed some of the troubleshooting from here and it hasn't resolved the issue.

bug provideaws

Most helpful comment

I get similar issues with ebs_block_devices in 0.6.16 and 0.7.0. It tries to recreate them every single time, and if I do an ignore_changes on ebs_block_devices then TF just crashes on the diff.

All 7 comments

I should also note that we've had this setup running well for approximately 2 months and only recently have started seeing this happen (since upgrading to 0.6.15 it seems.) We also have a stage environment with the same exact ami build process and terraform configuration for this app in particular that isn't showing this behavior at all.

I get similar issues with ebs_block_devices in 0.6.16 and 0.7.0. It tries to recreate them every single time, and if I do an ignore_changes on ebs_block_devices then TF just crashes on the diff.

Thanks for the info @PurrBiscuit – I'm curious, are you using remote state for the staging environment? Are you still seeing this behavior?

@catsby things have changed with our terraform setup since April and we are now using remote state files between environments...however at the time that I first filed the issue we weren't. we still have the random root_block_device updating for that one app however. I actually have a support ticket, #1872, open with you about it. I'll send you over some more info in that ticket.

@PurrBiscuit thanks! I replied to that ticket internally but before I had a proper zendesk account, so it came from "product" I think 😄

I replied here as well incase someone else has seen this behavior and can share more information.

Thanks!

Hey all – we haven't been able to reproduce this and haven't heard much otherwise, so we're going to close this for now.

If you have any addition information please let us know!

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atkinchris picture atkinchris  ·  68Comments

nevir picture nevir  ·  82Comments

phinze picture phinze  ·  167Comments

kforsthoevel picture kforsthoevel  ·  86Comments

ncraike picture ncraike  ·  77Comments