"aws_ami" 和 most_recent=true 会影响未来的更新吗?
Will "aws_ami" with most_recent=true impact future updates?
鉴于下面的配置,如果我 运行 在 Amazon 推出新版本的 AMI 时对基础设施应用命令会发生什么?
test 实例会被销毁并重新创建吗?
场景
- 地形初始化
- 地形应用
- 等N个月
- terraform 计划(或申请)
AM 我将看到 "forced" 使用当时 "recent" 的旧版本 AMI 创建的 ec2 实例的重建?
data "aws_ami" "amazon-linux-2" {
most_recent = true
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
resource "aws_instance" "test" {
depends_on = ["aws_internet_gateway.test"]
ami = "${data.aws_ami.amazon-linux-2.id}"
associate_public_ip_address = true
iam_instance_profile = "${aws_iam_instance_profile.test.id}"
instance_type = "t2.micro"
key_name = "bflad-20180605"
vpc_security_group_ids = ["${aws_security_group.test.id}"]
subnet_id = "${aws_subnet.test.id}"
}
"aws_ami" most_recent=true 会影响未来的更新吗?
是的,正如@ydaetskcoR 所说,您可以查看 ignore_changes
生命周期,然后它不会重新创建实例。 https://www.terraform.io/docs/configuration/resources.html#ignore_changes
@ydeatskoR 和@sogyals429 有正确答案。更具体地说:
resource "aws_instance" "test" {
# ... (all the stuff at the top)
lifecycle {
ignore_changes = [
ami,
]
}
}
注意:文档移至:https://www.terraform.io/docs/language/meta-arguments/lifecycle.html#ignore_changes
鉴于下面的配置,如果我 运行 在 Amazon 推出新版本的 AMI 时对基础设施应用命令会发生什么?
test 实例会被销毁并重新创建吗?
场景
- 地形初始化
- 地形应用
- 等N个月
- terraform 计划(或申请)
AM 我将看到 "forced" 使用当时 "recent" 的旧版本 AMI 创建的 ec2 实例的重建?
data "aws_ami" "amazon-linux-2" {
most_recent = true
filter {
name = "owner-alias"
values = ["amazon"]
}
filter {
name = "name"
values = ["amzn2-ami-hvm*"]
}
}
resource "aws_instance" "test" {
depends_on = ["aws_internet_gateway.test"]
ami = "${data.aws_ami.amazon-linux-2.id}"
associate_public_ip_address = true
iam_instance_profile = "${aws_iam_instance_profile.test.id}"
instance_type = "t2.micro"
key_name = "bflad-20180605"
vpc_security_group_ids = ["${aws_security_group.test.id}"]
subnet_id = "${aws_subnet.test.id}"
}
"aws_ami" most_recent=true 会影响未来的更新吗?
是的,正如@ydaetskcoR 所说,您可以查看 ignore_changes
生命周期,然后它不会重新创建实例。 https://www.terraform.io/docs/configuration/resources.html#ignore_changes
@ydeatskoR 和@sogyals429 有正确答案。更具体地说:
resource "aws_instance" "test" {
# ... (all the stuff at the top)
lifecycle {
ignore_changes = [
ami,
]
}
}
注意:文档移至:https://www.terraform.io/docs/language/meta-arguments/lifecycle.html#ignore_changes