Here is an example of creating multiple subnets in a single block of code in YAML Cloud Formation:
yaml
Copy code
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
InstanceTenancy: default
EnableDnsSupport: true
EnableDnsHostnames: true
Subnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.1.0/24
AvailabilityZone: us-west-2a
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.2.0/24
AvailabilityZone: us-west-2b
Subnet3:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
CidrBlock: 10.0.3.0/24
AvailabilityZone: us-west-2c
This code creates a VPC with three subnets. The VPC is defined with its own CidrBlock and properties such as InstanceTenancy, EnableDnsSupport, and EnableDnsHostnames. The subnets are defined with the VpcId referencing the created VPC, a CidrBlock for each subnet, and an AvailabilityZone.
You can modify the code to suit your specific requirements, such as adding more subnets or changing the properties of the VPC or subnets.