简体   繁体   中英

Referencing tags in resources with CloudFormation

How can I reference a common set of tags in cloudFormation without declaring tags in each resource if possible?

For example, with Terraform you can create a locals.tf file and have a block for tags to be applied across your deployed resources common_tags . Example:

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

By referencing the tags with tags = local.common_tags , I could assign tags to an s3 bucket as shown below, with just one line of code:

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

Is it possible to do the above, but with CloudFormation?

I resolved it by using the cli and update-stack command with the --tags option to push tags written in a tags.json file stored locally to my cloudFormation stack in AWS.

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>

Reference AWS documentation: https://docs.aws.amazon.com/cli/latest/reference/cloudformation/update-stack.html#update-stack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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