資源編排服務(wù)ROS(Resource Orchestration Service)支持Count功能,用于批量創(chuàng)建資源,滿足復(fù)雜場(chǎng)景或者動(dòng)態(tài)化場(chǎng)景的需求。本文為您介紹如何使用Count功能進(jìn)行大規(guī)模部署。

擴(kuò)容場(chǎng)景

本場(chǎng)景將使用Count功能,批量創(chuàng)建ECS(按量付費(fèi)的ECS)。以創(chuàng)建3000個(gè)ECS為例,共計(jì)需要36183個(gè)資源,具體如下:

資源數(shù)量說明
ALIYUN::ECS::NetworkInterface9000個(gè)1個(gè)ECS要綁定3個(gè)彈性網(wǎng)卡(ENI)。
ALIYUN::ECS::NetworkInterfaceAttachment9000個(gè)該資源用于綁定彈性網(wǎng)卡(ENI)到專有網(wǎng)絡(luò)(VPC)類型實(shí)例上。
ALIYUN::VPC::EIP9000個(gè)1個(gè)彈性網(wǎng)卡(ENI)要綁定1個(gè)彈性公網(wǎng)IP(EIP)。
ALIYUN::VPC::EIPAssociation9000個(gè)該資源用于綁定彈性公網(wǎng)IP(EIP)。
ALIYUN::ECS::InstanceGroup3個(gè)1個(gè)ALIYUN::ECS::InstanceGroup最多包含1000個(gè)ECS資源。
ALIYUN::VPC::CommonBandwidthPackage90個(gè)100個(gè)彈性公網(wǎng)IP(EIP)需要1個(gè)共享帶寬包。
ALIYUN::VPC::CommonBandwidthPackageIp90個(gè)該資源用于添加彈性公網(wǎng)IP(EIP)到共享帶寬中。

因?yàn)槊總€(gè)資源棧最多容納300個(gè)資源,無法滿足需求,故需結(jié)合嵌套資源棧功能和Count功能設(shè)計(jì)解決方案。

方案一:基礎(chǔ)方案

