admin管理员组文章数量:1279237
We would like to use a tag to identify the team who has authored the HCL code we are using to deploy AWS resources.
We wish to use this tag value so we can have Wiz provide a snapshot of the resources running on the estate at a particular time.
Is it possible to declare a tag in terraform HCL so that its value is constant?
We would like to use a tag to identify the team who has authored the HCL code we are using to deploy AWS resources.
We wish to use this tag value so we can have Wiz provide a snapshot of the resources running on the estate at a particular time.
Is it possible to declare a tag in terraform HCL so that its value is constant?
Share Improve this question edited Feb 25 at 10:17 Marko E 18.2k4 gold badges26 silver badges35 bronze badges asked Feb 24 at 9:50 Rob WellsRob Wells 37.2k13 gold badges84 silver badges147 bronze badges2 Answers
Reset to default 3I am only going to guess you would like the tags to be consistent across different deployments of AWS resources. In that case, I would suggest using default_tags
. They will be propagated to all resources. If there are however more specific ones, the result will be a merge of all the tags, unless there's overlap, in which case the non-default ones take precedence. Example:
provider "aws" {
default_tags {
tags = {
Author = "John Doe"
# other tags go here
}
}
}
resource "aws_vpc" "example" {
# ..other configuration...
}
output "vpc_resource_level_tags" {
value = aws_vpc.example.tags
}
output "vpc_all_tags" {
value = aws_vpc.example.tags_all
}
I would say the usual default tag when using terraform is CreatedBy = "terraform"
. If you need to really get down to the bottom of who really created a resource, I would argue tags are not really a best place for that. Using CloudTrail would help understanding who actually ran apply. Ideally, the apply command shouldn't be run by a person, rather by CI/CD, but that's a bit off-topic here.
Use locals
locals {
author_tag = "Author=YourName"
}
resource "aws_instance" "example" {
# aws config
tags = {
Author = local.author_tag
}
}
本文标签: amazon web servicesConstant tag values in TerraformStack Overflow
版权声明:本文标题:amazon web services - Constant tag values in Terraform - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281538a2370036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论