繁体   English   中英

使用 CloudFormation 引用资源中的标签

[英]Referencing tags in resources with CloudFormation

如果可能,如何在不声明每个资源中的标签的情况下引用 cloudFormation 中的一组通用标签?

例如,使用 Terraform 您可以创建一个locals.tf文件,并为要在部署的资源中应用的标签提供一个块common_tags 例子:

locals {
  common_tags = {
    project = "asigra_errors_processing"
    environment = "dev"
    author = "zimcanit"
    }
}

通过使用tags = local.common_tags引用标签,我可以将标签分配给 s3 存储桶,如下所示,只需一行代码:

resource "aws_s3_bucket" "asigra_s3" {
    bucket = "logged-asigra-errors-2022"
    region = var.aws_region
    tags = local.common_tags
}

是否可以使用 CloudFormation 执行上述操作?

我通过使用带有 --tags 选项的 cli 和 update-stack 命令来解决它,以将在 tags.json 文件中写入的标签推送到我在 AWS 中的 cloudFormation 堆栈中。

aws cloudformation update-stack --stack-name infrastructure --template-body  file://<insert filepath to cloudformation template file here> --tags file://<insert filepath to json file containing tags to be propogated across deployed resources>

参考 AWS 文档: https://docs.aws.amazon.com/cli/latest/reference/cloudformation/update-stack.html#update-stack

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM