I have a rather complex set of CloudFormation templates that I use for provisioning the different environments of our infrastructure. However I recently got the request to tag the created resources with a rather extensive list of tags (like 15).
Hardcoding the tags into each of the template file doesn't seem like a good idea to me. I would rather create the list of tags once and refer to them for every taggeable resource. Problem is: I am not even sure this is possible. Do you know of any way that a reusable list of tags can be achieved?
I want to write this:
ECSAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
...
Tags: !Ref ElTags
rather than
ECSAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
...
Tags: !Ref ElTags
- Key: Name
Value: !Join ["-", [!Ref EnvironmentName, 'ecs-as-group'] ]
PropagateAtLaunch: true
- Key: TEAM
Value: !Ref TeamName
PropagateAtLaunch: true
You simply create a separate template for the resources that you want to reuse and then save that template in an Amazon S3 bucket. Whenever you want to add those resources in another template, use the AWS::CloudFormation::Stack resource to specify the S3 URL of the nested template.
To update a AWS CloudFormation stack (console)In the AWS CloudFormation console , from the list of stacks, select the running stack that you want to update. In the stack details pane, choose Update. If you haven't modified the stack template, select Use current template, and then choose Next.
If you use nested stacks, rolling back the parent stack will attempt to roll back all the child stacks as well. Open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . Select the stack that you want to update, choose Stack actions, and then choose Continue update rollback.
Stack names are "reusable". Each stack deployment is identified by its own unique Stack ID . The stack ID lets CloudFormation keep track of the stack history across multiple deployments if the same stack name.
You can easily reuse tags if you don't pass them to the template but instead reference them during deployment. The tags will be propagated to all ressources of the stack. A command similar to the one below might meet your needs:
aws cloudformation create-stack --stack-name mystack \
--template-body file://my_template.yaml --tags file://my_tags.json
The file my_tags.json is of the format
[
{"Key": "mytag", "Value": "val"},
...
]
Alternatively, you could deploy your stack through CodePipeline and define the tags in the template configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With