全部產品
Search
文件中心

Resource Orchestration Service:ALIYUN::ECS::Route

更新時間:Jan 15, 2026

ALIYUN::ECS::Route類型用於建立自訂路由條目。

文法

{
  "Type": "ALIYUN::ECS::Route",
  "Properties": {
    "DestinationCidrBlock": String,
    "RouteTableId": String,
    "NextHopId": String,
    "NextHopType": String,
    "NextHopList": List
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

DestinationCidrBlock

String

自訂路由條目的目標網段。

支援 IPv4、IPv6、首碼列表的目標網段和首碼列表的執行個體 ID。需滿足以下要求:

  • 目標網段不能指向 100.64.0.0/10 或被 100.64.0.0/10 包含。

  • 同一張路由表內的不同路由條目的目標網段不能相同。

RouteTableId

String

要添加自訂路由條目的路由表 ID。

NextHopId

String

自訂路由條目的下一跳執行個體ID。

若選擇NextHopTypeEcr,您可以通過 DescribeExpressConnectRouterAssociation介面擷取 AssociationId 作為下一跳 ID。

NextHopType

String

自訂路由條目的下一跳類型。

取值:

  • Instance(預設值):ECS 執行個體。

  • HaVip:高可用虛擬 IP。

  • RouterInterface:路由器介面。

  • NetworkInterface:彈性網卡。

  • VpnGateway:VPN 閘道。

  • IPv6Gateway:IPv6 網關。

  • NatGateway:NAT Gateway。

  • Attachment:轉寄路由器。

  • VpcPeer:VPC 對等串連。

  • Ipv4Gateway:IPv4 網關。

  • GatewayEndpoint:網關終端節點。

  • Ecr:專線網關。

  • GatewayLoadBalancerEndpoint:網關型負載平衡終端節點。

NextHopList

List

自訂路由條目的下一跳的列表。

如果指定NextHopList,則該路由條目為ECMP路由條目。子級條數 <= 16。

更多資訊,請參見NextHopList 屬性

NextHopList 文法

"NextHopList": [
  {
    "NextHopId": String,
    "NextHopType": String
  }
]

NextHopList 屬性

屬性名稱

類型

必須

允許更新

描述

約束

NextHopId

String

ECMP路由條目的下一跳執行個體的ID。

NextHopType

String

ECMP路由條目的下一跳的類型。

取值:RouterInterface,表示路由器介面。

傳回值

Fn::GetAtt

RouteEntryId:自訂路由條目ID。

樣本

情境 1 :建立自訂路由條目

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSRoute:
    Type: ALIYUN::ECS::Route
    Properties:
      RouteTableId: vtb-25oud****
      DestinationCidrBlock: 172.16.XX.XX/24
      NextHopId: i-25xzy****
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Resources": {
    "ECSRoute": {
      "Type": "ALIYUN::ECS::Route",
      "Properties": {
        "RouteTableId": "vtb-25oud****",
        "DestinationCidrBlock": "172.16.XX.XX/24",
        "NextHopId": "i-25xzy****"
      }
    }
  }
}

情境 2 :建立VPC對等連線路由

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  DestinationCidrBlock:
    Required: true
    Type: String
    Description:
      en: The RouteEntry's target network segment.
    Label:
      zh-cn: 自訂路由條目的目標網段
      en: DestinationCidrBlock
  RouteTableId:
    Required: true
    Type: String
    Description:
      en: RouteTableId of created route entry.
    Label:
      zh-cn: 路由表ID
      en: RouteTableId
  NextHopType:
    Default: Instance
    Required: false
    Type: String
    Description:
      en: The next hop type. Now support 'Instance|HaVip|RouterInterface|NetworkInterface|VpnGateway|IPv6Gateway|NatGateway|Attachment'. The default value is Instance.When the NextHopList is specified, the value will be ignored.
    Label:
      zh-cn: 自訂路由條目的下一跳類型
      en: NextHopType
  NextHopId:
    Default: Null
    Required: false
    Type: String
    Description:
      en: The route entry's next hop. When the NextHopList is specified, the value will be ignored.
    Label:
      zh-cn: 自訂路由條目的下一跳執行個體ID
      en: NextHopId
  NextHopList:
    AssociationPropertyMetadata:
      Parameters:
        NextHopId:
          Required: true
          Type: String
          Description:
            en: Route entry next hop Instance id or Tunnel id.
          Label:
            zh-cn: ECMP路由條目的下一跳執行個體的ID
            en: NextHopId
        NextHopType:
          Default: RouterInterface
          Required: false
          Type: String
          Description:
            en: Route entry next hop type. Now support 'RouterInterface'.
          Label:
            zh-cn: ECMP路由條目的下一跳的類型
            en: NextHopType
    Description:
      en: The route entry's next hop list. If router is virtual border router, the value will be ignore. The list should contain 2-4 next hop. NextHopId of each next hop must be RouterInterface that VRouter forwards to VBR.
    Default: Null
    Required: false
    Label:
      zh-cn: 自訂路由條目的下一跳的列表
      en: NextHopList
    AssociationProperty: List[Parameters]
    Type: Json
Resources:
  RouteEntry:
    Type: ALIYUN::ECS::Route
    Properties:
      DestinationCidrBlock:
        Ref: DestinationCidrBlock
      RouteTableId:
        Ref: RouteTableId
      NextHopType:
        Ref: NextHopType
      NextHopId:
        Ref: NextHopId
      NextHopList:
        Ref: NextHopList
