定义生命周期检查,以避免在标签更改时重新部署资源

问题描述 投票:0回答:1

如何定义生命周期检查以避免标签更改时重新部署资源

当我使用时:

terraform {
  required_version = ">=1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.0.0"
    }
  }
}

provider "aws" {
  region  = var.aws_region
  lifecycle {
    ignore_changes = [
      # Ignore changes to tags, e.g. because a management agent
      # updates these based on some ruleset managed elsewhere.
      tags,
    ]
  }
}

我收到错误: 块类型名称“lifecycle”保留供 Terraform 在未来版本中使用。

amazon-web-services terraform infrastructure-as-code
1个回答
0
投票

ignore_changes 应在资源级别设置,而不是提供者。

示例:

resource "aws_instance" "web" {
  ami           = "ami-0c94855ba95c574c8"
  instance_type = "t3.micro"

  lifecycle {
    ignore_changes = [
      tags
    ]
  }
}

一些注意事项:

  • 在计划 create 操作时会考虑与给定属性名称相对应的参数,但在计划 update 时会被忽略。
  • 代替列表,可以使用特殊关键字
    all
    来指示 Terraform 忽略所有属性,这意味着 Terraform 可以创建和销毁远程对象,但永远不会建议对其进行更新。
  • 只能忽略资源类型定义的属性。
    ignore_changes
    不能应用于自身或任何其他元参数。
© www.soinside.com 2019 - 2024. All rights reserved.