Example - Nested stack: Root stack template
AWSTemplateFormatVersion: "2010-09-09"
Description: AWS CloudFormation workshop - Nested stacks - Root template (uksb-1q9p31idr).
Parameters:
AvailabilityZones:
Type: List<AWS::EC2::AvailabilityZone::Name>
Description: The list of Availability Zones to use for the subnets in the VPC. Select 2 AZs.
VPCName:
Type: String
Description: The name of the VPC.
Default: cfn-workshop-vpc
VPCCidr:
Type: String
Description: The CIDR block for the VPC.
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/16
PublicSubnet1Cidr:
Type: String
Description: The CIDR block for the public subnet located in Availability Zone 1.
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/24
PublicSubnet2Cidr:
Type: String
Description: The CIDR block for the public subnet located in Availability Zone 2.
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.1.0/24
EnvironmentType:
Description: 'Specify the Environment type of the stack.'
Type: String
Default: Test
AllowedValues:
- Dev
- Test
- Prod
ConstraintDescription: 'Specify either Dev, Test or Prod.'
Resources:
VpcStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: ./vpc.yaml
TimeoutInMinutes: 20
Parameters:
AvailabilityZones:
Fn::Join:
- ','
- !Ref AvailabilityZones
VPCCidr: !Ref VPCCidr
VPCName: !Ref VPCName
PublicSubnet1Cidr: !Ref PublicSubnet1Cidr
PublicSubnet2Cidr: !Ref PublicSubnet2Cidr
IamStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: ./iam.yaml
TimeoutInMinutes: 10
EC2Stack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: ./ec2.yaml
TimeoutInMinutes: 20
Parameters:
EnvironmentType: !Ref EnvironmentType
VpcId: !GetAtt VpcStack.Outputs.VpcId
SubnetId: !GetAtt VpcStack.Outputs.PublicSubnet1
WebServerInstanceProfile: !GetAtt IamStack.Outputs.WebServerInstanceProfile
Outputs:
WebsiteURL:
Value: !GetAtt EC2Stack.Outputs.WebsiteURL