ALIYUN::ROS::Stack用于嵌套创建资源栈,最多支持5层嵌套。
ALIYUN::ROS::Stack类型在顶层模板中将资源栈作为资源进行嵌套。
您可以从该包含模板内的一个嵌套资源栈来添加输出值。您也可以将Fn::GetAtt函数与该嵌套资源栈的逻辑名称以及嵌套资源栈中Outputs.NestedStackOutputName格式的输出值名称结合使用。
当您应用模板更改来更新顶级资源栈时,ROS会更新顶级资源栈,并启动对其嵌套资源栈的更新。ROS将更新已修改嵌套资源栈的资源,但不更新未修改嵌套资源栈的资源。
语法
{
"Type": "ALIYUN::ROS::Stack",
"Properties": {
"TemplateURL": String,
"TimeoutMins": Number,
"Parameters": Map
}
}
属性
属性名称 | 类型 | 必须 | 允许更新 | 描述 | 约束 |
---|---|---|---|---|---|
TemplateURL | String | 否 | 是 |
模板主体的文件的位置 |
模板主体的文件最大为524288个字节,URL的最大长度为1024个字节。
URL必须指向位于Web服务器(HTTP、HTTPS)或阿里云OSS存储空间中的模板。例如: OSS地域如未指定,默认与资源栈RegionId相同。 必需指定 |
TemplateBody | Map | 否 | 是 | 模板内容,用于简化模板的传递 |
内容为原始数据,函数只在子模板中生效,不在当前模板中生效。 必需指定 |
TimeoutMins | Number | 否 | 是 | 创建或更新资源栈的超时时间 | 单位:分。
默认值:60 |
Parameters | Map | 否 | 是 | 一组值对,表示在创建此嵌套资源栈时传递给ROS的参数 | Parameters中的每个键都对应于嵌套资源栈模板中的参数名,每个值对应于参数取值。如果嵌套资源栈需要输入参数,则必须指定此参数。 |
返回值
Fn::GetAtt
您可以通过以下代码,获取嵌套栈的输出。
{
"Fn::GetAtt": [
"<nested_stack>",
"Outputs.<nested_stack_output_name>"
]
}
通过Ref
引用嵌套资源栈资源时,将获得嵌套资源栈的ARN。例如:arn:acs:ros::cn-hangzhou:12345****:stacks/test-nested-stack-Demo-jzkyq7mn****/e71c1e04-1a57-46fc-b9a4-cf7ce0d3****
。
示例
- 内层资源栈创建VPC、VSwitch、安全组示例(输出结果保存至oss://ros/template/vpc.txt)
{ "ROSTemplateFormatVersion": "2015-09-01", "Description": "One VPC, VSwitch, security group.", "Parameters": { "ZoneId": { "Type": "String", "Description": "The available zone" }, "SecurityGroupName": { "Type": "String", "Description": "The security group name", "Default": "my-sg-name" }, "VpcName": { "Type": "String", "Description": "The VPC name", "MinLength": 2, "MaxLength": 128, "ConstraintDescription": "[2, 128] English or Chinese letters", "Default": "my-vpc-name" }, "VpcCidrBlock": { "Type": "String", "AllowedValues": [ "192.168.0.0/16", "172.16.0.0/12", "10.0.0.0/8" ], "Default": "10.0.0.0/8" }, "VSwitchCidrBlock": { "Type": "String", "Description": "The VSwitch subnet which must be within VPC", "Default": "10.0.10.0/24" }, "UpdateVersion": { "Type": "Number", "Default": 0 } }, "Resources": { "Vpc": { "Type": "ALIYUN::ECS::VPC", "Properties": { "CidrBlock": { "Ref": "VpcCidrBlock" }, "VpcName": { "Ref": "VpcName" } } }, "VSwitch": { "Type": "ALIYUN::ECS::VSwitch", "Properties": { "CidrBlock": { "Ref": "VSwitchCidrBlock" }, "ZoneId": { "Ref": "ZoneId" }, "VpcId": { "Fn::GetAtt": [ "Vpc", "VpcId" ] } } }, "SecurityGroup": { "Type": "ALIYUN::ECS::SecurityGroup", "Properties": { "SecurityGroupName": { "Ref": "SecurityGroupName" }, "VpcId": { "Ref": "Vpc" } } }, "WaitConditionHandle": { "Type": "ALIYUN::ROS::WaitConditionHandle", "Properties": { "UpdateVersion": { "Ref": "UpdateVersion" } } } }, "Outputs": { "SecurityGroupId": { "Value": { "Fn::GetAtt": [ "SecurityGroup", "SecurityGroupId" ] } }, "VpcId": { "Value": { "Fn::GetAtt": [ "Vpc", "VpcId" ] } }, "VSwitchId": { "Value": { "Fn::GetAtt": [ "VSwitch", "VSwitchId" ] } } } }
- 外层资源栈示例
{ "ROSTemplateFormatVersion": "2015-09-01", "Description": "One ECS instance.", "Parameters": { "ImageId": { "Default": "centos_7", "Type": "String", "Description": "Image Id, represents the image resource to startup the ECS instance" }, "InstanceType": { "Type": "String", "Description": "The ECS instance type,", "Default": "ecs.xn4.small" }, "ZoneId": { "Type": "String", "Description": "The available zone " }, "InstanceChargeType": { "Type": "String", "AllowedValues": [ "PrePaid", "PostPaid" ], "Default": "PostPaid", "Description": "The instance charge type" }, "SecurityGroupName": { "Type": "String", "Description": "The security group name", "Default": "my-sg-name" }, "NetworkInterfaceName": { "Type": "String", "Description": "The Network interface name", "Default": "my-eni-name" }, "VpcName": { "Type": "String", "Description": "The VPC name", "MinLength": 2, "MaxLength": 128, "ConstraintDescription": "[2, 128] English or Chinese letters", "Default": "my-vpc-name" }, "IoOptimized": { "AllowedValues": [ "none", "optimized" ], "Description": "IO optimized, optimized is for the IO optimized instance type", "Type": "String", "Default": "optimized" }, "SystemDiskCategory": { "AllowedValues": [ "cloud", "cloud_efficiency", "cloud_ssd" ], "Description": "System disk category: average cloud disk(cloud), efficient cloud disk(cloud_efficiency) or SSD cloud disk(cloud_ssd)", "Type": "String", "Default": "cloud_ssd" }, "VpcCidrBlock": { "Type": "String", "AllowedValues": [ "192.168.0.0/16", "172.16.0.0/12", "10.0.0.0/8" ], "Default": "10.0.0.0/8" }, "VSwitchCidrBlock": { "Type": "String", "Description": "The VSwitch subnet which must be within VPC", "Default": "10.0.10.0/24" }, "UpdateVersion": { "Type": "Number", "Default": 0 } }, "Resources": { "NetworkStack": { "Type": "ALIYUN::ROS::Stack", "Properties": { "TemplateURL": "oss://ros/template/vpc.txt", "TimeoutMins": 5, "Parameters": { "ZoneId": { "Ref": "ZoneId" }, "SecurityGroupName": { "Ref": "SecurityGroupName" }, "VpcName": { "Ref": "VpcName" }, "VpcCidrBlock": { "Ref": "VpcCidrBlock" }, "VSwitchCidrBlock": { "Ref": "VSwitchCidrBlock" }, "UpdateVersion": { "Ref": "UpdateVersion" } } } }, "WebServer": { "Type": "ALIYUN::ECS::Instance", "Properties": { "ImageId": { "Ref": "ImageId" }, "InstanceType": { "Ref": "InstanceType" }, "InstanceChargeType": { "Ref": "InstanceChargeType" }, "SecurityGroupId": { "Fn::GetAtt": [ "NetworkStack", "Outputs.SecurityGroupId" ] }, "VpcId": { "Fn::GetAtt": [ "NetworkStack", "Outputs.VpcId" ] }, "VSwitchId": { "Fn::GetAtt": [ "NetworkStack", "Outputs.VSwitchId" ] }, "IoOptimized": { "Ref": "IoOptimized" }, "ZoneId": { "Ref": "ZoneId" }, "SystemDisk_Category": { "Ref": "SystemDiskCategory" }, "DiskMappings": [ { "Category": "cloud_ssd", "Size": 20 } ] } } }, "Outputs": { "InstanceId": { "Value": { "Fn::GetAtt": [ "WebServer", "InstanceId" ] } }, "PublicIp": { "Value": { "Fn::GetAtt": [ "WebServer", "PublicIp" ] } }, "SecurityGroupId": { "Value": { "Fn::GetAtt": [ "NetworkStack", "Outputs.SecurityGroupId" ] } }, "VpcId": { "Value": { "Fn::GetAtt": [ "NetworkStack", "Outputs.VpcId" ] } }, "VSwitchId": { "Value": { "Fn::GetAtt": [ "NetworkStack", "Outputs.VSwitchId" ] } }, "NetworkStackArn": { "Value": { "Ref": "NetworkStack" } } } }