blob: e6b391698161659b429d4055d0f265bdc808e653 [file] [log] [blame]
AWSTemplateFormatVersion: '2010-09-09'
Description: Deploy Gerrit network stack
Parameters:
InternetGatewayIdProp:
Type: String
Default: ""
Description: Internet Gateway id. If empty Internet Gateway will be created
VPCIdProp:
Type: String
Default: ""
Description: VPC id. If empty VPC will be created
Subnet1IdProp:
Type: String
Default: ""
Description: Subnet1 id. If empty Network Stack will be created
Subnet2IdProp:
Type: String
Default: ""
Description: Subnet2 id. If empty Network Stack will be created
Subnet1CIDR:
Type: String
Default: 10.0.0.0/24
Description: Subnet 1 CIDR.
Subnet2CIDR:
Type: String
Default: 10.0.32.0/24
Description: Subnet 2 CIDR.
VPCCIDR:
Type: String
Default: 10.0.0.0/16
Description: VPC CIDR.
Subnet1AZProp:
Type: String
Default: ""
Description: The Availability Zone of subnet1
Subnet2AZProp:
Type: String
Default: ""
Description: The Availability Zone of subnet2
Conditions:
CreateVPC: !Equals [!Ref VPCIdProp, ""]
CreateNetworkStack: !Equals [!Ref Subnet1IdProp, ""]
HasSubnet1AZ: !Not
- !Equals [!Ref Subnet1AZProp, ""]
HasSubnet2AZ: !Not
- !Equals [!Ref Subnet2AZProp, ""]
CreateInternetGateway: !And
- !Equals [!Ref InternetGatewayIdProp, ""]
- !Condition CreateNetworkStack
Resources:
VPC:
Condition: CreateVPC
Type: AWS::EC2::VPC
Properties:
EnableDnsSupport: true
EnableDnsHostnames: true
CidrBlock: !Ref VPCCIDR
# Public subnets, where containers can have public IP addresses
PublicSubnetOne:
Condition: CreateNetworkStack
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::If:
- HasSubnet1AZ
- !Ref 'Subnet1AZProp'
- Fn::Select:
- 0
- Fn::GetAZs: ""
VpcId: !If [CreateVPC, !Ref 'VPC', !Ref 'VPCIdProp' ]
CidrBlock: !Ref 'Subnet1CIDR'
MapPublicIpOnLaunch: true
PublicSubnetTwo:
Condition: CreateNetworkStack
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone:
Fn::If:
- HasSubnet2AZ
- !Ref 'Subnet2AZProp'
- Fn::Select:
- 1
- Fn::GetAZs: ""
VpcId: !If [CreateVPC, !Ref 'VPC', !Ref 'VPCIdProp' ]
CidrBlock: !Ref 'Subnet2CIDR'
MapPublicIpOnLaunch: true
# Setup networking resources for the public subnets. Containers
# in the public subnets have public IP addresses and the routing table
# sends network traffic via the internet gateway.
InternetGateway:
Condition: CreateInternetGateway
Type: AWS::EC2::InternetGateway
GatewayAttachement:
Condition: CreateNetworkStack
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !If [CreateVPC, !Ref 'VPC', !Ref 'VPCIdProp' ]
InternetGatewayId: !If [CreateInternetGateway, !Ref 'InternetGateway', !Ref 'InternetGatewayIdProp' ]
PublicRouteTable:
Condition: CreateNetworkStack
Type: AWS::EC2::RouteTable
Properties:
VpcId: !If [CreateVPC, !Ref 'VPC', !Ref 'VPCIdProp' ]
PublicRoute:
Condition: CreateNetworkStack
Type: AWS::EC2::Route
DependsOn: GatewayAttachement
Properties:
RouteTableId: !Ref 'PublicRouteTable'
DestinationCidrBlock: '0.0.0.0/0'
GatewayId: !If [CreateInternetGateway, !Ref 'InternetGateway', !Ref 'InternetGatewayIdProp' ]
PublicSubnetOneRouteTableAssociation:
Condition: CreateNetworkStack
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnetOne
RouteTableId: !Ref PublicRouteTable
PublicSubnetTwoRouteTableAssociation:
Condition: CreateNetworkStack
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnetTwo
RouteTableId: !Ref PublicRouteTable
Outputs:
VPCRef:
Value: !If [CreateVPC, !Ref 'VPC', !Ref 'VPCIdProp' ]
PublicSubnetOneRef:
Value: !If [CreateNetworkStack, !Ref 'PublicSubnetOne', !Ref 'Subnet1IdProp' ]
PublicSubnetOneAZ:
Value: !If [CreateNetworkStack, !GetAtt PublicSubnetOne.AvailabilityZone, !Ref 'Subnet1AZProp' ]
PublicOneCIDR:
Value: !Ref 'Subnet1CIDR'
PublicSubnetTwoRef:
Value: !If [CreateNetworkStack, !Ref 'PublicSubnetTwo', !Ref 'Subnet2IdProp' ]
PublicSubnetTwoAZ:
Value: !If [CreateNetworkStack, !GetAtt PublicSubnetTwo.AvailabilityZone, !Ref 'Subnet2AZProp' ]
PublicTwoCIDR:
Value: !Ref 'Subnet2CIDR'