SHOW:
|
|
- or go back to the newest paste.
| 1 | --- | |
| 2 | AWSTemplateFormatVersion: '2010-09-09' | |
| 3 | Description: '2AZs (pub+priv) (based on cloudonaut.io template)' | |
| 4 | # Invoke with | |
| 5 | - | # aws cloudformation create-stack --stack-name <name> --template-body https://pastebin.com/raw/<id> --parameters ParameterKey=Owner,ParameterValue=<owner> ParameterKey=ClassB,ParameterValue=10 ParameterKey=NatSubnetZone,ParameterValue=B --profile awslabs |
| 5 | + | # aws cloudformation create-stack --stack-name <name> --template-body https://pastebin.com/raw/<id> --parameters ParameterKey=Owner,ParameterValue=<owner> ParameterKey=ClassB,ParameterValue=10 --profile awslabs |
| 6 | Metadata: | |
| 7 | 'AWS::CloudFormation::Interface': | |
| 8 | ParameterGroups: | |
| 9 | - Label: | |
| 10 | default: 'VPC Parameters' | |
| 11 | Parameters: | |
| 12 | - ClassB | |
| 13 | Parameters: | |
| 14 | ClassB: | |
| 15 | Description: 'Class B of VPC (10.XXX.0.0/16)' | |
| 16 | Type: Number | |
| 17 | Default: 0 | |
| 18 | ConstraintDescription: 'Must be in the range [0-255]' | |
| 19 | MinValue: 0 | |
| 20 | MaxValue: 255 | |
| 21 | Owner: | |
| 22 | Description: 'Owner of the resources.' | |
| 23 | Type: String | |
| 24 | - | NatSubnetZone: |
| 24 | + | |
| 25 | - | Description: 'NATgw Subnet zone.' |
| 25 | + | |
| 26 | VPC: | |
| 27 | - | Default: A |
| 27 | + | |
| 28 | - | AllowedValues: |
| 28 | + | |
| 29 | - | - A |
| 29 | + | |
| 30 | - | - B |
| 30 | + | |
| 31 | - | Conditions: |
| 31 | + | |
| 32 | - | NatInPublicSubnetA: !Equals [ !Ref NatSubnetZone, A ] |
| 32 | + | |
| 33 | - | |
| 33 | + | |
| 34 | - Key: Name | |
| 35 | Value: !Sub '${Owner}-vpc-${ClassB}'
| |
| 36 | - Key: Owner | |
| 37 | Value: !Sub '${Owner}'
| |
| 38 | InternetGateway: | |
| 39 | Type: 'AWS::EC2::InternetGateway' | |
| 40 | Properties: | |
| 41 | Tags: | |
| 42 | - Key: Name | |
| 43 | Value: !Sub '${Owner}-igw-${ClassB}'
| |
| 44 | - Key: Owner | |
| 45 | Value: !Sub '${Owner}'
| |
| 46 | VPCGatewayAttachment: | |
| 47 | Type: 'AWS::EC2::VPCGatewayAttachment' | |
| 48 | Properties: | |
| 49 | VpcId: !Ref VPC | |
| 50 | InternetGatewayId: !Ref InternetGateway | |
| 51 | SubnetAPublic: | |
| 52 | Type: 'AWS::EC2::Subnet' | |
| 53 | Properties: | |
| 54 | AvailabilityZone: !Select [0, !GetAZs ''] | |
| 55 | CidrBlock: !Sub '10.${ClassB}.0.0/20'
| |
| 56 | MapPublicIpOnLaunch: true | |
| 57 | VpcId: !Ref VPC | |
| 58 | Tags: | |
| 59 | - Key: Name | |
| 60 | Value: !Sub '${Owner}-sub-${ClassB}-A public'
| |
| 61 | - Key: Reach | |
| 62 | Value: public | |
| 63 | - Key: Owner | |
| 64 | Value: !Sub '${Owner}'
| |
| 65 | SubnetAPrivate: | |
| 66 | Type: 'AWS::EC2::Subnet' | |
| 67 | Properties: | |
| 68 | AvailabilityZone: !Select [0, !GetAZs ''] | |
| 69 | CidrBlock: !Sub '10.${ClassB}.16.0/20'
| |
| 70 | VpcId: !Ref VPC | |
| 71 | Tags: | |
| 72 | - Key: Name | |
| 73 | Value: !Sub '${Owner}-sub-${ClassB}-A private'
| |
| 74 | - Key: Reach | |
| 75 | Value: private | |
| 76 | - Key: Owner | |
| 77 | Value: !Sub '${Owner}'
| |
| 78 | SubnetBPublic: | |
| 79 | Type: 'AWS::EC2::Subnet' | |
| 80 | Properties: | |
| 81 | AvailabilityZone: !Select [1, !GetAZs ''] | |
| 82 | CidrBlock: !Sub '10.${ClassB}.32.0/20'
| |
| 83 | MapPublicIpOnLaunch: true | |
| 84 | VpcId: !Ref VPC | |
| 85 | Tags: | |
| 86 | - Key: Name | |
| 87 | Value: !Sub '${Owner}-sub-${ClassB}-B public'
| |
| 88 | - Key: Reach | |
| 89 | Value: public | |
| 90 | - Key: Owner | |
| 91 | Value: !Sub '${Owner}'
| |
| 92 | SubnetBPrivate: | |
| 93 | Type: 'AWS::EC2::Subnet' | |
| 94 | Properties: | |
| 95 | AvailabilityZone: !Select [1, !GetAZs ''] | |
| 96 | CidrBlock: !Sub '10.${ClassB}.48.0/20'
| |
| 97 | VpcId: !Ref VPC | |
| 98 | Tags: | |
| 99 | - Key: Name | |
| 100 | Value: !Sub '${Owner}-sub-${ClassB}-B private'
| |
| 101 | - Key: Reach | |
| 102 | Value: private | |
| 103 | - Key: Owner | |
| 104 | Value: !Sub '${Owner}'
| |
| 105 | RouteTablePublic: | |
| 106 | Type: 'AWS::EC2::RouteTable' | |
| 107 | Properties: | |
| 108 | VpcId: !Ref VPC | |
| 109 | Tags: | |
| 110 | - Key: Name | |
| 111 | Value: !Sub '${Owner}-rt-${ClassB}-public'
| |
| 112 | - Key: Owner | |
| 113 | Value: !Sub '${Owner}'
| |
| 114 | RouteTablePrivate: | |
| 115 | Type: 'AWS::EC2::RouteTable' | |
| 116 | Properties: | |
| 117 | VpcId: !Ref VPC | |
| 118 | Tags: | |
| 119 | - Key: Name | |
| 120 | Value: !Sub '${Owner}-rt-${ClassB}-private'
| |
| 121 | - Key: Owner | |
| 122 | Value: !Sub '${Owner}'
| |
| 123 | RouteTableAssociationAPublic: | |
| 124 | Type: 'AWS::EC2::SubnetRouteTableAssociation' | |
| 125 | Properties: | |
| 126 | SubnetId: !Ref SubnetAPublic | |
| 127 | RouteTableId: !Ref RouteTablePublic | |
| 128 | RouteTableAssociationAPrivate: | |
| 129 | Type: 'AWS::EC2::SubnetRouteTableAssociation' | |
| 130 | Properties: | |
| 131 | SubnetId: !Ref SubnetAPrivate | |
| 132 | RouteTableId: !Ref RouteTablePrivate | |
| 133 | RouteTableAssociationBPublic: | |
| 134 | Type: 'AWS::EC2::SubnetRouteTableAssociation' | |
| 135 | Properties: | |
| 136 | SubnetId: !Ref SubnetBPublic | |
| 137 | RouteTableId: !Ref RouteTablePublic | |
| 138 | RouteTableAssociationBPrivate: | |
| 139 | Type: 'AWS::EC2::SubnetRouteTableAssociation' | |
| 140 | Properties: | |
| 141 | SubnetId: !Ref SubnetBPrivate | |
| 142 | RouteTableId: !Ref RouteTablePrivate | |
| 143 | RouteTablePublicInternetRoute: | |
| 144 | Type: 'AWS::EC2::Route' | |
| 145 | DependsOn: VPCGatewayAttachment | |
| 146 | Properties: | |
| 147 | RouteTableId: !Ref RouteTablePublic | |
| 148 | DestinationCidrBlock: '0.0.0.0/0' | |
| 149 | GatewayId: !Ref InternetGateway | |
| 150 | ||
| 151 | ||
| 152 | ||
| 153 | ||
| 154 | Outputs: | |
| 155 | TemplateID: | |
| 156 | Description: 'cloudonaut.io template id' | |
| 157 | Value: 'vpc/vpc-2azs' | |
| 158 | StackName: | |
| 159 | Description: 'Stack name' | |
| 160 | Value: !Sub '${AWS::StackName}'
| |
| 161 | AZs: | |
| 162 | - | EIP: |
| 162 | + | |
| 163 | - | Type: 'AWS::EC2::EIP' |
| 163 | + | |
| 164 | Export: | |
| 165 | - | Domain: vp |
| 165 | + | |
| 166 | - | NatGateway: |
| 166 | + | |
| 167 | - | Type: 'AWS::EC2::NatGateway' |
| 167 | + | |
| 168 | Value: !Select [0, !GetAZs ''] | |
| 169 | - | AllocationId: !GetAtt 'EIP.AllocationId' |
| 169 | + | |
| 170 | - | SubnetId: !If [NatInPublicSubnetA, !Ref SubnetAPublic, !Ref SubnetBPublic] |
| 170 | + | |
| 171 | - | Route: |
| 171 | + | |
| 172 | - | Type: AWS::EC2::Route |
| 172 | + | |
| 173 | Value: !Select [1, !GetAZs ''] | |
| 174 | Export: | |
| 175 | Name: !Sub '${AWS::StackName}-AZB'
| |
| 176 | - | NatGatewayId: !Ref NatGateway |
| 176 | + | |
| 177 | Description: 'Class B.' | |
| 178 | Value: !Ref ClassB | |
| 179 | Export: | |
| 180 | Name: !Sub '${AWS::StackName}-ClassB'
| |
| 181 | VPC: | |
| 182 | Description: 'VPC.' | |
| 183 | Value: !Ref VPC | |
| 184 | Export: | |
| 185 | Name: !Sub '${AWS::StackName}-VPC'
| |
| 186 | SubnetsPublic: | |
| 187 | Description: 'Subnets public.' | |
| 188 | Value: !Join [',', [!Ref SubnetAPublic, !Ref SubnetBPublic]] | |
| 189 | Export: | |
| 190 | Name: !Sub '${AWS::StackName}-SubnetsPublic'
| |
| 191 | SubnetsPrivate: | |
| 192 | Description: 'Subnets private.' | |
| 193 | Value: !Join [',', [!Ref SubnetAPrivate, !Ref SubnetBPrivate]] | |
| 194 | Export: | |
| 195 | Name: !Sub '${AWS::StackName}-SubnetsPrivate'
| |
| 196 | SubnetAPublic: | |
| 197 | Description: 'Subnet A public.' | |
| 198 | Value: !Ref SubnetAPublic | |
| 199 | Export: | |
| 200 | Name: !Sub '${AWS::StackName}-SubnetAPublic'
| |
| 201 | SubnetPrivate: | |
| 202 | Description: 'Subnet A private.' | |
| 203 | Value: !Ref SubnetAPrivate | |
| 204 | Export: | |
| 205 | Name: !Sub '${AWS::StackName}-SubnetAPrivate'
| |
| 206 | SubnetBPublic: | |
| 207 | Description: 'Subnet B public.' | |
| 208 | Value: !Ref SubnetBPublic | |
| 209 | Export: | |
| 210 | Name: !Sub '${AWS::StackName}-SubnetBPublic'
| |
| 211 | SubnetBPrivate: | |
| 212 | Description: 'Subnet B private.' | |
| 213 | Value: !Ref SubnetBPrivate | |
| 214 | Export: | |
| 215 | Name: !Sub '${AWS::StackName}-SubnetBPrivate'
| |
| 216 | RouteTablePrivate: | |
| 217 | Description: 'Route table private (deprecated in v4, will be removed in v5).' | |
| 218 | Value: !Ref RouteTablePrivate | |
| 219 | Export: | |
| 220 | Name: !Sub '${AWS::StackName}-RouteTablePrivate'
| |
| 221 | RouteTablePublic: | |
| 222 | Description: 'Route table public (deprecated in v4, will be removed in v5).' | |
| 223 | Value: !Ref RouteTablePublic | |
| 224 | Export: | |
| 225 | Name: !Sub '${AWS::StackName}-RouteTablePublic' |