日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

資源(Resources)

資源(Resources)用于描述資源棧中每個資源的屬性和資源之間的依賴關系。一個資源可以被其他資源引用,也可以在輸出(Outputs)中被引用。

資源實體類型

資源實體類型分為普通資源和數據源資源,普通資源可進一步分為阿里云資源和自定義資源,具體如下表所示。

資源實體類型

說明

普通資源(Resource)

  • 阿里云資源:用于創建阿里云資源,以及對資源進行更新和刪除。阿里云資源類型以ALIYUN::開頭。

  • 自定義資源:用于創建自定義邏輯的資源,并可自定義資源如何更新和刪除。自定義資源類型以Custom::開頭,或者為ALIYUN::ROS::CustomResource。

    更多信息,請參見概覽。

數據源資源(DataSource)

用于查詢云服務資源數據。

更多信息,請參見數據源資源

語法

Resources由資源ID和資源描述組成。資源描述用大括號({ })括起。如果聲明多個資源,用半角逗號(,)分隔開。Resources的語法結構示例代碼段如下:

Resources:
  資源1 Name:
    Type: 資源類型
    Condition: 是否創建此資源的條件
    Properties: 資源屬性描述
  資源2 Name:
    Type: 資源類型
    Condition: 是否創建此資源的條件
    Properties: 資源屬性描述

參數說明如下:

  • 資源Name在模板中具有唯一性。在創建模板其他部分時,可以通過資源Name引用該資源。

  • 資源類型(Type)表示正在聲明的資源的類型。例如:ALIYUN::ECS::Instance表示阿里云ECS實例。關于ROS支持的所有資源類型列表和詳細信息,請參見資源類型索引

  • 資源屬性(Properties)是為資源指定的附加選項。例如:必須為每個阿里云ECS實例指定一個Image ID。

示例

Resources:
  ECSInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****

如果資源不需要聲明任何屬性,可以忽略該資源的屬性部分。

屬性值可以是文本字符串、字符串列表、布爾值、引用參數或者函數返回值。 當您編寫JSON模板時,請參見以下規則。

  • 如果屬性值為文本字符串,該值會被雙引號(" ")括起來。

  • 如果屬性值為任一類型的字符串列表,則會被方括號([ ])括起來。

  • 如果屬性值為內部函數或引用的參數,則會被大括號({ })括起來。

當您將文字、列表、引用參數和函數返回值合并起來取值時,上述規則也適用。聲明不同的屬性值類型示例如下:

{
  "Properties": {
    "String": "string",
    "LiteralList": [
      "value1",
      "value2"
    ],
    "Boolean": true,
    "ReferenceForOneValue": {
      "Ref": "ResourceID"
    },
    "FunctionResultWithFunctionParams": {
      "Fn::Join": [
        "%",
        [
          "Key=",
          {
            "Ref": "SomeParameter"
          }
        ]
      ]
    }
  }
}

DeletionPolicy

當您需要你移除資源時,會面臨兩種情況:

  • 當DeletionPolicy取值為Delete時,在從資源棧移除資源的同時,刪除資源本身。

  • 當DeletionPolicy取值為Retain時,在從資源棧移除資源的同時,保留資源本身。

例如:設置在資源棧刪除時保留ECS實例,可按照以下代碼段進行聲明:

Resources:
  ECSInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
    DeletionPolicy: Retain

在本示例中,如果該模板對應的資源棧被刪除,則會保留ECSInstance資源。

DependsOn

在模板中,設置DependsOn屬性,可以指定特定資源緊跟著另一個資源后創建。為某個資源添加DependsOn屬性后,該資源僅在DependsOn屬性中指定的資源之后創建。

重要

允許DependsOn依賴的資源ConditionFalse,為False時不影響該資源的創建。

用法示例包括以下兩種:

  • 依賴單個資源:

    DependsOn: ResourceName
  • 依賴多個資源:

    DependsOn:
      - ResourceName1
      - ResourceName2

如以下代碼段所示,WebServer將在DatabaseServer創建成功后才開始創建:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    DependsOn: DatabseServer
  DatabseServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small

