Terraform: サンプルが難しい〜aws_autoscaling_groupが上手くいかない話〜
Placement groups may not be used with instances of typeの話
↓のサンプルやれば、オートスケールできるようになるんじゃね、って軽いノリで検証し始めたけど、見事にはまった。
ソースは上記リンク先のページをそのまま。
* aws_autoscaling_group.bar: 1 error(s) occurred: * aws_autoscaling_group.bar: "foobar3-terraform-test": Waiting up to 10m0s: Need at least 4 healthy instances in ASG, have 0. Most recent activity: { ActivityId: "94f5a09e-6491-f883-31fc-9a67b6e36d34", AutoScalingGroupName: "foobar3-terraform-test", Cause: "At 2019-01-07T09:16:12Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 4.", Description: "Launching a new EC2 instance. Status Reason: Placement groups may not be used with instances of type 't2.micro'. Launching EC2 instance failed.", Details: "{\"Subnet ID\":\"subnet-0f8f0e78e2f93e59e\",\"Availability Zone\":\"ap-northeast-1c\"}", EndTime: 2019-01-07 09:16:14 +0000 UTC, Progress: 100, StartTime: 2019-01-07 09:16:14.334 +0000 UTC, StatusCode: "Failed", StatusMessage: "Placement groups may not be used with instances of type 't2.micro'. Launching EC2 instance failed." }
多分、こんな感じのことを言われてる気がする。
10分待った、最低4台のインスタンスがいるはずなんだけど、1台もいないよ。 t2.microでPlacement groupsが使われてないかもよ。上がらんし
知らんし。
1台だけEC2インスタンス上がってる。
10分待ったけど、って待ちすぎ。と思って画面見てたら、↓こんなんあった。
wait_for_capacity_timeout "" =>"10m"
何も指定してないとデフォ10分になるっぽい。これはとりあえず5mに変えておこう。
あと、health_check_typeがELBになっていたけど、ELB作る設定は書いてないのでEC2に変更してみる。
変更後 wait_for_capacity_timeout = "5m" health_check_type = "EC2
再度実行
$ terraform apply 〜略〜 health_check_type: "" => "EC2" 〜略〜 wait_for_capacity_timeout: "" => "5m" 〜略〜 * aws_autoscaling_group.bar: 1 error(s) occurred: * aws_autoscaling_group.bar: "foobar3-terraform-test": Waiting up to 5m0s: Need at least 4 healthy instances in ASG, have 0. Most recent activity: { ActivityId: "da95a09e-e5cd-0267-43c3-ff43250264a2", AutoScalingGroupName: "foobar3-terraform-test", Cause: "At 2019-01-07T09:51:30Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 4.", Description: "Launching a new EC2 instance. Status Reason: Placement groups may not be used with instances of type 't2.micro'. Launching EC2 instance failed.", Details: "{\"Subnet ID\":\"subnet-05082e304ca64329e\",\"Availability Zone\":\"ap-northeast-1c\"}", EndTime: 2019-01-07 09:51:31 +0000 UTC, Progress: 100, StartTime: 2019-01-07 09:51:31.648 +0000 UTC, StatusCode: "Failed", StatusMessage: "Placement groups may not be used with instances of type 't2.micro'. Launching EC2 instance failed." }
変更はちゃんと適用されたけど、問題はここじゃないくさい。
1台目が起動したあとのヘルスチェックかな???
Placement Groupに対応しているEC2インスタンスタイプの話
調べてたら、たまたま引っかかった。クラスタープレイスメントグループの制約だった。
懐を気にしてinstance_type = t2.microにしてたけど、サポートされていなかった。
そして、オレオレ和訳も間違っていた。
× t2.microでPlacement groupsが使われてないかもよ。上がらんし ○ t2.microでPlacement groupsが使われないかもよ。上がらんし
↓のようにaws_launch_configurationを修正したら無事上がった。
$ cat launch_config.tf resource "aws_launch_configuration" "foobar" { name = "test-launch-config" image_id = "ami-092834f1e5079fb84" # AWS Placement_Groupがt2とか対応してないっぽい instance_type = "m5.large" #instance_type = "t2.micro" key_name = "${var.key_name}" }
m5を4台とか要らん。。。
現状、まだヘルスチェックが上手く引っかからず、意図せずdesired_capacityまでスケールアウトしてしまう。
Error: Error applying plan: 1 error(s) occurred: * aws_autoscaling_group.bar: 1 error(s) occurred: * aws_autoscaling_group.bar: "foobar3-terraform-test": Waiting up to 5m0s: Need at least 1 healthy instances in ASG, have 0. Most recent activity: { ActivityId: "ea15a0b3-2f8a-d85e-a6e4-d86b1f95e8fa", AutoScalingGroupName: "foobar3-terraform-test", Cause: "At 2019-01-08T09:29:43Z a user request update of AutoScalingGroup constraints to min: 0, max: 5, desired: 1 changing the desired capacity from 0 to 1. At 2019-01-08T09:29:44Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.", Description: "Launching a new EC2 instance: i-039eb1472280c5749", Details: "{\"Subnet ID\":\"subnet-0720c7a4238f0fd26\",\"Availability Zone\":\"ap-northeast-1c\"}", Progress: 40, StartTime: 2019-01-08 09:29:45.911 +0000 UTC, StatusCode: "MidLifecycleAction" }
引き続き、検証しよう・・・。
その他:terraform destroyしたときにEBSが消えない話
消されなかったEBSが大量に残ってるんだけど・・・。
delete_on_terminationオプションだろうな、あとで入れとこう。
忘れたままにしといたら、課金が捗りそう。