gpt4 book ai didi

Terraform(AWS 提供商)- Auto Scaling 组不会对启动模板更改生效

转载 作者:行者123 更新时间:2023-12-03 17:04:02 26 4
gpt4 key购买 nike

无法在使用启动模板时使启动模板与 ASG 一起工作,它使用一个小技巧与启动配置一起工作,即通过在 ASG 资源中插入启动配置名称,但它不适用于启动模板。
ASG 使用最新版本来启动新实例,但不会对预运行实例进行任何更改,尽管启动模板发生了变化。

我知道这是预料之中的,但我们是否有任何解决方法可以使启动模板与 ASG 一起使用,或者我们需要坚持启动配置本身?

TF 代码片段 -

resource "aws_launch_template" "lc_ec2" {
image_id = "${var.ami_id}"
instance_type = "${var.app_instance_type}"
key_name = "${var.orgname}_${var.environ}_kp"
vpc_security_group_ids = ["${aws_security_group.sg_ec2.id}"]
user_data = "${base64encode(var.userdata)}"
block_device_mappings {
device_name = "/dev/xvdv"
ebs {
volume_size = 15
}
}
iam_instance_profile {
name = "${var.orgname}_${var.environ}_profile"
}
lifecycle {
create_before_destroy = true
}

tag_specifications {
resource_type = "instance"
tags = "${merge(map("Name", format("%s-%s-lc-ec2", var.orgname, var.environ)), var.tags)}"
}
tag_specifications {
resource_type = "volume"
tags = "${merge(map("Name", format("%s-%s-lc-ec2-volume", var.orgname, var.environ)), var.tags)}"
}
tags = "${merge(map("Name", format("%s-%s-lc-ec2", var.orgname, var.environ)), var.tags)}"
}

resource "aws_autoscaling_group" "asg_ec2" {
name = "${var.orgname}-${var.environ}-asg-ec2-${aws_launch_template.lc_ec2.name}"

vpc_zone_identifier = ["${data.aws_subnet.private.*.id}"]
min_size = 1
desired_capacity = 1
max_size = 1
target_group_arns = ["${aws_lb_target_group.alb_tg.arn}"]
default_cooldown= 100
health_check_grace_period = 100
termination_policies = ["ClosestToNextInstanceHour", "NewestInstance"]
health_check_type="ELB"
launch_template = {
id = "${aws_launch_template.lc_ec2.id}"
version = "$$Latest"
}
lifecycle {
create_before_destroy = true
}

tags = [
{
key = "Name"
value = "${var.orgname}"
propagate_at_launch = true
},
{
key = "Environ"
value = "${var.environ}"
propagate_at_launch = true
}
]
}

最佳答案

有一个技巧可以实现这一点。

AWS CloudFormation 支持自动扩展组的滚动更新。
由于 Terraform 支持 cloudformation 堆栈资源,因此您可以将 ASG 定义为具有更新策略的 cloudformation 堆栈。但是,CloudFormation 不支持启动模板版本的 $$Latest 标签,因此您必须参数化版本并从在您的 terraform 配置文件中创建的启动模板资源的 latest_version 属性中获取输入值。

关于Terraform(AWS 提供商)- Auto Scaling 组不会对启动模板更改生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51250943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com