首先,假定ECS數(shù)量為M,將資源劃分到子資源棧中,并使用父資源棧進(jìn)行整合。

  • 子資源棧A:用于創(chuàng)建ECS,綁定ENI和EIP。
    假定ECS數(shù)量為N,0<=N<=20,那么子資源棧最多包含1+240=241個(gè)資源。
    • 20個(gè)ECS:1個(gè)ALIYUN::ECS::InstanceGroup資源。
    • ENI+EIP:20*12=240。
  • 子資源棧B:用于創(chuàng)建共享帶寬包,關(guān)聯(lián)共享帶寬包和EIP。
    子資源棧中共享帶寬包數(shù)量為3,那么子資源棧最多包含(1+1)*3=6個(gè)資源。
    • 因?yàn)?個(gè)ECS綁定了3個(gè)EIP,對(duì)應(yīng)于三條網(wǎng)絡(luò)線路,所以放3個(gè)共享帶寬包。
    • 因?yàn)?00個(gè)EIP要加入1個(gè)共享帶寬包中,所以1個(gè)子資源棧B最多可以容納300個(gè)EIP。1個(gè)子資源棧A產(chǎn)生最多60個(gè)EIP,所以一個(gè)子資源棧B對(duì)應(yīng)于5個(gè)子資源棧A。
  • 父資源棧:主要用于整合子資源棧。

    資源總數(shù)為150+30=180,能夠放入一個(gè)資源棧中。

    • 子資源棧A:數(shù)量為(M+20-1)//20,最大值為150。因?yàn)槊?個(gè)子資源棧A的輸出會(huì)作為1個(gè)子資源B的輸入。子資源棧A的個(gè)數(shù)需要對(duì)齊到5,這樣會(huì)包含一些N取值為0的子資源棧A。所以最終數(shù)量為((M+20-1)//20+4)//5*5,最大值仍為150。
    • 子資源棧B:數(shù)量為子資源棧A的1/5,即((M+20-1)//20+4)//5,最大值為30。

其次,進(jìn)行模板設(shè)計(jì)。

  • 子資源棧A
    • Eni[0]、Eni[1]、Eni[2]綁定到Servers[0],Eni[3]、Eni[4]、Eni[5]綁定到Servers[1],依此類推,Eni[3*i]、Eni[3*i+1]、Eni[3*i+2]綁定到Servers[i],0<=i<=N-1。
    • Eip-ChinaTelecom[i]綁定到Eni[3*i]、Eip-ChinaUnicom[i]綁定到Eni[3*i+1]、Eip-ChinaMobile[i]綁定到Eni[3*i+2],0<=i<=N-1。這樣1個(gè)ECS就綁定了3個(gè)不同ISP的EIP。
    說明 此處ISP使用ChinaTelecom、ChinaUnicom和ChinaMobile僅作為示例。
    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      NumberOfEcs:
        Type: Number
        MinValue: 0
        MaxValue: 20
    Conditions:
      NonEmpty:
        Fn::Not:
          Fn::Equals:
            - 0
            - Ref: NumberOfEcs
    Resources:
      Servers:
        Type: ALIYUN::ECS::InstanceGroup
        Condition: NonEmpty
        Properties:
          MinAmount:
            Ref: NumberOfEcs
          MaxAmount:
            Ref: NumberOfEcs
      Eni:
        Type: ALIYUN::ECS::NetworkInterface
        Count:
          Fn::Calculate:
            - '{0}*3'
            - 0
            - - Ref: NumberOfEcs
        Properties: null
      EniBinder:
        Type: ALIYUN::ECS::NetworkInterfaceAttachment
        Count:
          Fn::Calculate:
            - '{0}*3'
            - 0
            - - Ref: NumberOfEcs
        Properties:
          InstanceId:
            Fn::Select:
              - Fn::Calculate:
                  - '{0}//3'
                  - 0
                  - Ref: ALIYUN::Index
              - Fn::GetAtt:
                  - Servers
                  - InstanceIds
          NetworkInterfaceId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eni
      Eip-ChinaTelecom:
        Type: ALIYUN::VPC::EIP
        Count:
          Ref: NumberOfEcs
        Properties:
          Isp: ChinaTelecom
      Eip-ChinaTelecom-Binder:
        Type: ALIYUN::VPC::EIPAssociation
        Count:
          Ref: NumberOfEcs
        Properties:
          InstanceId:
            Fn::Select:
              - Fn::Calculate:
                  - '{0}*3'
                  - 0
                  - - Ref: ALIYUN::Index
              - Ref: Eni
          AllocationId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eip-ChinaTelecom
      Eip-ChinaUnicom:
        Type: ALIYUN::VPC::EIP
        Count:
          Ref: NumberOfEcs
        Properties:
          Isp: ChinaUnicom
      Eip-ChinaUnicom-Binder:
        Type: ALIYUN::VPC::EIPAssociation
        Count:
          Ref: NumberOfEcs
        Properties:
          InstanceId:
            Fn::Select:
              - Fn::Calculate:
                  - '{0}*3+1'
                  - 0
                  - - Ref: ALIYUN::Index
              - Ref: Eni
          AllocationId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eip-ChinaUnicom
      Eip-ChinaMobile:
        Type: ALIYUN::VPC::EIP
        Count:
          Ref: NumberOfEcs
        Properties:
          Isp: ChinaMobile
      Eip-ChinaMobile-Binder:
        Type: ALIYUN::VPC::EIPAssociation
        Count:
          Ref: NumberOfEcs
        Properties:
          InstanceId:
            Fn::Select:
              - Fn::Calculate:
                  - '{0}*3+2'
                  - 0
                  - - Ref: ALIYUN::Index
              - Ref: Eni
          AllocationId:
            Fn::Select:
              - Ref: ALIYUN::Index
              - Ref: Eip-ChinaMobile
    Outputs:
      Eips-ChinaTelecom:
        Value:
          Ref: Eip-ChinaTelecom
      Eips-ChinaUnicom:
        Value:
          Ref: Eip-ChinaUnicom
      Eips-ChinaMobile:
        Value:
          Ref: Eip-ChinaMobile
  • 子資源棧B

    這是一個(gè)普通模板,ChinaTelecom的EIP加入ChinaTelecom的共享帶寬包,ChinaUnicom的EIP加入ChinaUnicom的共享帶寬包,ChinaMobile的EIP加入ChinaMobile的共享帶寬包。

    說明 此處使用ChinaTelecom、ChinaUnicom和ChinaMobile僅作為示例。
    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      Eips-ChinaTelecom:
        Type: Json
      Eips-ChinaUnicom:
        Type: Json
      Eips-ChinaMobile:
        Type: Json
    Resources:
      CommonBandwidthPackage-ChinaTelecom:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Properties: null
      CommonBandwidthPackage-ChinaTelecom-IpBinder:
        Type: ALIYUN::VPC::CommonBandwidthPackageIp
        Properties:
          Eips:
            Ref: Eips-ChinaTelecom
          BandwidthPackageId:
            Ref: CommonBandwidthPackage-ChinaTelecom
      CommonBandwidthPackage-ChinaUnicom:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Properties: null
      CommonBandwidthPackage-ChinaUnicom-IpBinder:
        Type: ALIYUN::VPC::CommonBandwidthPackageIp
        Properties:
          Eips:
            Ref: Eips-ChinaUnicom
          BandwidthPackageId:
            Ref: CommonBandwidthPackage-ChinaUnicom
      CommonBandwidthPackage-ChinaMobile:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Properties: null
      CommonBandwidthPackage-ChinaMobile-IpBinder:
        Type: ALIYUN::VPC::CommonBandwidthPackageIp
        Properties:
          Eips:
            Ref: Eips-ChinaMobile
          BandwidthPackageId:
            Ref: CommonBandwidthPackage-ChinaMobile
  • 父資源棧
    嵌套資源棧要求模板通過URL提供,將兩個(gè)子資源棧的模板加入OSS Bucket。假定子資源棧A的模板地址為oss://templates/resourses-a,子資源棧B的模板地址為oss://templates/resourses-b。
    • 資源A為子資源棧A。

      NumberOfEcs的取值表達(dá)式為(1-(({1}+1)//(({0}+19)//20+1)+999)//1000)*((({0}-20*{1})//20+{0})//({0}+1)*(20-({0}-{0}//20*20))+({0}-{0}//20*20)),計(jì)算方法如下:

      • 限制條件:Fn::Calculate只能使用加、減、乘、浮點(diǎn)除(/)、整數(shù)除(//)五種運(yùn)算。
      • 取值規(guī)則:從第0組開始,每次從M中取20個(gè);如果不足20個(gè),則取剩下的所有;如果已取完,則為0。通過舉例了解子資源棧A中NumberOfEcs參數(shù)應(yīng)該的取值:
        • 當(dāng)M=1時(shí),A.Count為5,NumberOfEcs依次為1、0、0、0、0。
        • 當(dāng)M=20時(shí),A.Count為5,NumberOfEcs依次為20、0、0、0、0。
        • 當(dāng)M=99時(shí),A.Count為5,NumberOfEcs依次為20、20、20、20、19。
        • 當(dāng)M=100時(shí),A.Count為5,NumberOfEcs依次為20、20、20、20、20。
        • 當(dāng)M=101時(shí),A.Count為10,NumberOfEcs依次為20、20、20、20、20、1、0、0、0、0。
      • 數(shù)學(xué)技巧:
        • 技巧1:如何將序列 0, 1, 2, ... 轉(zhuǎn)換成 0, 1, 1, ...?

          使用 F(x, t)=(x + t) // (t + 1),其中t>=Max(x)。當(dāng)x為0時(shí),F(xiàn)(0)=0;當(dāng)x>=1,F(xiàn)(x)>=1,而 F(x) = (x + t) // (t + 1) <= (x + Max(x)) // (Max(x) + 1) <= (Max(x) + Max(x)) // (Max(x) + 1) < 2,所以F(x)=1。

        • 技巧2:如何將0、1的序列轉(zhuǎn)換成P、Q的序列?

          令G(x, P, Q)=x*(Q-P)+P,x取值為0或1。f(0)=P,f(1)=Q。

        • 技巧3:如果計(jì)算M和N的余數(shù)?

          M%N = M-M//N*N。

      • 表達(dá)式:

        定義N=20,U=(M+N-1)//N,V=(U+4)//5*5,則U表示對(duì)齊到5前子資源棧A的數(shù)量,V表示對(duì)齊到5后子資源棧A的數(shù)量,也就是實(shí)際數(shù)量。

        當(dāng)M=101時(shí),觀察f(i)=(M-N*i)//N(i為編號(hào),對(duì)應(yīng)于ALIYUN::Index偽參數(shù),0<=i<V,U=6,V=10),其值依次為f(0)=5、f(1)=4、f(2)=3、f(3)=2、f(4)=1、f(5)=0、f(6)=-1、f(7)=-2、f(8)=-3、f(9)=-4。

        • 0<=i<U

          序列為5、4、3、2、1、0,利用技巧1,可以將其轉(zhuǎn)換為1、1、1、1、1、0。

          令t = M >= Max(f(i)),則g(i) = F(f(i), M) = ((M-N*i)//N + M) // (M+1),這是序列函數(shù)。利用技巧2,可以將序列轉(zhuǎn)換為20、20、20、20、20、1,也就是0<=i<U時(shí)NumberOfEcs的取值。

          令P=M%N,Q=N, h(i) = G(g(i), M%N, N) = (((M-N*i)//N + M) // (M+1)) * (N - (M-M//N*N)) + (M-M//N*N)。

        • i>=U

          0<=i<U時(shí),值為1;i>=U時(shí),值為0。觀察k(i)=(i+1)//(U+1),當(dāng)0<=i<U時(shí),值為0;i>=U時(shí),值>=1。

          使用技巧1,即可轉(zhuǎn)換成0和1的序列。我們估算下k(i)的最大值:Max(k(i))=V//(U+1)=(U+4)//5*5//(U+1)<=4,t取4即可,這里我們?nèi)?99。

          新序列p(i) = 1- F(k(i), 999) = 1 - ((i+1)//((M+N-1)//N+1) + 999) // 1000。當(dāng)0<=i<U時(shí),值為1;i>=U時(shí),值0。

        最終的序列q(i) = p(i) * h(i) = (1 - ((i+1)//((M+N-1)//N+1) + 999) // 1000) * (((M-N*i)//N + M) // (M+1)) * (N - (M-M//N*N)) + (M-M//N*N)。令M={0}, i={1}, N=20代入q(i)得到表達(dá)式:(1-(({1}+1)//(({0}+19)//20+1)+999)//1000)*((({0}-20*{1})//20+{0})//({0}+1)*(20-({0}-{0}//20*20))+({0}-{0}//20*20))。

    • 資源B為子資源棧B。

      子資源棧B[i]會(huì)將子資源棧A[5*i]、A[5*i+1]、A[5*i+2]、A[5*i+3]、A[5*i+4]的輸出拼接在一起作為輸入。

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  NumberOfEcs:
    Type: Number
    MinValue: 0
Resources:
  A:
    Type: ALIYUN::ROS::Stack
    Count:
      Fn::Calculate:
        - (({0}+19)//20+4)//5*5
        - 0
        - - Ref: NumberOfEcs
    Properties:
      TemplateURL: oss://templates/resourses-a
      Parameters:
        NumberOfEcs:
          Fn::Calculate:
            - (1-(({1}+1)//(({0}+19)//20+1)+999)//1000)*((({0}-20*{1})//20+{0})//({0}+1)*(20-({0}-{0}//20*20))+({0}-{0}//20*20))
            - 0
            - - Ref: NumberOfEcs
              - Ref: ALIYUN::Index
  B:
    Type: ALIYUN::ROS::Stack
    Count:
      Fn::Calculate:
        - (({0}+19)//20+4)//5
        - 0
        - - Ref: NumberOfEcs
    Properties:
      TemplateURL: oss://templates/resourses-b
      Parameters:
        Eips-ChinaTelecom:
          Fn::ListMerge:
            - Fn::Select:
                - Fn::Calculate:
                    - 5*{0}
                    - 0
                    - - Ref: ALIYUN::Index
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom
            - Fn::Select:
                - Fn::Calculate:
                    - 5*{0}+1
                    - 0
                    - - Ref: ALIYUN::Index
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom
            - Fn::Select:
                - Fn::Calculate:
                    - 5*{0}+2
                    - 0
                    - - Ref: ALIYUN::Index
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom
            - Fn::Select:
                - Fn::Calculate:
                    - 5*{0}+3
                    - 0
                    - - Ref: ALIYUN::Index
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom
            - Fn::Select:
                - Fn::Calculate:
                    - 5*{0}+4
                    - 0
                    - - Ref: ALIYUN::Index
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom

5個(gè)資源棧A對(duì)應(yīng)一個(gè)資源棧B,5是固定的,無法實(shí)現(xiàn)動(dòng)態(tài)。因?yàn)镕n::Select已經(jīng)支持slice選取功能,通過Start:Stop:Step的方式從列表中選取多個(gè)元素,所以可以實(shí)現(xiàn)動(dòng)態(tài)化。

結(jié)合宙斯場(chǎng)景,使用Fn::Min簡化表達(dá)式。新模板如下:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  NumberOfEcs:
    Type: Number
    MinValue: 0
Resources:
  A:
    Type: ALIYUN::ROS::Stack
    Count:
      Fn::Calculate:
        - ({0}+19)//20
        - 0
        - - Ref: NumberOfEcs
    Properties:
      TemplateURL: oss://templates/resourses-a
      Parameters:
        NumberOfEcs:
          Fn::Min:
            - 20
            - Fn::Calculate:
                - '{0}-{1}*20'
                - 0
                - - Ref: NumberOfEcs
                  - Ref: ALIYUN::Index
  B:
    Type: ALIYUN::ROS::Stack
    Count:
      Fn::Calculate:
        - (({0}+19)//20+4)//5
        - 0
        - - Ref: NumberOfEcs
    Properties:
      TemplateURL: oss://templates/resourses-b
      Parameters:
        Eips-ChinaTelecom:
          Fn::ListMerge:
            - Fn::Select:
                - Fn::Replace:
                    - Start:
                        Fn::Calculate:
                          - 5*{0}
                          - 0
                          - - Ref: ALIYUN::Index
                      Stop:
                        Fn::Calculate:
                          - 5*({0}+1)
                          - 0
                          - - Ref: ALIYUN::Index
                    - Start:Stop
                - Fn::GetAtt:
                    - A
                    - Eips-ChinaTelecom

方案二:優(yōu)化方案

將資源進(jìn)行重新劃分:

  • 子資源棧A:將ALIYUN::VPC::CommonBandwidthPackageIp加入子資源棧A中。
  • 子資源棧B:將所有ALIYUN::VPC::CommonBandwidthPackage加入一個(gè)子資源棧B中。子資源棧B本身的數(shù)量不再需要使用Count,但里面的資源需要使用Count。子資源棧B輸出創(chuàng)建的共享帶寬包ID列表,并傳遞給子資源棧A。

將所有參數(shù)動(dòng)態(tài)化:

  • 將子資源A的ECS數(shù)量最大值20,變成參數(shù)MaxNumberOfEcsPerStack。
  • 將100個(gè)EIP存放的共享帶寬包數(shù)量1,變成參數(shù)MaxNumberOfEipPerBandwidthPackage。
  • 在父資源中創(chuàng)建子資源A時(shí),傳遞EipIndexOffset=ALIYUN::Index * MaxNumberOfEcsPerStack。
  • 在子資源棧A中通過計(jì)算構(gòu)建動(dòng)態(tài)數(shù)量的ALIYUN::VPC::CommonBandwidthPackageIp,將EIP分組后綁定到不同的共享帶寬包。

優(yōu)化后模板如下:

  • 子資源棧A

    令A(yù)=EipIndexOffset,B=NumberOfEcs,C=MaxNumberOfEipPerBandwidthPackage,i=ALIYUN::Index:A//C 為Stack內(nèi)第一個(gè)EIP要綁定的共享帶寬包的編號(hào)。(A+B-1)//C 為Stack內(nèi)最后一個(gè)EIP要綁定的共享帶寬包的編號(hào)。所以CommonBandwidthPackage-ChinaTelecom-IpBinder.Count = ((A+B-1)//C-A//C)+1。

    所以CommonBandwidthPackage-ChinaTelecom-IpBinder.BandwidthPackageId=CommonBandwidthPackage-ChinaTelecom-List[A//C+i]。組內(nèi)的Eip-ChinaTelecom該如何分散到CommonBandwidthPackage-ChinaTelecom-IpBinder,我們從全局的角度看:

    全局編號(hào)在 [ (A//C+i)*C, (A//C+i+1)*C ) 之間的CommonBandwidthPackage-ChinaTelecom-IpBinder[ (A//C+i) ] 中。將全局編號(hào)轉(zhuǎn)換成局部編號(hào),只需要減去偏移,即 [ (A//C+i)*C - A, (A//C+i+1)*C - A ) 。但這個(gè)范圍必須限制到 [0, B]中,所以結(jié)果為[ Max((A//C+i)*C - A, 0), Min((A//C+i+1)*C - A, B) ]。

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      NumberOfEcs:
        Type: Number
        MinValue: 1
      MaxNumberOfEipPerBandwidthPackage:
        Type: Number
        MinValue: 1
      EipIndexOffset:
        Type: Number
      CommonBandwidthPackage-ChinaTelecom-List:
        Type: Json
      CommonBandwidthPackage-ChinaUnicom-List:
        Type: Json
      CommonBandwidthPackage-ChinaMobile-List:
        Type: Json
    Conditions:
      NonEmpty:
        Fn::Not:
          Fn::Equals:
            - 0
            - Ref: NumberOfEcs
    Resources:
      CommonBandwidthPackage-ChinaTelecom-IpBinder:
        Type: ALIYUN::VPC::CommonBandwidthPackageIp
        Count:
          Fn::Calculate:
            - (({0}+{1}-1)//{2}-{0}//{2})+1
            - 0
            - - Ref: EipIndexOffset
              - Ref: NumberOfEcs
              - Ref: MaxNumberOfEipPerBandwidthPackage
        Properties:
          Eips:
            Fn::Select:
              - Fn::Replace:
                  - Start:
                      Fn::Max:
                        - 0
                        - Fn::Calculate:
                            - ({0}//{2}+{1})*{2}-{0}
                            - 0
                            - - Ref: EipIndexOffset
                              - Ref: ALIYUN::Index
                              - Ref: MaxNumberOfEipPerBandwidthPackage
                    Stop:
                      Fn::Min:
                        - Ref: NumberOfEcs
                        - Fn::Calculate:
                            - ({0}//{2}+{1}+1)*{2}-{0}
                            - 0
                            - - Ref: EipIndexOffset
                              - Ref: ALIYUN::Index
                              - Ref: MaxNumberOfEipPerBandwidthPackage
                  - Start:Stop
              - Ref: Eip-ChinaTelecom
          BandwidthPackageId:
            Fn::Select:
              - Fn::Calculate:
                  - '{0}//{2}+{1}'
                  - 0
                  - - Ref: EipIndexOffset
                    - Ref: ALIYUN::Index
                    - Ref: MaxNumberOfEipPerBandwidthPackage
              - Ref: CommonBandwidthPackage-ChinaTelecom-List
  • 子資源棧B
    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      Count:
        Type: Number
    Resources:
      CommonBandwidthPackage-ChinaTelecom:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Count:
          Ref: Count
        Properties: null
      CommonBandwidthPackage-ChinaUnicom:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Count:
          Ref: Count
        Properties: null
      CommonBandwidthPackage-ChinaMobile:
        Type: ALIYUN::VPC::CommonBandwidthPackage
        Count:
          Ref: Count
        Properties: null
    Outputs:
      CommonBandwidthPackage-ChinaTelecom-List:
        Value:
          Ref: CommonBandwidthPackage-ChinaTelecom
      CommonBandwidthPackage-ChinaUnicom-List:
        Value:
          Ref: CommonBandwidthPackage-ChinaUnicom
      CommonBandwidthPackage-ChinaMobile-List:
        Value:
          Ref: CommonBandwidthPackage-ChinaMobile
  • 父資源棧
    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      NumberOfEcs:
        Type: Number
        MinValue: 0
      MaxNumberOfEcsPerStack:
        Type: Number
        MinValue: 1
        Default: 20
      MaxNumberOfEipPerBandwidthPackage:
        Type: Number
        MinValue: 1
        Default: 100
    Resources:
      B:
        Type: ALIYUN::ROS::Stack
        Properties:
          TemplateURL: oss://templates/resourses-b
          Parameters:
            Count:
              Fn::Calculate:
                - ({0}+{1}-1)//{1}
                - 0
                - - Ref: NumberOfEcs
                  - Ref: MaxNumberOfEipPerBandwidthPackage
      A:
        Type: ALIYUN::ROS::Stack
        Count:
          Fn::Calculate:
            - ({0}+{1}-1)//{1}
            - 0
            - - Ref: NumberOfEcs
              - Ref: MaxNumberOfEcsPerStack
        Properties:
          TemplateURL: oss://templates/resourses-a
          Parameters:
            NumberOfEcs:
              Fn::Min:
                - Ref: MaxNumberOfEcsPerStack
                - Fn::Calculate:
                    - '{0}-{1}*{2}'
                    - 0
                    - - Ref: NumberOfEcs
                      - Ref: ALIYUN::Index
                      - Ref: MaxNumberOfEcsPerStack
            MaxNumberOfEipPerBandwidthPackage:
              Ref: MaxNumberOfEipPerBandwidthPackage
            EipIndexOffset:
              Fn::Calculate:
                - '{0}*{1}'
                - 0
                - - Ref: MaxNumberOfEcsPerStack
                  - Ref: ALIYUN::Index
            CommonBandwidthPackage-ChinaTelecom-List:
              Fn::GetAtt:
                - B
                - CommonBandwidthPackage-ChinaTelecom-List
            CommonBandwidthPackage-ChinaUnicom-List:
              Fn::GetAtt:
                - B
                - CommonBandwidthPackage-ChinaUnicom-List
            CommonBandwidthPackage-ChinaMobile-List:
              Fn::GetAtt:
                - B
                - CommonBandwidthPackage-ChinaMobile-List