Outputs:
  RouteEntryId:
    Description: The ID of the route entry.
    Value:
      Fn::GetAtt:
        - RouteEntry
        - RouteEntryId
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "DestinationCidrBlock": {
      "Required": true,
      "Type": "String",
      "Description": {
        "en": "The RouteEntry's target network segment."
      },
      "Label": {
        "zh-cn": "自訂路由條目的目標網段",
        "en": "DestinationCidrBlock"
      }
    },
    "RouteTableId": {
      "Required": true,
      "Type": "String",
      "Description": {
        "en": "RouteTableId of created route entry."
      },
      "Label": {
        "zh-cn": "路由表ID",
        "en": "RouteTableId"
      }
    },
    "NextHopType": {
      "Default": "Instance",
      "Required": false,
      "Type": "String",
      "Description": {
        "en": "The next hop type. Now support 'Instance|HaVip|RouterInterface|NetworkInterface|VpnGateway|IPv6Gateway|NatGateway|Attachment'. The default value is Instance.When the NextHopList is specified, the value will be ignored."
      },
      "Label": {
        "zh-cn": "自訂路由條目的下一跳類型",
        "en": "NextHopType"
      }
    },
    "NextHopId": {
      "Default": null,
      "Required": false,
      "Type": "String",
      "Description": {
        "en": "The route entry's next hop. When the NextHopList is specified, the value will be ignored."
      },
      "Label": {
        "zh-cn": "自訂路由條目的下一跳執行個體ID",
        "en": "NextHopId"
      }
    },
    "NextHopList": {
      "AssociationPropertyMetadata": {
        "Parameters": {
          "NextHopId": {
            "Required": true,
            "Type": "String",
            "Description": {
              "en": "Route entry next hop Instance id or Tunnel id."
            },
            "Label": {
              "zh-cn": "ECMP路由條目的下一跳執行個體的ID",
              "en": "NextHopId"
            }
          },
          "NextHopType": {
            "Default": "RouterInterface",
            "Required": false,
            "Type": "String",
            "Description": {
              "en": "Route entry next hop type. Now support 'RouterInterface'."
            },
            "Label": {
              "zh-cn": "ECMP路由條目的下一跳的類型",
              "en": "NextHopType"
            }
          }
        }
      },
      "Description": {
        "en": "The route entry's next hop list. If router is virtual border router, the value will be ignore. The list should contain 2-4 next hop. NextHopId of each next hop must be RouterInterface that VRouter forwards to VBR."
      },
      "Default": null,
      "Required": false,
      "Label": {
        "zh-cn": "自訂路由條目的下一跳的列表",
        "en": "NextHopList"
      },
      "AssociationProperty": "List[Parameters]",
      "Type": "Json"
    }
  },
  "Resources": {
    "RouteEntry": {
      "Type": "ALIYUN::ECS::Route",
      "Properties": {
        "DestinationCidrBlock": {
          "Ref": "DestinationCidrBlock"
        },
        "RouteTableId": {
          "Ref": "RouteTableId"
        },
        "NextHopType": {
          "Ref": "NextHopType"
        },
        "NextHopId": {
          "Ref": "NextHopId"
        },
        "NextHopList": {
          "Ref": "NextHopList"
        }
      }
    }
  },
  "Outputs": {
    "RouteEntryId": {
      "Description": "The ID of the route entry.",
      "Value": {
        "Fn::GetAtt": [
          "RouteEntry",
          "RouteEntryId"
        ]
      }
    }
  }
}

情境 3 :建立WordPress叢集

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 建立WordPress叢集,含VPC、ECS、SLB、RDS資源,自動設定網路與負載平衡,支援自訂執行個體規格、數量及資料庫配置。
  en: Create a WordPress cluster, including VPC, ECS, SLB, and RDS resources, automatically configure network and load balancing, and support customized instance specifications, quantity, and database configuration.
