[英]Pass stack tags to nested stack in Cloudformation
我可以使用AWS::CloudFormation::Stack
將參數傳遞給嵌套的Cloudformation AWS::CloudFormation::Stack
,包括引用的值:
"MyNestedStack" : {
"Type" : "AWS::CloudFormation::Stack",
"Condition" : "MyCondition",
"Properties" : {
"TemplateURL" : {
"Fn::Join" : ["", ["https://mybucket.s3.amazonaws.com/", {
"Ref" : "S3BucketLocation"
}, "/MyNestedStack.template"]]
},
"Parameters": {
"MyVPC" : {
"Ref" : "VPC"
},
"MySubnet" : {
"Ref" : "ManagementSubnet"
},
"MySubnetAZ" : {
"Fn::GetAtt" : [ "ManagementSubnet", "AvailabilityZone" ]
}
"InstanceType" : "m3.large",
"KeyName" : "MyKey",
}
}
}
但我無法找到任何文檔如何將應用於父堆棧的Stack標記傳遞給子(嵌套)堆棧。
原始堆棧被調用:
#Create Stack
aws cloudformation create-stack --parameters ${parms} --tags Key='Environment Name',Value=${name} Key=Name,Value=${env} --stack-name ${env} --template-url ${url}
Environment name
和Name
標簽應用於原始堆棧中的資源(如實例),但不應用於嵌套堆棧中的資源,也不應用於嵌套堆棧本身。
AWS已實現將堆棧標記傳播到子堆棧。 我無法找到反映此更改的公告或文檔,但現在可以使用了。
AWS CloudFormation資源標記類型頁面指出:
所有堆棧級標記(包括自動創建的標記)都會傳播到AWS CloudFormation支持的資源。
在下面的示例父/子堆棧模板中,父對象上的堆棧標記傳播到父堆棧中的EC2實例,子堆棧,子堆棧中的EC2實例。
注意:EC2標記仍然不會傳播到從塊設備映射創建的卷。
父堆棧示例
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Test Child Stack Tag Propagation (Parent Stack)",
"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName"
},
"Subnet": {
"Type": "AWS::EC2::Subnet::Id"
},
"VPC": {
"Type": "AWS::EC2::VPC::Id"
},
"AMI": {
"Type": "AWS::EC2::Image::Id",
"Default": "ami-f2210191"
},
"ChildTemplateUrl": {
"Type" : "String"
}
},
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : "t2.nano",
"SecurityGroupIds" : [{"Ref" : "InstanceSecurityGroup"}],
"SubnetId" : { "Ref" : "Subnet" },
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : {"Ref": "AMI"}
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Enable SSH access via port 22",
"VpcId" : { "Ref": "VPC"},
"SecurityGroupIngress" : [ {
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : "0.0.0.0/0"
} ]
}
},
"MyNestedStack" : {
"Type" : "AWS::CloudFormation::Stack",
"Properties" : {
"TemplateURL" : {"Ref": "ChildTemplateUrl"},
"Parameters": {
"Subnet" : {"Ref": "Subnet"},
"KeyName" : {"Ref": "KeyName"},
"AMI" : {"Ref": "AMI"},
"SecurityGroup": {"Ref" : "InstanceSecurityGroup"},
"VPC": {"Ref": "VPC"}
}
}
}
},
"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "EC2Instance" }
},
"IP" : {
"Description" : "Private IP address of the newly created VPC EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PrivateIp" ] }
}
}
}
兒童堆棧示例
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Test Child Stack Tag Propagation (Child Stack)",
"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName"
},
"Subnet": {
"Type": "AWS::EC2::Subnet::Id"
},
"VPC": {
"Type": "AWS::EC2::VPC::Id"
},
"AMI": {
"Type": "AWS::EC2::Image::Id"
},
"SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup::Id"
}
},
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : "t2.nano",
"SecurityGroupIds" : [{"Ref" : "SecurityGroup"}],
"SubnetId" : { "Ref" : "Subnet" },
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : {"Ref": "AMI"}
}
}
},
"Outputs" : {
"InstanceId" : {
"Description" : "InstanceId of the newly created EC2 instance",
"Value" : { "Ref" : "EC2Instance" }
},
"IP" : {
"Description" : "Private IP address of the newly created VPC EC2 instance",
"Value" : { "Fn::GetAtt" : [ "EC2Instance", "PrivateIp" ] }
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.