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

Route53 Private Hosted Zone Parameterised List of VPCs

我正在尝试为 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"]

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

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

我目前找到的解决办法是嵌套!If,用这里来落下下一个VPC/Region列表,数量不多。同时更改条件,使其不累积;

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]

然后 VPC 属性 变为;

  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"
                  ]
                ]
              ]
            ]
          ]
        ]
      ]
    ]