【发布时间】:2018-08-15 10:19:48
【问题描述】:
我可以在参数部分 AWS CloudFormation 模板中将标签定义为参数并在每个创建的资源中使用它吗?
我当前的模板:
AWSTemplateFormatVersion: 2010-09-09
Description: "Some information"
Parameters:
Test1:
Type: String
Description: Test1
Default: t1
Test2:
Type: String
Description: Test2
Default: t2
...
LBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Enable access to app loadbalancer"
Tags:
- Key: Name
Value: !Join
- ""
- - !Ref Test1
- !Ref Test2
- Key: Test1
Value: !Ref Test1
- Key: Test2
Value: !Ref Test2
我对任何其他资源(AWS::ElasticLoadBalancing::LoadBalancer、AWS::AutoScaling::AutoScalingGroup 等)使用相同的标签,并且看起来像是重复的代码(每次创建新资源时)。我可以制作这样的东西吗?:
AWSTemplateFormatVersion: 2010-09-09
Description: "Some information"
Parameters:
Test1:
Type: String
Description: Test1
Default: t1
Test2:
Type: String
Description: Test2
Default: t2
Tag:
#define all tags, which I created above
...
LBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Enable access to app loadbalancer"
Tags: !Ref Tag
...
很遗憾,我在https://docs.aws.amazon.com/ 上没有找到任何相关信息
【问题讨论】:
-
您或许可以使用include transform 来执行此操作。但我认为这是一个丑陋的解决方案,所以不是答案。
标签: amazon-web-services templates yaml amazon-cloudformation