概要
起動設定を更新した際に相関関係にあるASGで起動しているインスタンスが作り直されてしまうので、これを回避する。
方法
EC2Resources
のaws_launch_configuration
を使用時、引数にname
ではなく name_prefix
を使用する。
launch_configuration.tf
resource "aws_launch_configuration" xxxxxxxx-autoscaling-conf" {
name_prefix = "xxxxxxxx-autoscaling"
image_id = "ami-xxxxx"
instance_type = "t2.medium"
iam_instance_profile = "xxxxxxxx"
key_name = "xxxxxxxx"
security_groups = ["sg-xxxxxxxx"]
associate_public_ip_address = true
user_data = "${file("xxxxxxxx.sh")}"
root_block_device {
volume_type = "gp2"
volume_size = "50"
delete_on_termination = "true"
}
lifecycle {
create_before_destroy = true
}
}
- IDのみがユニークなものに置換され、ASGは影響を受けない
aws_launch_configuration.xxxxxxxx-autoscaling-autoscaling-conf:
id = xxxxxxxx-autoscalingxxxxxxxxxxxxxxxx