Parameters:
  VpcCidrBlock:
    Type: String
    Label:
      en: VPC Cidrblock
      zh-cn: VPC網段
    Description:
      en: 'The IP address range of the VPC in the CIDR block form. You can use the
        following IP address ranges and their subnets: 10.0.0.0/8 172.16.0.0/12  192.168.0.0/16'
      zh-cn: 專用網路的網段,可選值:10.0.0.0/8,172.16.0.0/12,192.168.0.0/16。
    Default: 10.0.0.0/8
    AllowedValues:
    - 192.168.0.0/16
    - 172.16.0.0/12
    - 10.0.0.0/8
  ZoneId:
    Type: String
    Label:
      en: Zone ID
      zh-cn: 可用性區域ID
    Description:
      en: The available zone ID, you should confirm the zone support ECS、VPC、VSwitch
        or not.
      zh-cn: 可用性區域ID,需確認所選可用性區域下是否支援ECS、VPC、VSwitch等資源。
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
  VSwitchCidrBlock:
    Type: String
    Label:
      en: VSwitch CidrBlock
      zh-cn: VSwitch網段
    Description:
      en: VSwitch subnet which is within VPC.
      zh-cn: 交換器網段,必須為VPC子網段。
    Default: 10.0.10.0/24
  InstanceType:
    Type: String
    Label:
      en: Instance Type
      zh-cn: 執行個體規格
    Description:
      en: <font color='blue'><b>1.Before selecting the model please confirm that the
        current available zone under the model is in stock, some models need to be
        reported in advance</b></font><br><font color='blue'><b>2.List of optional
        models</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU 4GiB Intranet
        bandwidth1Gbps In-grid sending and receiving packages30MillionPPS</font>]<br></b>[ecs.c5.xlarge
        <font color='green'>4vCPU 8GiB Intranet bandwidth1.5Gbps In-grid sending and
        receiving packages50MillionPPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU
        16GiB Intranet bandwidth2.5Gbps In-grid sending and receiving packages80MillionPPS</font>]
      zh-cn: <font color='blue'><b>1.選擇機型前請先確認當前可用性區域下該機型是否有貨,部分機型需要提前報備</b></font><br><font
        color='blue'><b>2.可選機型列表</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU
        4GiB 內網頻寬1Gbps 內網收發包30萬PPS</font>]<br></b>[ecs.c5.xlarge <font color='green'>4vCPU
        8GiB 內網頻寬1.5Gbps 內網收發包50萬PPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU
        16GiB 內網頻寬2.5Gbps 內網收發包80萬PPS</font>]
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ZoneId
  ImageId:
    Type: String
    Label:
      en: Image ID
      zh-cn: 鏡像ID
    Description:
      en: 'Instance Image ID. see detail: <b><a href=''https://www.alibabacloud.com/help/doc-detail/112977.html''
        target=''_blank''><font color=''blue''>Find the mirror</font></a></b>'
      zh-cn: 執行個體鏡像,詳見:<b><a href='https://www.alibabacloud.com/help/document_detail/112977.html'
        target='_blank'><font color='blue'>尋找鏡像</font></a></b>
    AssociationProperty: ALIYUN::ECS::Image::ImageId
    AssociationPropertyMetadata:
      InstanceType: ${InstanceType}
      SupportedImageOwnerAlias:
        - system
        - self
        - others
    Default: centos_7_04_64_20G_alibase_201701015.vhd
  InstancePassword:
    Type: String
    Label:
      en: Instance Password
      zh-cn: 執行個體密碼
    Description:
      en: The 8-30 long login password of instance, consists of the uppercase, lowercase
        letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
      zh-cn: 長度8-30,必須包含大寫字母、小寫字母、數字、特殊符號三個;<br>特殊字元包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
    ConstraintDescription:
      en: 'Length 8-30, must contain upper case letters, lower case letters, Numbers,
        special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/'
      zh-cn: 長度8-30,必須包含大寫字母、小寫字母、數字、特殊符號三種;特殊字元包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/
    AllowedPattern: '[0-9A-Za-z\_\-&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
    MinLength: '8'
    MaxLength: '30'
    NoEcho: true
  NumberOfNode:
    Type: Number
    Label:
      en: Instances Amount
      zh-cn: 伺服器數量
    Description:
      en: Number of WordPress instances.
      zh-cn: WordPress伺服器數量
    Default: 3
    MinValue: 1
    MaxValue: 100
  SystemDiskCategory:
    Type: String
    Label:
      en: System Disk Type
      zh-cn: 系統硬碟類型
    Description:
      en: '<font color=''blue''><b>Optional values:</b></font><br>[cloud_efficiency: <font color=''green''>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color=''green''>SSD Cloud Disk</font>]<br>[cloud_essd: <font color=''green''>ESSD Cloud Disk</font>]<br>[cloud: <font color=''green''>Cloud Disk</font>]<br>[ephemeral_ssd: <font color=''green''>Local SSD Cloud Disk</font>]'
      zh-cn: '<font color=''blue''><b>可選值:</b></font><br>[cloud_efficiency: <font color=''green''>高效雲端硬碟</font>]<br>[cloud_ssd: <font color=''green''>SSD雲端硬碟</font>]<br>[cloud_essd: <font color=''green''>ESSD雲端硬碟</font>]<br>[cloud: <font color=''green''>普通雲端硬碟</font>]<br>[ephemeral_ssd: <font color=''green''>本地SSD盤</font>]'
    AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
    AssociationPropertyMetadata:
      LocaleKey: DiskCategory
      InstanceType: ${InstanceType}
      ZoneId: ZoneId
  LoadBalancerSpec:
    Type: String
    Label:
      en: Specifications
      zh-cn: 規格
    Description:
      en: Instance specifications,</br>see detail:</b><a href='https://www.alibabacloud.com/help/doc-detail/85939.html'
        target='_blank'><b><font color='blue'>Performance Support Type</b></font></a>
      zh-cn: 執行個體規格,</br>詳見:</b><a href='https://www.alibabacloud.com/help/document_detail/85939.html'
        target='_blank'><b><font color='blue'>效能保障型</b></font></a>
    Default: slb.s1.small
  Category:
    AssociationPropertyMetadata:
      LocaleKey: RDSCategory
    Default: Null
    Required: false
    AllowedValues:
      - Basic
      - HighAvailability
      - cluster
    Label:
      zh-cn: 執行個體系列
      en: Category
    Type: String
  DBInstanceClass:
    Type: String
    Label:
      en: Instance Class
      zh-cn: 執行個體類型
    Description:
      en: Database instance type. Refer the RDS database instance type.<a href='https://www.alibabacloud.com/help/doc-detail/26312.htm'
        target='_blank'>View RDS resources type</a>
      zh-cn: '資料庫執行個體類型, <br>詳見: <a href=''https://www.alibabacloud.com/help/document_detail/26312.html''
        target=''_blank''><b><font color=''blue''>執行個體規格表</font></b></a>.'
    AssociationProperty: ALIYUN::RDS::Instance::InstanceType
    AssociationPropertyMetadata:
      Engine: MySQL
      Category: ${Category}
      EngineVersion: ${EngineVersion}
      ZoneId: ${ZoneId}
    Default: rds.mysql.s1.small
  EngineVersion:
    Type: String
    Label:
      en: Engine Version
      zh-cn: 資料庫引擎版本
    Description:
      en: RDS MySQL Engine Version
      zh-cn: RDS MySQL 資料庫版本號碼
    AssociationProperty: ALIYUN::RDS::Engine::EngineVersion
    AssociationPropertyMetadata:
      Engine: MySQL
    Default: '8.0'
  DBInstanceStorage:
    Type: Number
    Label:
      en: Storage Size
      zh-cn: 儲存空間
    Description:
      en: 'Incrementing in every 5G, unit: GB'
      zh-cn: 資料庫儲存空間,每5GB進行遞增。
    ConstraintDescription:
      en: 'Incrementing in every 5G, unit: GB'
      zh-cn: 每5GB進行遞增。
    Default: 50
    MinValue: 5
    MaxValue: 2000
  DBName:
    Type: String
    Label:
      en: DB Name
      zh-cn: 資料庫名
    Description:
      en: Name of WordPress database
      zh-cn: WordPress資料庫名
    ConstraintDescription:
      en: Consist of 2 to 64 characters of lowercase letters, underline. Must begin
        with a letter and be end with an alphanumeric character
      zh-cn: 由 2 到 64 個小寫字母組成,底線。必須以字母開頭,以字母數字字元結尾
    Default: wordpress
    MinLength: 2
    MaxLength: 64
  DBUser:
    Type: String
    Label:
      en: DB Username
      zh-cn: 資料庫帳號
    Description:
      en: Username of WordPress database
      zh-cn: WordPress資料庫帳號
    ConstraintDescription:
      en: Consist of 2 to 64 characters of lowercase letters, underline. Must begin
        with a letter and be end with an alphanumeric character
      zh-cn: 由 2 到 64 個小寫字母組成,底線。必須以字母開頭,以字母數字字元結尾
    Default: wpuser
    MinLength: 2
    MaxLength: 16
  DBPassword:
    Type: String
    Label:
      en: DB Password
      zh-cn: 資料庫密碼
    Description:
      en: The password of WordPress database consists of 8 to 32 characters of alphanumeric
        characters, hyphen and underline
      zh-cn: WordPress資料庫密碼,由8~32位大小寫字母、數字、底線、連字號組成。
    ConstraintDescription:
      en: Consist of 8 to 32 characters of alphanumeric characters, hyphen and underline
      zh-cn: 由 8 到 32 個字母數字字元、連字號和底線組成
    MinLength: 8
    MaxLength: 32
    NoEcho: true
