Reputation: 1039
I'm trying to create a Cloud Formation Template for a Route53 Private Hosted Zone where lists of VPCs and Regions that the PHZ is associated are supplied as a Parameter
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
I've got conditions set up to for specifying the number of VPCs.
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
]...
unfortunately I've not been able to create the list of HostedZoneVPCs
I was hoping to use these conditions to supply AWS::NoValue to when building the list
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"]
However this does not work and fails to create the Hosted Zone.
Is there any way within Cloudformation that I can construct the list of HostedZoneVPCs using the xVPC Conditions I've created?
Upvotes: 0
Views: 232
Reputation: 1039
The solution I've currently found is to nest !If
and use here to fall down to the next VPC/Region List is the count does not much. Also change Conditions so that they are not cumulative;
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]
and the VPCs Property then becomes;
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"
]
]
]
]
]
]
]
]
Upvotes: 0