Terraform:“tags”和“tags_all”有什么区别?

Rya*_* Lv 14 terraform

将 terraform 升级到 后3.64.2,尽管我没有更改任何代码,但terraform plan提醒我它将替换tagtag_all. tags和 和有什么不一样tags_all

~ resource "aws_lb_listener" "frontend_http_tcp" {
        id                = "xxxxx"
      ~ tags              = {
          - "environment" = "production" -> null
          - "purpose"     = "onboarding-integration" -> null
          - "terraform"   = "true" -> null
        }
      ~ tags_all          = {
          - "environment" = "production"
          - "purpose"     = "onboarding-integration"
          - "terraform"   = "true"
        } -> (known after apply)
        # (4 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }
Run Code Online (Sandbox Code Playgroud)

小智 24

在 Terraform 中,您可以在顶层定义标签。tags_all基本上是individual resource tags+top level tags

例如;

# Terraform 0.12 and later syntax
provider "aws" {
  # ... other configuration ...
  default_tags {
    tags = {
      Environment = "Production"
      Owner       = "Ops"
    }
  }
}

resource "aws_vpc" "example" {
  # ... other configuration ...

  # This configuration by default will internally combine tags defined
  # within the provider configuration block and those defined here
  tags = {
    Name = "MyVPC"
  }
}
Run Code Online (Sandbox Code Playgroud)

在上面的例子中;tags_all

tags_all = {
  Name = "MyVPC"
  Environment = "Production"
  Owner       = "Ops"
     }
Run Code Online (Sandbox Code Playgroud)

而标签是

tags = {
    Name = "MyVPC"
  }
Run Code Online (Sandbox Code Playgroud)

参考= https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/resource-tagging