こんな感じのを定義して一度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...
そうしたら動いた!!!