terraform - most_recent=true 的 "aws_ami"会影响 future 的更新吗?

标签 terraform terraform-provider-aws terraform0.12+

根据下面的配置,如果 Amazon 推出新版本的 AMI,我对基础设施运行 apply 命令会发生什么情况?

测试实例会被销毁并重新创建吗?

所以场景

  1. 地形初始化
  2. 地形应用
  3. 等待N个月
  4. 地形计划(或申请)

我是否会看到“强制”重新创建 N 个月前使用当时“最新”的 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}"
}

带有most_recent=true 的“aws_ami”会影响 future 的更新吗?

最佳答案

@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

关于terraform - most_recent=true 的 "aws_ami"会影响 future 的更新吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61826847/

相关文章:

amazon-web-services - 如何在 terraform 资源中的 zipmap 和列表上创建嵌套 for 循环

当不存在循环时,terraform destroy 会产生循环错误

terraform - 使用 Cloud Watch 和 Terraform 拍摄计划的 EBS 快照

amazon-web-services - 如何解决错误 : "Argument names must not be quoted" in Terraform?

google-cloud-platform - 使用 Terraform 为 GCS 启用 "Interoperable"访问权限?

azure - 在 Azure 中创建多个具有不同配置的 VM

amazon-web-services - 如何使用 Terraform 在 AWS SSM 参数中存储三元素元组?

amazon-web-services - 地形错误: Incorrect attribute value type for subnet_ids vpc modules

azure - 如何使用 Terraform 创建 Azure VNET 时添加多个地址空间

Terraform Datadog 查询无效