Posted at

EKS用に8個のサブネットを持つVPCを作成するCF

More than 1 year has passed since last update.


前提


  • EKSのチュートリアルで利用するVPCのCFに書き加えただけ

  • サブネットを8つにしたかった


CFのコード

---

AWSTemplateFormatVersion: '2010-09-09'
Description: 'Amazon EKS Sample VPC'

Parameters:

VpcBlock:
Type: String
Default: 192.168.0.0/16
Description: The CIDR range for the VPC. This should be a valid private (RFC 1918) CIDR range.

Subnet01Block:
Type: String
Default: 192.168.0.0/19
Description: CidrBlock for subnet 01 within the VPC

Subnet02Block:
Type: String
Default: 192.168.32.0/19
Description: CidrBlock for subnet 02 within the VPC

Subnet03Block:
Type: String
Default: 192.168.64.0/19
Description: CidrBlock for subnet 03 within the VPC

Subnet04Block:
Type: String
Default: 192.168.96.0/19
Description: CidrBlock for subnet 04 within the VPC

Subnet05Block:
Type: String
Default: 192.168.128.0/19
Description: CidrBlock for subnet 05 within the VPC

Subnet06Block:
Type: String
Default: 192.168.160.0/19
Description: CidrBlock for subnet 06 within the VPC

Subnet07Block:
Type: String
Default: 192.168.192.0/19
Description: CidrBlock for subnet 07 within the VPC

Subnet08Block:
Type: String
Default: 192.168.224.0/19
Description: CidrBlock for subnet 08 within the VPC

Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: "Worker Network Configuration"
Parameters:
- VpcBlock
- Subnet01Block
- Subnet02Block
- Subnet03Block
- Subnet04Block
- Subnet05Block
- Subnet06Block
- Subnet07Block
- Subnet08Block

Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcBlock
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: !Sub '${AWS::StackName}-VPC'

InternetGateway:
Type: "AWS::EC2::InternetGateway"

VPCGatewayAttachment:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC

RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: Public Subnets
- Key: Network
Value: Public

Route:
DependsOn: VPCGatewayAttachment
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway

Subnet01:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 01
Properties:
AvailabilityZone:
Fn::Select:
- '0'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet01Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet01"

Subnet02:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 02
Properties:
AvailabilityZone:
Fn::Select:
- '1'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet02Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet02"

Subnet03:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 03
Properties:
AvailabilityZone:
Fn::Select:
- '2'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet03Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet03"

Subnet04:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 04
Properties:
AvailabilityZone:
Fn::Select:
- '3'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet04Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet04"

Subnet05:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 05
Properties:
AvailabilityZone:
Fn::Select:
- '0'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet05Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet05"

Subnet06:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 06
Properties:
AvailabilityZone:
Fn::Select:
- '1'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet06Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet06"

Subnet07:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 07
Properties:
AvailabilityZone:
Fn::Select:
- '2'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet07Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet07"

Subnet08:
Type: AWS::EC2::Subnet
Metadata:
Comment: Subnet 08
Properties:
AvailabilityZone:
Fn::Select:
- '3'
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Ref: Subnet08Block
VpcId:
Ref: VPC
Tags:
- Key: Name
Value: !Sub "${AWS::StackName}-Subnet08"

Subnet01RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet01
RouteTableId: !Ref RouteTable

Subnet02RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet02
RouteTableId: !Ref RouteTable

Subnet03RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet03
RouteTableId: !Ref RouteTable

Subnet04RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet04
RouteTableId: !Ref RouteTable

Subnet05RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet05
RouteTableId: !Ref RouteTable

Subnet06RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet06
RouteTableId: !Ref RouteTable

Subnet07RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet07
RouteTableId: !Ref RouteTable

Subnet08RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref Subnet08
RouteTableId: !Ref RouteTable

ControlPlaneSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Cluster communication with worker nodes
VpcId: !Ref VPC

Outputs:

SubnetIds:
Description: All subnets in the VPC
Value: !Join [ ",", [ !Ref Subnet01, !Ref Subnet02, !Ref Subnet03, !Ref Subnet04, !Ref Subnet04, !Ref Subnet05, !Ref Subnet06, !Ref Subnet07, !Ref Subnet08] ]

SecurityGroups:
Description: Security group for the cluster control plane communication with worker nodes
Value: !Join [ ",", [ !Ref ControlPlaneSecurityGroup ] ]

VpcId:
Description: The VPC Id
Value: !Ref VPC