Resources:
  LoadBalancer:
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      LoadBalancerName: wordpress_cluster_slb
      LoadBalancerSpec:
        Ref: LoadBalancerSpec
  AttachEcs:
    Type: ALIYUN::SLB::BackendServerAttachment
    Properties:
      BackendServers:
      - ServerId:
          Fn::Select:
          - '0'
          - Fn::GetAtt:
            - WebServerGroup
            - InstanceIds
        Weight: 100
      - ServerId:
          Fn::Select:
          - '1'
          - Fn::GetAtt:
            - WebServerGroup
            - InstanceIds
        Weight: 100
      - ServerId:
          Fn::Select:
          - '2'
          - Fn::GetAtt:
            - WebServerGroup
            - InstanceIds
        Weight: 100
      LoadBalancerId:
        Ref: LoadBalancer
  CreateListener_80:
    Type: ALIYUN::SLB::Listener
    Properties:
      BackendServerPort: '80'
      Bandwidth: 100
      HealthCheck:
        HealthyThreshold: 3
        HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
        Interval: 2
        Timeout: 5
        UnhealthyThreshold: 3
      ListenerPort: '80'
      LoadBalancerId:
        Ref: LoadBalancer
      Protocol: http
      Scheduler: wrr
  Vpc:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock:
        Ref: VpcCidrBlock
      VpcName: wordpress_cluster
  SecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      VpcId:
        Ref: Vpc
      SecurityGroupEgress:
      - DestCidrIp: 0.0.0.0/0
        IpProtocol: all
        NicType: internet
        PortRange: -1/-1
        Priority: 1
      - DestCidrIp: 0.0.0.0/0
        IpProtocol: all
        NicType: intranet
        PortRange: -1/-1
        Priority: 1
      SecurityGroupIngress:
      - IpProtocol: tcp
        NicType: internet
        PortRange: 80/80
        Priority: 1
        SourceCidrIp: 0.0.0.0/0
      - IpProtocol: all
        NicType: intranet
        PortRange: -1/-1
        Priority: 1
        SourceCidrIp: 0.0.0.0/0
      SecurityGroupName: wordpress_cluster_sg
  VSwitch:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      ZoneId:
        Ref: ZoneId
      VpcId:
        Ref: Vpc
      CidrBlock:
        Ref: VSwitchCidrBlock
  ECSSnatGateWay:
    Type: ALIYUN::ECS::Instance
    Properties:
      VpcId:
        Fn::GetAtt:
        - Vpc
        - VpcId
      VSwitchId:
        Ref: VSwitch
      SecurityGroupId:
        Fn::GetAtt:
        - SecurityGroup
        - SecurityGroupId
      ImageId:
        Ref: ImageId
      InstanceType:
        Ref: InstanceType
      InternetMaxBandwidthOut: 80
      Password:
        Ref: InstancePassword
      Tags:
      - Key: ECS_SNAT_GATEWAY
        Value: ecs_snat_gateway
      UserData:
        Fn::Replace:
        - ros-notify:
            Fn::GetAtt:
            - ECSSnatGateWayConditionHandle
            - CurlCli
        - Fn::Join:
          - ''
          - - '#!/bin/sh'
            - '

              '
            - PostRouting=
            - Ref: VSwitchCidrBlock
            - '

              '
            - SourceRouting=`ifconfig eth0|grep inet|awk '{print $2}'|tr -d 'addr:'`
            - '

              '
            - "echo 'net.ipv4.ip_forward=1'>> /etc/sysctl.conf \n"
            - "sysctl -p \n"
            - "iptables -t nat -I POSTROUTING -s $PostRouting -j SNAT --to-source\
              \ $SourceRouting \n"
            - 'apt-get update

              '
            - 'apt-get install -y curl

              '
            - 'ros-notify -d ''{"data" : " docker swarm created"}''

              '
  ECSSnatGateWayConditionHandle:
    Type: ALIYUN::ROS::WaitConditionHandle
    Properties: {}
  ECSSnatGateWayGroupWaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    Properties:
      Count: 1
      Handle:
        Ref: ECSSnatGateWayConditionHandle
      Timeout: 600
    DependsOn: ECSSnatGateWay
  Database:
    Type: ALIYUN::RDS::DBInstance
    Properties:
      VPCId:
        Ref: Vpc
      VSwitchId:
        Ref: VSwitch
      DBInstanceClass:
        Ref: DBInstanceClass
      DBInstanceDescription: DataBase
      DBInstanceStorage:
        Ref: DBInstanceStorage
      DBMappings:
      - CharacterSetName: utf8
        DBName:
          Ref: DBName
      Engine: MySQL
      Category:
        Ref: Category
      EngineVersion:
        Ref: EngineVersion
      MasterUserPassword:
        Ref: DBPassword
      MasterUsername:
        Ref: DBUser
      SecurityIPList: 0.0.0.0/0
    DependsOn: ECSSnatGateWayGroupWaitCondition
  VRoute:
    Type: ALIYUN::ECS::Route
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      NextHopId:
        Fn::GetAtt:
        - ECSSnatGateWay
        - InstanceId
      RouteId:
        Fn::GetAtt:
        - Vpc
        - VRouterId
      RouteTableId:
        Fn::GetAtt:
        - Vpc
        - RouteTableId
  WebServerGroup:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      VpcId:
        Ref: Vpc
      VSwitchId:
        Ref: VSwitch
      SecurityGroupId:
        Ref: SecurityGroup
      ImageId:
        Ref: ImageId
      AllocatePublicIP: true
      InstanceType:
        Ref: InstanceType
      IoOptimized: optimized
      MaxAmount:
        Ref: NumberOfNode
      Password:
        Ref: InstancePassword
      SystemDiskCategory:
        Ref: SystemDiskCategory
      UserData:
        Fn::Replace:
        - ros-notify:
            Fn::GetAtt:
            - WebServerGroupConditionHandle
            - CurlCli
        - Fn::Join:
          - ''
          - - '#!/bin/sh'
            - '

              '
            - DatabaseUser=
            - Ref: DBUser
            - '

              '
            - DatabasePwd=
            - Ref: DBPassword
            - '

              '
            - DatabaseName=
            - Ref: DBName
            - '

              '
            - DatabaseHost=
            - Fn::GetAtt:
              - Database
              - InnerConnectionString
            - '

              '
            - 'WebRootPath=''/var/www/html''

              '
            - 'ApacheIndex=''Options Indexes FollowSymLinks''

              '
            - 'ApacheIndexReplace=''Options FollowSymLinks''

              '
            - 'mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

              '
            - 'wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

              '
            - 'yum makecache

              '
            - "yum install -y unzip zip \n"
            - "yum install -y curl httpd mysql-server php56 php56-php-mysql \n"
            - "rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm \n"
            - "rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm \n"
            - "yum install -y php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64\
              \ php56w-gd.x86_64 php56w-imap.x86_64 php56w-ldap.x86_64 php56w-mysql.x86_64\
              \ php56w-pdo.x86_64 php56w-odbc.x86_64 php56w-process.x86_64 php56w-xml.x86_64\
              \ php56w-xmlrpc.x86_64 \n"
            - 'chkconfig httpd on

              '
            - '#wget http://wordpress.org/latest.tar.gz

              '
            - '#tar -xzvf latest.tar.gz

              '
            - "wget https://ros-template-resources.oss-cn-beijing.aliyuncs.com/WordPress/WordPress.zip\
              \ \n"
            - "unzip WordPress.zip \n"
            - "mv WordPress-master wordpress \n"
            - 'sed -i "s/database_name_here/$DatabaseName/" wordpress/wp-config-sample.php

              '
            - 'sed -i "s/username_here/$DatabaseUser/" wordpress/wp-config-sample.php

              '
            - 'sed -i "s/password_here/${DatabasePwd:-$DatabasePwdDef}/" wordpress/wp-config-sample.php

              '
            - 'sed -i "s/localhost/$DatabaseHost/" wordpress/wp-config-sample.php

              '
            - 'mv wordpress/wp-config-sample.php wordpress/wp-config.php

              '
            - 'cp -a wordpress/* $WebRootPath

              '
            - 'rm -rf wordpress*

              '
            - 'service httpd stop

              '
            - 'usermod -d $WebRootPath apache &>/dev/null

              '
            - 'chown apache:apache -R $WebRootPath

              '
            - 'sed -i "s/$ApacheIndex/$ApacheIndexReplace/" /etc/httpd/conf/httpd.conf

              '
            - 'service httpd start

              '
            - 'ros-notify -d ''{"data" : "Install Wordpress"}''

              '
    DependsOn: Database
  WebServerGroupConditionHandle:
    Type: ALIYUN::ROS::WaitConditionHandle
    Properties: {}
  WebServerGroupWaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    Properties:
      Count:
        Ref: NumberOfNode
      Handle:
        Ref: WebServerGroupConditionHandle
      Timeout: 900
    DependsOn: WebServerGroup
