重用CloudFormation标签列表 [英] Reuse list of CloudFormation tags
问题描述
我有一组相当复杂的CloudFormation模板,可用于配置基础架构的不同环境。但是,我最近收到了用大量标签(例如15个)标记已创建资源的请求。
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?
我想这样写:
ECSAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
...
Tags: !Ref ElTags
而不是
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 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
文件my_tags.json的格式为
The file my_tags.json is of the format
[
{"Key": "mytag", "Value": "val"},
...
]
或者,您可以通过CodePipeline部署堆栈,并在模板配置
Alternatively, you could deploy your stack through CodePipeline and define the tags in the template configuration
这篇关于重用CloudFormation标签列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!