全部產品
Search
文件中心

:ALIYUN::ROS::Stack

更新時間:Jun 19, 2024

ALIYUN::ROS::Stack用於建立嵌套資源棧,最多支援5層嵌套。

嵌套資源棧本身可以包含其他嵌套資源棧,構成一個資源棧階層。根資源棧是所有嵌套資源棧最終歸屬的父資源棧,根資源棧的模板稱為頂層模板。ALIYUN::ROS::Stack類型在頂層模板中將資源棧作為資源進行嵌套。

您可以將嵌套資源棧模板中的一個資源棧的輸出用作另一個資源棧的輸入。您也可以使用Fn::GetAtt函數,將函數參數設定為嵌套資源棧的名稱和Outputs.NestedStackOutputName格式的輸出值,擷取嵌套資源棧的輸出。更多資訊,請參見使用嵌套資源棧

文法

{
  "Type": "ALIYUN::ROS::Stack",
  "Properties": {
    "TemplateURL": String,
    "TemplateBody": String,
    "TemplateId": String,
    "TemplateVersion": String,
    "TimeoutMins": Number,
    "Parameters": Map,
    "ResourceGroupId": String,
    "Tags": List
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

TemplateURL

String

模板主體的檔案的位置。

模板主體的檔案最大為524,288個位元組,URL的最大長度為1024個位元組。

URL必須指向位於Web伺服器(HTTP、HTTPS)或阿里雲OSS儲存空間中的模板。例如:oss://ros/template/demooss://ros/template/demo?RegionId=cn-hangzhou

OSS地區如未指定,預設與資源棧RegionId相同。

您必須指定TemplateURLTemplateBodyTemplateId其中一個。如果都指定,則使用TemplateBody

TemplateBody

Map

模板內容,用於簡化模板的傳遞。

內容為未經處理資料,函數只在子模板中生效,不在當前模板中生效。

您必須指定TemplateURLTemplateBodyTemplateId其中一個。如果都指定,則使用TemplateBody

TemplateId

String

模板ID。

您必須指定TemplateURLTemplateBodyTemplateId其中一個。如果都指定,則使用TemplateBody

TemplateVersion

String

模板版本名。

TimeoutMins

Number

建立或更新資源棧的逾時時間。

單位:分。

預設值:60。

Parameters

Map

一組索引值對,表示在建立此嵌套資源棧時傳遞給ROS的參數。

Parameters中的每個鍵都對應於嵌套資源棧模板中的參數名,每個值對應於參數取值。如果嵌套資源棧需要輸入參數,則必須指定此參數。

ResourceGroupId

String

資源群組ID。

Tags

List

標籤列表。

最多支援20個標籤。更多資訊。請參見Tags屬性

Tags文法

"Tags": [
  {
    "Key": String,
    "Value": String
  }
]

Tags屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

標籤鍵。

長度不超過128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

Value

String

標籤值。

長度不超過128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

傳回值

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

  • YAML格式

    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
    
  • JSON格式

    {
      "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"
            ]
          }
        }
      }
    }

父資源棧樣本

  • YAML格式

    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
    
  • JSON格式

    {
      "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"
          }
        }
      }
    }