Outputs:
  JumpHostIp:
    Description:
      en: The jump host IP.
      zh-cn: 跳轉主機IP。
    Value:
      Fn::GetAtt:
      - ECSSnatGateWay
      - PublicIp
  WordPressUrl:
    Description:
      en: WordPress URL.
      zh-cn: WordPress 網址。
    Value:
      Fn::Join:
      - ''
      - - http://
        - Fn::GetAtt:
          - LoadBalancer
          - IpAddress
        - :80
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
    - Parameters:
      - VpcCidrBlock
      - ZoneId
      - VSwitchCidrBlock
      Label:
        default:
          en: VPC
          zh-cn: 專用網路
    - Parameters:
      - InstanceType
      - ImageId
      - SystemDiskCategory
      - NumberOfNode
      - InstancePassword
      Label:
        default:
          en: ECS
          zh-cn: 雲端服務器
    - Parameters:
      - LoadBalancerSpec
      Label:
        default:
          en: SLB
          zh-cn: 負載平衡
    - Parameters:
      - Category
      - EngineVersion
      - DBInstanceClass
      - DBInstanceStorage
      - DBName
      - DBUser
      - DBPassword
      Label:
        default:
          en: RDS
          zh-cn: 資料庫
    TemplateTags:
    - acs:example:網路:建立WordPress叢集並配置VPC的SNAT功能訪問Internet
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "建立WordPress叢集,含VPC、ECS、SLB、RDS資源,自動設定網路與負載平衡,支援自訂執行個體規格、數量及資料庫配置。",
    "en": "Create a WordPress cluster, including VPC, ECS, SLB, and RDS resources, automatically configure network and load balancing, and support customized instance specifications, quantity, and database configuration."
  },
  "Parameters": {
    "VpcCidrBlock": {
      "Type": "String",
      "Label": {
        "en": "VPC Cidrblock",
        "zh-cn": "VPC網段"
      },
      "Description": {
        "en": "The IP address range of the VPC in the CIDR block form. You can use the following IP address ranges and their subnets: 10.0.0.0/8 172.16.0.0/12  192.168.0.0/16",
        "zh-cn": "專用網路的網段,可選值:10.0.0.0/8,172.16.0.0/12,192.168.0.0/16。"
      },
      "Default": "10.0.0.0/8",
      "AllowedValues": [
        "192.168.0.0/16",
        "172.16.0.0/12",
        "10.0.0.0/8"
      ]
    },
    "ZoneId": {
      "Type": "String",
      "Label": {
        "en": "Zone ID",
        "zh-cn": "可用性區域ID"
      },
      "Description": {
        "en": "The available zone ID, you should confirm the zone support ECS、VPC、VSwitch or not.",
        "zh-cn": "可用性區域ID,需確認所選可用性區域下是否支援ECS、VPC、VSwitch等資源。"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId"
    },
    "VSwitchCidrBlock": {
      "Type": "String",
      "Label": {
        "en": "VSwitch CidrBlock",
        "zh-cn": "VSwitch網段"
      },
      "Description": {
        "en": "VSwitch subnet which is within VPC.",
        "zh-cn": "交換器網段,必須為VPC子網段。"
      },
      "Default": "10.0.10.0/24"
    },
    "InstanceType": {
      "Type": "String",
      "Label": {
        "en": "Instance Type",
        "zh-cn": "執行個體規格"
      },
      "Description": {
        "en": "<font color='blue'><b>1.Before selecting the model please confirm that the current available zone under the model is in stock, some models need to be reported in advance</b></font><br><font color='blue'><b>2.List of optional models</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU 4GiB Intranet bandwidth1Gbps In-grid sending and receiving packages30MillionPPS</font>]<br></b>[ecs.c5.xlarge <font color='green'>4vCPU 8GiB Intranet bandwidth1.5Gbps In-grid sending and receiving packages50MillionPPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU 16GiB Intranet bandwidth2.5Gbps In-grid sending and receiving packages80MillionPPS</font>]",
        "zh-cn": "<font color='blue'><b>1.選擇機型前請先確認當前可用性區域下該機型是否有貨,部分機型需要提前報備</b></font><br><font color='blue'><b>2.可選機型列表</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU 4GiB 內網頻寬1Gbps 內網收發包30萬PPS</font>]<br></b>[ecs.c5.xlarge <font color='green'>4vCPU 8GiB 內網頻寬1.5Gbps 內網收發包50萬PPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU 16GiB 內網頻寬2.5Gbps 內網收發包80萬PPS</font>]"
      },
      "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "ZoneId": "ZoneId"
      }
    },
    "ImageId": {
      "Type": "String",
      "Label": {
        "en": "Image ID",
        "zh-cn": "鏡像ID"
      },
      "Description": {
        "en": "Instance Image ID. see detail: <b><a href='https://www.alibabacloud.com/help/doc-detail/112977.html' target='_blank'><font color='blue'>Find the mirror</font></a></b>",
        "zh-cn": "執行個體鏡像,詳見:<b><a href='https://www.alibabacloud.com/help/document_detail/112977.html' target='_blank'><font color='blue'>尋找鏡像</font></a></b>"
      },
      "AssociationProperty": "ALIYUN::ECS::Image::ImageId",
      "AssociationPropertyMetadata": {
        "InstanceType": "${InstanceType}",
        "SupportedImageOwnerAlias": [
          "system",
          "self",
          "others"
        ]
      },
      "Default": "centos_7_04_64_20G_alibase_201701015.vhd"
    },
    "InstancePassword": {
      "Type": "String",
      "Label": {
        "en": "Instance Password",
        "zh-cn": "執行個體密碼"
      },
      "Description": {
        "en": "The 8-30 long login password of instance, consists of the uppercase, lowercase letter and number. <br> special characters include()`~!@#$%^&*_-+=|{}[]:;'<>,.?/",
        "zh-cn": "長度8-30,必須包含大寫字母、小寫字母、數字、特殊符號三個;<br>特殊字元包括:()`~!@#$%^&*_-+=|{}[]:;'<>,.?/"
      },
      "ConstraintDescription": {
        "en": "Length 8-30, must contain upper case letters, lower case letters, Numbers, special symbols three; special characters include: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/",
        "zh-cn": "長度8-30,必須包含大寫字母、小寫字母、數字、特殊符號三種;特殊字元包括:()`~!@#$%^&*_-+=|{}[]:;' <>,.?/"
      },
      "AllowedPattern": "[0-9A-Za-z\\_\\-&:;'<>,=%`~!@#\\(\\)\\$\\^\\*\\+\\|\\{\\}\\[\\]\\.\\?\\/]+$",
      "MinLength": "8",
      "MaxLength": "30",
      "NoEcho": true
    },
    "NumberOfNode": {
      "Type": "Number",
      "Label": {
        "en": "Instances Amount",
        "zh-cn": "伺服器數量"
      },
      "Description": {
        "en": "Number of WordPress instances.",
        "zh-cn": "WordPress伺服器數量"
      },
      "Default": 3,
      "MinValue": 1,
      "MaxValue": 100
    },
    "SystemDiskCategory": {
      "Type": "String",
      "Label": {
        "en": "System Disk Type",
        "zh-cn": "系統硬碟類型"
      },
      "Description": {
        "en": "<font color='blue'><b>Optional values:</b></font><br>[cloud_efficiency: <font color='green'>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color='green'>SSD Cloud Disk</font>]<br>[cloud_essd: <font color='green'>ESSD Cloud Disk</font>]<br>[cloud: <font color='green'>Cloud Disk</font>]<br>[ephemeral_ssd: <font color='green'>Local SSD Cloud Disk</font>]",
        "zh-cn": "<font color='blue'><b>可選值:</b></font><br>[cloud_efficiency: <font color='green'>高效雲端硬碟</font>]<br>[cloud_ssd: <font color='green'>SSD雲端硬碟</font>]<br>[cloud_essd: <font color='green'>ESSD雲端硬碟</font>]<br>[cloud: <font color='green'>普通雲端硬碟</font>]<br>[ephemeral_ssd: <font color='green'>本地SSD盤</font>]"
      },
      "AssociationProperty": "ALIYUN::ECS::Disk::SystemDiskCategory",
      "AssociationPropertyMetadata": {
        "LocaleKey": "DiskCategory",
        "InstanceType": "${InstanceType}",
        "ZoneId": "ZoneId"
      }
    },
    "LoadBalancerSpec": {
      "Type": "String",
      "Label": {
        "en": "Specifications",
        "zh-cn": "規格"
      },
      "Description": {
        "en": "Instance specifications,</br>see detail:</b><a href='https://www.alibabacloud.com/help/doc-detail/85939.html' target='_blank'><b><font color='blue'>Performance Support Type</b></font></a>",
        "zh-cn": "執行個體規格,</br>詳見:</b><a href='https://www.alibabacloud.com/help/document_detail/85939.html' target='_blank'><b><font color='blue'>效能保障型</b></font></a>"
      },
      "Default": "slb.s1.small"
    },
    "Category": {
      "AssociationPropertyMetadata": {
        "LocaleKey": "RDSCategory"
      },
      "Default": null,
      "Required": false,
      "AllowedValues": [
        "Basic",
        "HighAvailability",
        "cluster"
      ],
      "Label": {
        "zh-cn": "執行個體系列",
        "en": "Category"
      },
      "Type": "String"
    },
    "DBInstanceClass": {
      "Type": "String",
      "Label": {
        "en": "Instance Class",
        "zh-cn": "執行個體類型"
      },
      "Description": {
        "en": "Database instance type. Refer the RDS database instance type.<a href='https://www.alibabacloud.com/help/doc-detail/26312.htm' target='_blank'>View RDS resources type</a>",
        "zh-cn": "資料庫執行個體類型, <br>詳見: <a href='https://www.alibabacloud.com/help/document_detail/26312.html' target='_blank'><b><font color='blue'>執行個體規格表</font></b></a>."
      },
      "AssociationProperty": "ALIYUN::RDS::Instance::InstanceType",
      "AssociationPropertyMetadata": {
        "Engine": "MySQL",
        "Category": "${Category}",
        "EngineVersion": "${EngineVersion}",
        "ZoneId": "${ZoneId}"
      },
      "Default": "rds.mysql.s1.small"
    },
    "EngineVersion": {
      "Type": "String",
      "Label": {
        "en": "Engine Version",
        "zh-cn": "資料庫引擎版本"
      },
      "Description": {
        "en": "RDS MySQL Engine Version",
        "zh-cn": "RDS MySQL 資料庫版本號碼"
      },
      "AssociationProperty": "ALIYUN::RDS::Engine::EngineVersion",
      "AssociationPropertyMetadata": {
        "Engine": "MySQL"
      },
      "Default": "8.0"
    },
    "DBInstanceStorage": {
      "Type": "Number",
      "Label": {
        "en": "Storage Size",
        "zh-cn": "儲存空間"
      },
      "Description": {
        "en": "Incrementing in every 5G, unit: GB",
        "zh-cn": "資料庫儲存空間,每5GB進行遞增。"
      },
      "ConstraintDescription": {
        "en": "Incrementing in every 5G, unit: GB",
        "zh-cn": "每5GB進行遞增。"
      },
      "Default": 50,
      "MinValue": 5,
      "MaxValue": 2000
    },
    "DBName": {
      "Type": "String",
      "Label": {
        "en": "DB Name",
        "zh-cn": "資料庫名"
      },
      "Description": {
        "en": "Name of WordPress database",
        "zh-cn": "WordPress資料庫名"
      },
      "ConstraintDescription": {
        "en": "Consist of 2 to 64 characters of lowercase letters, underline. Must begin with a letter and be end with an alphanumeric character",
        "zh-cn": "由 2 到 64 個小寫字母組成,底線。必須以字母開頭,以字母數字字元結尾"
      },
      "Default": "wordpress",
      "MinLength": 2,
      "MaxLength": 64
    },
    "DBUser": {
      "Type": "String",
      "Label": {
        "en": "DB Username",
        "zh-cn": "資料庫帳號"
      },
      "Description": {
        "en": "Username of WordPress database",
        "zh-cn": "WordPress資料庫帳號"
      },
      "ConstraintDescription": {
        "en": "Consist of 2 to 64 characters of lowercase letters, underline. Must begin with a letter and be end with an alphanumeric character",
        "zh-cn": "由 2 到 64 個小寫字母組成,底線。必須以字母開頭,以字母數字字元結尾"
      },
      "Default": "wpuser",
      "MinLength": 2,
      "MaxLength": 16
    },
    "DBPassword": {
      "Type": "String",
      "Label": {
        "en": "DB Password",
        "zh-cn": "資料庫密碼"
      },
      "Description": {
        "en": "The password of WordPress database consists of 8 to 32 characters of alphanumeric characters, hyphen and underline",
        "zh-cn": "WordPress資料庫密碼,由8~32位大小寫字母、數字、底線、連字號組成。"
      },
      "ConstraintDescription": {
        "en": "Consist of 8 to 32 characters of alphanumeric characters, hyphen and underline",
        "zh-cn": "由 8 到 32 個字母數字字元、連字號和底線組成"
      },
      "MinLength": 8,
      "MaxLength": 32,
      "NoEcho": true
    }
  },
  "Resources": {
    "LoadBalancer": {
      "Type": "ALIYUN::SLB::LoadBalancer",
      "Properties": {
        "LoadBalancerName": "wordpress_cluster_slb",
        "LoadBalancerSpec": {
          "Ref": "LoadBalancerSpec"
        }
      }
    },
    "AttachEcs": {
      "Type": "ALIYUN::SLB::BackendServerAttachment",
      "Properties": {
        "BackendServers": [
          {
            "ServerId": {
              "Fn::Select": [
                "0",
                {
                  "Fn::GetAtt": [
                    "WebServerGroup",
                    "InstanceIds"
                  ]
                }
              ]
            },
            "Weight": 100
          },
          {
            "ServerId": {
              "Fn::Select": [
                "1",
                {
                  "Fn::GetAtt": [
                    "WebServerGroup",
                    "InstanceIds"
                  ]
                }
              ]
            },
            "Weight": 100
          },
          {
            "ServerId": {
              "Fn::Select": [
                "2",
                {
                  "Fn::GetAtt": [
                    "WebServerGroup",
                    "InstanceIds"
                  ]
                }
              ]
            },
            "Weight": 100
          }
        ],
        "LoadBalancerId": {
          "Ref": "LoadBalancer"
        }
      }
    },
    "CreateListener_80": {
      "Type": "ALIYUN::SLB::Listener",
      "Properties": {
        "BackendServerPort": "80",
        "Bandwidth": 100,
        "HealthCheck": {
          "HealthyThreshold": 3,
          "HttpCode": "http_2xx,http_3xx,http_4xx,http_5xx",
          "Interval": 2,
          "Timeout": 5,
          "UnhealthyThreshold": 3
        },
        "ListenerPort": "80",
        "LoadBalancerId": {
          "Ref": "LoadBalancer"
        },
        "Protocol": "http",
        "Scheduler": "wrr"
      }
    },
    "Vpc": {
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "CidrBlock": {
          "Ref": "VpcCidrBlock"
        },
        "VpcName": "wordpress_cluster"
      }
    },
    "SecurityGroup": {
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "SecurityGroupEgress": [
          {
            "DestCidrIp": "0.0.0.0/0",
            "IpProtocol": "all",
            "NicType": "internet",
            "PortRange": "-1/-1",
            "Priority": 1
          },
          {
            "DestCidrIp": "0.0.0.0/0",
            "IpProtocol": "all",
            "NicType": "intranet",
            "PortRange": "-1/-1",
            "Priority": 1
          }
        ],
        "SecurityGroupIngress": [
          {
            "IpProtocol": "tcp",
            "NicType": "internet",
            "PortRange": "80/80",
            "Priority": 1,
            "SourceCidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol": "all",
            "NicType": "intranet",
            "PortRange": "-1/-1",
            "Priority": 1,
            "SourceCidrIp": "0.0.0.0/0"
          }
        ],
        "SecurityGroupName": "wordpress_cluster_sg"
      }
    },
    "VSwitch": {
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "ZoneId": {
          "Ref": "ZoneId"
        },
        "VpcId": {
          "Ref": "Vpc"
        },
        "CidrBlock": {
          "Ref": "VSwitchCidrBlock"
        }
      }
    },
    "ECSSnatGateWay": {
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "VpcId": {
          "Fn::GetAtt": [
            "Vpc",
            "VpcId"
          ]
        },
        "VSwitchId": {
          "Ref": "VSwitch"
        },
        "SecurityGroupId": {
          "Fn::GetAtt": [
            "SecurityGroup",
            "SecurityGroupId"
          ]
        },
        "ImageId": {
          "Ref": "ImageId"
        },
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "InternetMaxBandwidthOut": 80,
        "Password": {
          "Ref": "InstancePassword"
        },
        "Tags": [
          {
            "Key": "ECS_SNAT_GATEWAY",
            "Value": "ecs_snat_gateway"
          }
        ],
        "UserData": {
          "Fn::Replace": [
            {
              "ros-notify": {
                "Fn::GetAtt": [
                  "ECSSnatGateWayConditionHandle",
                  "CurlCli"
                ]
              }
            },
            {
              "Fn::Join": [
                "",
                [
                  "#!/bin/sh",
                  "\n",
                  "PostRouting=",
                  {
                    "Ref": "VSwitchCidrBlock"
                  },
                  "\n",
                  "SourceRouting=`ifconfig eth0|grep inet|awk '{print $2}'|tr -d 'addr:'`",
                  "\n",
                  "echo 'net.ipv4.ip_forward=1'>> /etc/sysctl.conf \n",
                  "sysctl -p \n",
                  "iptables -t nat -I POSTROUTING -s $PostRouting -j SNAT --to-source $SourceRouting \n",
                  "apt-get update\n",
                  "apt-get install -y curl\n",
                  "ros-notify -d '{\"data\" : \" docker swarm created\"}'\n"
                ]
              ]
            }
          ]
        }
      }
    },
    "ECSSnatGateWayConditionHandle": {
      "Type": "ALIYUN::ROS::WaitConditionHandle",
      "Properties": {}
    },
    "ECSSnatGateWayGroupWaitCondition": {
      "Type": "ALIYUN::ROS::WaitCondition",
      "Properties": {
        "Count": 1,
        "Handle": {
          "Ref": "ECSSnatGateWayConditionHandle"
        },
        "Timeout": 600
      },
      "DependsOn": "ECSSnatGateWay"
    },
    "Database": {
      "Type": "ALIYUN::RDS::DBInstance",
      "Properties": {
        "VPCId": {
          "Ref": "Vpc"
        },
        "VSwitchId": {
          "Ref": "VSwitch"
        },
        "DBInstanceClass": {
          "Ref": "DBInstanceClass"
        },
        "DBInstanceDescription": "DataBase",
        "DBInstanceStorage": {
          "Ref": "DBInstanceStorage"
        },
        "DBMappings": [
          {
            "CharacterSetName": "utf8",
            "DBName": {
              "Ref": "DBName"
            }
          }
        ],
        "Engine": "MySQL",
        "Category": {
          "Ref": "Category"
        },
        "EngineVersion": {
          "Ref": "EngineVersion"
        },
        "MasterUserPassword": {
          "Ref": "DBPassword"
        },
        "MasterUsername": {
          "Ref": "DBUser"
        },
        "SecurityIPList": "0.0.0.0/0"
      },
      "DependsOn": "ECSSnatGateWayGroupWaitCondition"
    },
    "VRoute": {
      "Type": "ALIYUN::ECS::Route",
      "Properties": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "NextHopId": {
          "Fn::GetAtt": [
            "ECSSnatGateWay",
            "InstanceId"
          ]
        },
        "RouteId": {
          "Fn::GetAtt": [
            "Vpc",
            "VRouterId"
          ]
        },
        "RouteTableId": {
          "Fn::GetAtt": [
            "Vpc",
            "RouteTableId"
          ]
        }
      }
    },
    "WebServerGroup": {
      "Type": "ALIYUN::ECS::InstanceGroup",
      "Properties": {
        "VpcId": {
          "Ref": "Vpc"
        },
        "VSwitchId": {
          "Ref": "VSwitch"
        },
        "SecurityGroupId": {
          "Ref": "SecurityGroup"
        },
        "ImageId": {
          "Ref": "ImageId"
        },
        "AllocatePublicIP": true,
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "IoOptimized": "optimized",
        "MaxAmount": {
          "Ref": "NumberOfNode"
        },
        "Password": {
          "Ref": "InstancePassword"
        },
        "SystemDiskCategory": {
          "Ref": "SystemDiskCategory"
        },
        "UserData": {
          "Fn::Replace": [
            {
              "ros-notify": {
                "Fn::GetAtt": [
                  "WebServerGroupConditionHandle",
                  "CurlCli"
                ]
              }
            },
            {
              "Fn::Join": [
                "",
                [
                  "#!/bin/sh",
                  "\n",
                  "DatabaseUser=",
                  {
                    "Ref": "DBUser"
                  },
                  "\n",
                  "DatabasePwd=",
                  {
                    "Ref": "DBPassword"
                  },
                  "\n",
                  "DatabaseName=",
                  {
                    "Ref": "DBName"
                  },
                  "\n",
                  "DatabaseHost=",
                  {
                    "Fn::GetAtt": [
                      "Database",
                      "InnerConnectionString"
                    ]
                  },
                  "\n",
                  "WebRootPath='/var/www/html'\n",
                  "ApacheIndex='Options Indexes FollowSymLinks'\n",
                  "ApacheIndexReplace='Options FollowSymLinks'\n",
                  "mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup\n",
                  "wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo\n",
                  "yum makecache\n",
                  "yum install -y unzip zip \n",
                  "yum install -y curl httpd mysql-server php56 php56-php-mysql \n",
                  "rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm \n",
                  "rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm \n",
                  "yum install -y php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-imap.x86_64 php56w-ldap.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-odbc.x86_64 php56w-process.x86_64 php56w-xml.x86_64 php56w-xmlrpc.x86_64 \n",
                  "chkconfig httpd on\n",
                  "#wget http://wordpress.org/latest.tar.gz\n",
                  "#tar -xzvf latest.tar.gz\n",
                  "wget https://ros-template-resources.oss-cn-beijing.aliyuncs.com/WordPress/WordPress.zip \n",
                  "unzip WordPress.zip \n",
                  "mv WordPress-master wordpress \n",
                  "sed -i \"s/database_name_here/$DatabaseName/\" wordpress/wp-config-sample.php\n",
                  "sed -i \"s/username_here/$DatabaseUser/\" wordpress/wp-config-sample.php\n",
                  "sed -i \"s/password_here/${DatabasePwd:-$DatabasePwdDef}/\" wordpress/wp-config-sample.php\n",
                  "sed -i \"s/localhost/$DatabaseHost/\" wordpress/wp-config-sample.php\n",
                  "mv wordpress/wp-config-sample.php wordpress/wp-config.php\n",
                  "cp -a wordpress/* $WebRootPath\n",
                  "rm -rf wordpress*\n",
                  "service httpd stop\n",
                  "usermod -d $WebRootPath apache &>/dev/null\n",
                  "chown apache:apache -R $WebRootPath\n",
                  "sed -i \"s/$ApacheIndex/$ApacheIndexReplace/\" /etc/httpd/conf/httpd.conf\n",
                  "service httpd start\n",
                  "ros-notify -d '{\"data\" : \"Install Wordpress\"}'\n"
                ]
              ]
            }
          ]
        }
      },
      "DependsOn": "Database"
    },
    "WebServerGroupConditionHandle": {
      "Type": "ALIYUN::ROS::WaitConditionHandle",
      "Properties": {}
    },
    "WebServerGroupWaitCondition": {
      "Type": "ALIYUN::ROS::WaitCondition",
      "Properties": {
        "Count": {
          "Ref": "NumberOfNode"
        },
        "Handle": {
          "Ref": "WebServerGroupConditionHandle"
        },
        "Timeout": 900
      },
      "DependsOn": "WebServerGroup"
    }
  },
  "Outputs": {
    "JumpHostIp": {
      "Description": {
        "en": "The jump host IP.",
        "zh-cn": "跳轉主機IP。"
      },
      "Value": {
        "Fn::GetAtt": [
          "ECSSnatGateWay",
          "PublicIp"
        ]
      }
    },
    "WordPressUrl": {
      "Description": {
        "en": "WordPress URL.",
        "zh-cn": "WordPress 網址。"
      },
      "Value": {
        "Fn::Join": [
          "",
          [
            "http://",
            {
              "Fn::GetAtt": [
                "LoadBalancer",
                "IpAddress"
              ]
            },
            ":80"
          ]
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "VpcCidrBlock",
            "ZoneId",
            "VSwitchCidrBlock"
          ],
          "Label": {
            "default": {
              "en": "VPC",
              "zh-cn": "專用網路"
            }
          }
        },
        {
          "Parameters": [
            "InstanceType",
            "ImageId",
            "SystemDiskCategory",
            "NumberOfNode",
            "InstancePassword"
          ],
          "Label": {
            "default": {
              "en": "ECS",
              "zh-cn": "雲端服務器"
            }
          }
        },
        {
          "Parameters": [
            "LoadBalancerSpec"
          ],
          "Label": {
            "default": {
              "en": "SLB",
              "zh-cn": "負載平衡"
            }
          }
        },
        {
          "Parameters": [
            "Category",
            "EngineVersion",
            "DBInstanceClass",
            "DBInstanceStorage",
            "DBName",
            "DBUser",
            "DBPassword"
          ],
          "Label": {
            "default": {
              "en": "RDS",
              "zh-cn": "資料庫"
            }
          }
        }
      ],
      "TemplateTags": [
        "acs:example:網路:建立WordPress叢集並配置VPC的SNAT功能訪問Internet"
      ]
    }
  }
}