LoginSignup
1
1

More than 5 years have passed since last update.

aws_launch_configurationのuser_dataの更新でエラーが出る件の対処

Last updated at Posted at 2016-11-12

こんな感じのを定義して一度apply後、user_dataを修正して再度applyすると

...snip...

resource "aws_launch_configuration" "config" {
    name                    = "${var.app_id}-as-config"
    image_id                = "ami-374db956"
    instance_type           = "t2.nano"

    key_name                = "home"
    iam_instance_profile    = "${aws_iam_instance_profile.profile.name}"
    security_groups         = ["${aws_security_group.security.name}"]

    user_data               = <<EOT
#cloud-config
...snip...
EOT
}

...snip...

こんな感じのエラーを吐く

Error applying plan:

1 error(s) occurred:

* aws_launch_configuration.config: Error creating launch configuration: AlreadyExists: Launch Configuration by this name already exists - A launch configuration already exists with the name acceptessa-as-config
        status code: 400, request id: 80fd0b22-a8b6-11e6-b7b8-fb76220c4050

散々ググっても出てこなくて、下記のようにcreate_before_destroyを指定したら解決するというissueを散々見たものの解決せず。

lifecycle {
  create_before_destroy = true
}

で、やっと見つけたのが下記のページで。

Take the name out of your launch config. If you want to be able to change it, then you need to let it autogenerate a name for you

雑に解釈すると aws_launch_configuration から name を外せよ。名前指定してるから上書きしようとして再作成できないんだよ。名前を指定しなかったら名前を自動生成してくれるよ、という感じでしょうか。

ということなので、aws_launch_configuration の設定から name を外し先ほどのlifecycleも追加し以下のように。

...snip...

resource "aws_launch_configuration" "config" {
    image_id                = "ami-374db956"
    instance_type           = "t2.nano"

    key_name                = "home"
    iam_instance_profile    = "${aws_iam_instance_profile.profile.name}"
    security_groups         = ["${aws_security_group.security.name}"]

    user_data               = <<EOT
#cloud-config
...snip...
EOT

    lifecycle {
      create_before_destroy = true
    }  
}

...snip...

そうしたら動いた!!!

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1