Route53私有托管区参数化VPC列表

时间:2017-03-20 13:53:54

标签: amazon-web-services amazon-cloudformation amazon-route53

我正在尝试为Route53 Private Hosted Zone创建一个云形成模板,其中与PHZ相关联的VPC和区域列表作为参数提供

  VPCIds:
    Type: List<AWS::EC2::VPC::Id>
    Description: The Evertz VPC Id

  Regions:
    Type: CommaDelimitedList
    Description: A list that containing the matching regions for the VPCs given

  NumberOfVPC:
    Type: Number

我已经设置了用于指定VPC数量的条件。

Conditions:
  2VPC: !Or [
    !Equals [!Ref NumberOfVPC, 2],
    Condition: 3VPC,
    Condition: 4VPC,
    Condition: 5VPC,
    Condition: 6VPC,
    Condition: 7VPC,
    Condition: 8VPC
    ]
  3VPC: !Or [
    !Equals [!Ref NumberOfVPC, 3],
    Condition: 4VPC,
    Condition: 5VPC,
    Condition: 6VPC,
    Condition: 7VPC,
    Condition: 8VPC
    ]...

很遗憾,我无法创建HostedZoneVPCs

列表

我希望在构建列表时使用这些条件来提供AWS :: NoValue

  Route53PrivateHostedZone:
    Type: "AWS::Route53::HostedZone"
    Properties:
      Name: !Ref ZoneName
      HostedZoneConfig:
        Comment: String
      HostedZoneTags:
        - Key: Name
          Value: Hosted Zone
      VPCs:
        -
          VPCId: !If [2VPC, !Ref "AWS::NoValue", !Select [0, !Ref VPCIds]]
          VPCRegion: !If [2VPC, !Ref "AWS::NoValue", !Select [0, !Ref Regions]]

      VPCs:
        - VPCId: !If [2VPC, !Select [0, !Ref VPCIds], !Ref "AWS::NoValue"]
          VPCRegion: !If [2VPC, !Select [0, !Ref Regions], !Ref "AWS::NoValue"]

        - VPCId: !If [2VPC, !Select [1, !Ref VPCIds], !Ref "AWS::NoValue"]
          VPCRegion: !If [2VPC, !Select [1, !Ref Regions], !Ref "AWS::NoValue"]

但是这不起作用,无法创建托管区域。

我是否可以使用我创建的xVPC条件在Cloudformation中构建HostedZoneVPCs列表?

1 个答案:

答案 0 :(得分:0)

我目前发现的解决方案是嵌套!If并使用此处下降到下一个VPC /区域列表,计数并不多。同时更改条件以使它们不累积;

Conditions:
  1VPC: !Equals [!Ref NumberOfVPC, 1]
  2VPC: !Equals [!Ref NumberOfVPC, 2]
  3VPC: !Equals [!Ref NumberOfVPC, 3]
  4VPC: !Equals [!Ref NumberOfVPC, 4]
  5VPC: !Equals [!Ref NumberOfVPC, 5]
  6VPC: !Equals [!Ref NumberOfVPC, 6]
  7VPC: !Equals [!Ref NumberOfVPC, 7]
  8VPC: !Equals [!Ref NumberOfVPC, 8]

然后VPCs属性成为;

  VPCs:
    !If [1VPC,
    [
      {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]}
    ],
      !If [2VPC,
      [
        {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
        {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]}
      ],
        !If [3VPC,
        [
          {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
          {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
          {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]}
        ],
          !If [4VPC,
          [
            {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
            {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
            {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]},
            {VPCId: !Select [3, !Ref VPCIds], VPCRegion: !Select [3, !Ref Regions]}
          ],
            !If [5VPC,
            [
              {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
              {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
              {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]},
              {VPCId: !Select [3, !Ref VPCIds], VPCRegion: !Select [3, !Ref Regions]},
              {VPCId: !Select [4, !Ref VPCIds], VPCRegion: !Select [4, !Ref Regions]}
            ],
              !If [6VPC,
              [
                {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
                {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
                {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]},
                {VPCId: !Select [3, !Ref VPCIds], VPCRegion: !Select [3, !Ref Regions]},
                {VPCId: !Select [4, !Ref VPCIds], VPCRegion: !Select [4, !Ref Regions]},
                {VPCId: !Select [5, !Ref VPCIds], VPCRegion: !Select [5, !Ref Regions]}
              ],
                !If [7VPC,
                [
                  {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
                  {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
                  {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]},
                  {VPCId: !Select [3, !Ref VPCIds], VPCRegion: !Select [3, !Ref Regions]},
                  {VPCId: !Select [4, !Ref VPCIds], VPCRegion: !Select [4, !Ref Regions]},
                  {VPCId: !Select [5, !Ref VPCIds], VPCRegion: !Select [5, !Ref Regions]},
                  {VPCId: !Select [6, !Ref VPCIds], VPCRegion: !Select [6, !Ref Regions]}
                ],
                  !If [8VPC,
                  [
                    {VPCId: !Select [0, !Ref VPCIds], VPCRegion: !Select [0, !Ref Regions]},
                    {VPCId: !Select [1, !Ref VPCIds], VPCRegion: !Select [1, !Ref Regions]},
                    {VPCId: !Select [2, !Ref VPCIds], VPCRegion: !Select [2, !Ref Regions]},
                    {VPCId: !Select [3, !Ref VPCIds], VPCRegion: !Select [3, !Ref Regions]},
                    {VPCId: !Select [4, !Ref VPCIds], VPCRegion: !Select [4, !Ref Regions]},
                    {VPCId: !Select [5, !Ref VPCIds], VPCRegion: !Select [5, !Ref Regions]},
                    {VPCId: !Select [6, !Ref VPCIds], VPCRegion: !Select [6, !Ref Regions]},
                    {VPCId: !Select [7, !Ref VPCIds], VPCRegion: !Select [7, !Ref Regions]}
                  ],
                  !Ref "AWS::NoValue"
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]