雲計算

ROS模版(參數)

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  Vpc:
    Type: 'ALIYUN::ECS::VPC'
    Properties:
      VpcName: test-vpc
      CidrBlock: 192.168.0.0/16

使用這個模版創建資源時,因為Vpc的屬性硬編碼在模版中,所以想要創建多個不同name、不同網段的Vpc時必須修改模版內容,這樣的話模版的複用性就很差。

使用參數提高模版複用性

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcName:
    Type: String
    Default: my-vpc
  VpcCidrBlock:
    Type: String
    Default: 192.168.0.0/16
    AllowedValues:
      - 10.0.0.0/8
      - 172.16.0.0/12
      - 192.168.0.0/16
Resources:
  Vpc:
    Type: 'ALIYUN::ECS::VPC'
    Properties:
      VpcName:
        Ref: VpcName
      CidrBlock:
        Ref: VpcCidrBlock
  • Resources中,使用Ref引用參數,即模版的Parameters中定義的值
  • Parameters中定義參數,其值為Map類型,key為參數名(用於被資源引用),value(Map類型)為參數名。

參數value

  • Type(必填項):定義參數的類型,取值為String/Number/Json/Boolean,Type的取值類型與引用該參數的資源屬性類型相同,資源屬性為Map或List時,參數類型取值為Json。
  • Default(非必填項):參數的默認值,在創建資源時可修改
  • AllowedValues(非必填項):定義可選的參數值,參數取值必須從列表中選擇
  • 完整參數信息請參考參數(Parameters)

控制檯效果

image.png

Leave a Reply

Your email address will not be published. Required fields are marked *