Condition

在模板中,使用Condition屬性可以指定是否需要創建此資源。只有Condition所指定的條件值為True時,才會創建此資源。

如以下代碼段所示,根據MaxAmount的值判斷否創建WebServer:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  MaxAmount:
    Type: Number
    Default: 1
Conditions:
  CreateWebServer:
    Fn::Not:
      Fn::Equals:
        - 0
        - Ref: MaxAmount
Resources:
  WebServer:
    Type: ALIYUN::ECS::InstanceGroup
    Condition: CreateWebServer
    Properties:
      ImageId: m-25l0rc****
      InstanceType: ecs.t1.small
      MaxAmount:
        Ref: MaxAmount
  DatabseServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small

Count

在模板中,為資源指定Count后,ROS會對模板進行預處理,把該資源展開成多個資源。 操作資源棧時使用處理后的模板。

  • 例如:資源名為A,其Count值為3。在處理后的模板中,沒有A資源,取而代之的是A[0]、A[1]A[2]這3個資源。

    Resources:
      A:
        Count: 3
        ...

    處理后:

    Resources:
      A[0]:
        ...
      A[1]:
        ...
      A[2]:
        ...
    重要

    如果展開后的資源的名稱在原模板中已存在,比如A[1]在原模板中已經定義,則預處理失敗,校驗不通過。

    請避免向已有資源添加Count屬性,因為這會導致資源名發生變化,引發刪除操作。

  • Count最終結果必須為自然數,僅支持如下函數:

  • 處理后的模板資源總數需要符合限制,目前最多支持300個。

  • 指定了Count的資源的屬性(Properties)中可以使用偽參數ALIYUN::Index,在預處理的時候會被替換為相應的數值。例如,A[0]使用的ALIYUN::Index會被替換為0,A[1]使用的ALIYUN::Index會被替換為1。模板其他地方不能使用ALIYUN::Index

  • 如果指定了Count的資源出現在DependsOn中,會被展開。

    DependsOn: A

    處理后:

    DependsOn:
      - A[0]
      - A[1]
      - A[2]
  • 如果指定了Count的資源出現在函數Ref、Fn::GetAtt中,會被展開。

    Ref: A
    Fn::GetAtt:
      - A
      - PropertyName

    處理后:

    - Ref: A[0]
    - Ref: A[1]
    - Ref: A[2]
    - Fn::GetAtt:
        - A[0]
        - PropertyName
    - Fn::GetAtt:
        - A[1]
        - PropertyName
    - Fn::GetAtt:
        - A[2]
        - PropertyName

    如果多個資源使用Count,并且存在引用關系。建議與Fn::Select以及ALIYUN::Index聯合使用。

    Fn::Select:
      - Ref: ALIYUN::Index
      - Ref: A

    A為例,B引用了A,且BCount為2,轉換后B[0]、B[1]中部分表達式分別如下:

    - Ref: A[0]
    - Ref: A[1]
  • 如果資源指定了Count屬性,則DependsOn屬性也支持表達式。DependsOn屬性的表達式可以使用的函數與Count屬性一致,可以使用ALIYUN::Index偽參數。表達式的格式與允許的計算結果如下表所示。

    格式

    示例

    允許的計算結果

    字典。

    Fn::Split:
      - ','
      - Server1,Server2

    null。

    如果為null值,則會移除DependsOn屬性。

    字符串。

    • 如果是空字符串,則會移除DependsOn屬性。

    • 如果是非空字符串,則必須是有效的資源名稱。

    列表。

    • 如果列表項為null或空字符串,則丟棄該列表項。

    • 如果列表為空,則會移除DependsOn屬性。

    • 如果列表不為空,則每一項必須是字符串,且為有效的資源名稱。

    列表。

    - Server0
    - Fn::Split:
        - ','
        - Server1,Server2

    列表項可以是字典或字符串,不同列表項允許的計算結果不同,具體如下:

    • 如果列表項為字典,則會進行表達式計算,允許的計算結果如下:

      • 如果為null值或空字符串,則丟棄該項。

      • 否則,必須是字符串,且為有效的資源名稱。

    • 如果列表項為字符串,則必須是有效的資源名稱。

    說明

    如果列表為空,則會移除DependsOn屬性。

    字符串。

    Server0

    字符串。

    不會進行額外的處理。

    如下示例模板用于控制Count資源單并發數。參數Count表示要創建的資源的數量,參數ParallelCount代表最大并發創建數。

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      Count:
        Type: Number
      ParallelCount:
        Type: Number
    Resources:
      WaitConditionHandle:
        Type: ALIYUN::ROS::WaitConditionHandle
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - WaitConditionHandle[index]

    當Count和ParallelCount取值不同時,處理后的模板也有差異,具體如下:

    • 若設置Count為3,ParallelCount為1,則處理后的模板為:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number
    • 若設置Count為5,ParallelCount為2,則處理后的模板為:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[3]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
        WaitConditionHandle[4]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[2]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number
    • 若設置Count為5,ParallelCount為3,則處理后的模板為:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[3]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[4]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number

