Thanks for the tip Michael and thank you for troubleshooting this step by step. We are heading in the right direction.
This is from the stack “demo-app-Vpc-ZBZIWQGHUZC0-SubnetCPrivate-8Q99DXA9MYV3”
Subnet CREATE_FAILED Template error: Fn::Select cannot select nonexistent value at index 2
I’ve tried this process about 6 times and this error is consistent.
I’m not sure if this matters, but this is the template I copied from the AWS VPC Subnet module.
AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules: AWS VPC Subnet'
Parameters:
VpcPlainModule:
Description: stack name of vpc-plain module
Type: String
Reach:
Description: Should the subnet has a route to the Internet?
Type: String
AllowedValues:
- private
- public
AZIndex:
Description: Index of the AZ where the subnet should be created in
Type: Number
MinValue: 0
MaxValue: 2
AZChar:
Description: Availability zone char
Type: String
AllowedValues:
- A
- B
- C
SubnetIndex:
Description: Index of the subnet
Type: Number
MinValue: 0
MaxValue: 5
SubnetCount:
Description: To slice the IP address ranges you need to specify how many subnets
you want to create in the VPC
Type: Number
MinValue: 1
MaxValue: 6
Conditions:
IsPublic:
Fn::Equals:
- Ref: Reach
- public
Resources:
Subnet:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::Select:
- Ref: AZIndex
- Fn::GetAZs: ''
CidrBlock:
Fn::Select:
- Ref: SubnetIndex
- Fn::Cidr:
- Fn::ImportValue:
Fn::Sub: ${VpcPlainModule}-CidrBlock
- Ref: SubnetCount
- 12
VpcId:
Fn::ImportValue:
Fn::Sub: ${VpcPlainModule}-Id
Tags:
- Key: Name
Value:
Fn::Sub: ${AZChar} ${Reach}
- Key: Reach
Value:
Ref: Reach
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Fn::ImportValue:
Fn::Sub: ${VpcPlainModule}-Id
Tags:
- Key: Name
Value:
Fn::Sub: ${AZChar} ${Reach}
SubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: Subnet
RouteTableId:
Ref: RouteTable
RouteInternet:
Type: AWS::EC2::Route
Condition: IsPublic
Properties:
RouteTableId:
Ref: RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Fn::ImportValue:
Fn::Sub: ${VpcPlainModule}-InternetGatewayId
NetworkAcl:
Type: AWS::EC2::NetworkAcl
Properties:
VpcId:
Fn::ImportValue:
Fn::Sub: ${VpcPlainModule}-Id
Tags:
- Key: Name
Value:
Fn::Sub: ${AZChar} ${Reach}
NetworkAclEntryAllowAllInbound:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId:
Ref: NetworkAcl
RuleNumber: 99
Protocol: -1
RuleAction: allow
Egress: false
CidrBlock: 0.0.0.0/0
NetworkAclEntryAllowAllOutbound:
Type: AWS::EC2::NetworkAclEntry
Properties:
NetworkAclId:
Ref: NetworkAcl
RuleNumber: 99
Protocol: -1
RuleAction: allow
Egress: true
CidrBlock: 0.0.0.0/0
SubnetNetworkAclAssociation:
Type: AWS::EC2::SubnetNetworkAclAssociation
Properties:
SubnetId:
Ref: Subnet
NetworkAclId:
Ref: NetworkAcl
Outputs:
ModuleId:
Value: vpc-subnet
ModuleVersion:
Value: 1.0.0
StackName:
Value:
Ref: AWS::StackName
Id:
Value:
Ref: Subnet
Export:
Name:
Fn::Sub: ${AWS::StackName}-Id
RouteTableId:
Value:
Ref: RouteTable
Export:
Name:
Fn::Sub: ${AWS::StackName}-RouteTableId
AvailabilityZone:
Value:
Fn::Select:
- Ref: AZIndex
- Fn::GetAZs: ''
Export:
Name:
Fn::Sub: ${AWS::StackName}-AvailabilityZone