I'm new to CloudFormation and want to create a template using YAML. I need to figure out is there any way we can create multiple VPCs using UserInput. As of now, I've used the following code:
Parameters:
EnvironmentName:
Description: An environment name that is prefixed to resource names
Type: String
vpcCIDR1:
Description: Please enter the IP range (CIDR notation) for this VPC
Type: String
Default: 10.3.0.0/16
vpcCIDR2:
Description: Please enter the IP range (CIDR notation) for this VPC
Type: String
Default: 10.4.0.0/16
Resources:
VPC1:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref vpcCIDR1
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Ref EnvironmentName
VPC2:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref vpcCIDR2
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Ref EnvironmentName
Instead of writing the same code again, I need the code to take user input for the VPCs count and create the VPCs according to the user input.
I've found the Count but when I use !Ref to pass parameter it is not working, it only works when I pass Count: 2 or any numeric value.