Count的示例模板如下。示例模板中創建了一組EIP和同等數量的ECS,并把EIP與ECS逐一綁定。

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Count:
    Type: Number
Resources:
  Eip:
    Type: ALIYUN::VPC::EIP
    Count:
      Ref: Count
    Properties:
      Bandwidth: 5
  Servers:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      MinAmount:
        Ref: Count
      MaxAmount:
        Ref: Count
      AllocatePublicIP: false
      ...: Null
  EipBind:
    Type: ALIYUN::VPC::EIPAssociation
    Count:
      Ref: Count
    Properties:
      InstanceId:
        Fn::Select:
          - Ref: ALIYUN::Index
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Fn::Select:
          - Ref: ALIYUN::Index
          - Ref: Eip
Outputs:
  InstanceIds:
    Value:
      Fn::GetAtt:
        - Servers
        - InstanceIds
  AllocationIds:
    Value:
      Ref: Eip
  EipAddresses:
    Value:
      Fn::GetAtt:
        - Eip
        - EipAddress

處理后:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Count:
    Type: Number
Resources:
  Eip[0]:
    Type: ALIYUN::VPC::EIP
    Properties:
      Bandwidth: 5
  Eip[1]:
    Type: ALIYUN::VPC::EIP
    Properties:
      Bandwidth: 5
  Servers:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      MinAmount:
        Ref: Count
      MaxAmount:
        Ref: Count
      AllocatePublicIP: false
      ...: Null
  EipBind[0]:
    Type: ALIYUN::VPC::EIPAssociation
    Properties:
      InstanceId:
        Fn::Select:
          - 0
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Ref: Eip[0]
  EipBind[1]:
    Type: ALIYUN::VPC::EIPAssociation
    Properties:
      InstanceId:
        Fn::Select:
          - 1
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Ref: Eip[1]
Outputs:
  InstanceIds:
    Value:
      Fn::GetAtt:
        - Servers
        - InstanceIds
  AllocationIds:
    Value:
      - Ref: Eip[0]
      - Ref: Eip[1]
  EipAddresses:
    Value:
      - Fn::GetAtt:
          - Eip[0]
          - EipAddress
      - Fn::GetAtt:
          - Eip[1]
          - EipAddress

資源聲明示例

典型的資源聲明示例如下:

Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small
      SecurityGroupId: sg-25zwc****
      ZoneId: cn-beijing-b
      Tags:
        - Key: Department1
          Value: HumanResource
        - Key: Department2
          Value: Finance
  ScalingConfiguration:
    Type: ALIYUN::ESS::ScalingConfiguration
    Properties:
      ImageId: ubuntu_14_04_64_20G_aliaegis_2015****.vhd
      InstanceType: ecs.t1.small
      InstanceId: i-25xhh****
      InternetChargeType: PayByTraffic
      InternetMaxBandwidthIn: 1
      InternetMaxBandwidthOut: 20
      SystemDisk_Category: cloud
      ScalingGroupId: bwhtvpcBcKYac9fe3vd0****
      SecurityGroupId: sg-25zwc****
      DiskMappings:
        - Size: 10
        - Category: cloud
          Size: 10