ROS引用Count參數(shù)后,如何使用ALIYUN::Index?
更新時(shí)間:
本文以使用Count批量創(chuàng)建EIP和SLB實(shí)例為例向您介紹如何在引用Count后正確使用ALIYUN::Index。
當(dāng)您在模板中為資源指定Count后,ROS會(huì)對(duì)模板進(jìn)行預(yù)處理,把對(duì)應(yīng)資源展開(kāi)為多個(gè)資源,操作資源棧時(shí)使用處理后的模板。更多信息,請(qǐng)參見(jiàn)資源(Resources)。
模板中定義的資源名為Eip,Count值為2,在ROS處理后的模板中不再有Eip資源,只有Eip[0]和Eip[1]兩個(gè)資源。同理處理后的模板中只包含Slb[0]和Slb[1]資源、EipBind[0]和EipBind[1]資源,而在EipBind[0]中的ALIYUN::Index會(huì)自動(dòng)轉(zhuǎn)換為0,其中Fn::GetAtt:Slb,引用的資源為列表[Slb[0],Slb[1]],會(huì)轉(zhuǎn)換成如下內(nèi)容。InstanceId使用Fn::Select就能引用到Slb[0],同理AllocationId能引用到Eip[0],自此就把Slb[0]和Eip[0]綁定到一起。
InstanceId:
Fn::Select:
- 0
- [Slb[0],Slb[1]]
完整示例如下:
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
Count:
Type: Number
Default: 2
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 10.0.0.0/8
VpcName: test-resource-count
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
CidrBlock: 10.0.10.0/24
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
Eip:
Type: ALIYUN::VPC::EIP
Count:
Ref: Count
Properties:
Bandwidth: 5
Slb:
Type: ALIYUN::SLB::LoadBalancer
Count:
Ref: Count
Properties:
LoadBalancerSpec: slb.s1.small
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName: test
MasterZoneId:
Ref: ZoneId
AddressType: intranet
EipBind:
Type: ALIYUN::VPC::EIPAssociation
Count:
Ref: Count
Properties:
InstanceId:
Fn::Select:
- Ref: ALIYUN::Index
- Fn::GetAtt:
- Slb
- LoadBalancerId
AllocationId:
Fn::Select:
- Ref: ALIYUN::Index
- Ref: Eip
Outputs:
LoadBalancerId:
Value:
Fn::GetAtt:
- Slb
- LoadBalancerId
EipAddresses:
Value:
Fn::GetAtt:
- Eip
- EipAddress
文檔內(nèi)容是否對(duì)您有幫助?