Skip to content

Instantly share code, notes, and snippets.

@sakamaki-kazuyoshi
Created July 16, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakamaki-kazuyoshi/cd739486c0e6ea3fd685e6bc4d4b7370 to your computer and use it in GitHub Desktop.
Save sakamaki-kazuyoshi/cd739486c0e6ea3fd685e6bc4d4b7370 to your computer and use it in GitHub Desktop.
HighPerformanceComputing
AWSTemplateFormatVersion: '2010-09-09'
Description: "Create BaseNetwork"
Parameters:
EnvType:
Description: Select Environment Type. Default is prd
Type: String
Default: prd
AllowedValues:
- prd
- dev
Mappings:
prd:
IPAddress:
VPCCider: 10.0.0.0/16
ResourceName:
VPCName: hpc-test-vpc
InternetGatewayName: hpc-test-igw
Resources:
Ec2Vpc:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: !FindInMap [ Ref: EnvType, IPAddress, VPCCider ]
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, VPCName ]
Ec2InternetGateway:
Type: "AWS::EC2::InternetGateway"
Properties:
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, InternetGatewayName ]
AttachIGW:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
VpcId: !Ref Ec2Vpc
InternetGatewayId: !Ref Ec2InternetGateway
Outputs:
StackEc2Vpc:
Value: !Ref Ec2Vpc
Export:
Name: !Sub "${AWS::StackName}-VPCID"
StackEc2InternetGateway:
Value: !Ref Ec2InternetGateway
Export:
Name: !Sub "${AWS::StackName}-InternetGatewayID"
AWSTemplateFormatVersion: '2010-09-09'
Description: "Create SharedServices"
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Parameters:
- EnvType
- BaseNetworkStackName
Parameters:
EnvType:
Description: Select Environment Type. Default is prd
Type: String
Default: prd
AllowedValues:
- prd
- dev
BaseNetworkStackName:
Description: BaseNetwork stack name
Type: String
Mappings:
prd:
IPAddress:
SubnetCider01: 10.0.1.0/24
SubnetCider02: 10.0.2.0/24
ResourceName:
NetworkAclName: hpc-test-nacl
SubnetName01: hpc-test-01-subnet
SubnetName02: hpc-test-02-subnet
RouteTableName01: hpc-test-rtb
Resources:
NetworkAcl01:
Type: "AWS::EC2::NetworkAcl"
Properties:
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, NetworkAclName ]
VpcId: { "Fn::ImportValue": !Join [ "-", [ "Ref":"BaseNetworkStackName","VPCID"]] }
NetworkAclEntryEgressTrue:
Type: "AWS::EC2::NetworkAclEntry"
Properties:
CidrBlock: 0.0.0.0/0
Egress: true
NetworkAclId: !Ref NetworkAcl01
Protocol: -1
RuleAction : allow
RuleNumber : 100
NetworkAclEntryEgressFalse:
Type: "AWS::EC2::NetworkAclEntry"
Properties:
CidrBlock: 0.0.0.0/0
Egress: false
NetworkAclId: !Ref NetworkAcl01
Protocol: -1
RuleAction : allow
RuleNumber : 100
RouteTable01:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: { "Fn::ImportValue": !Join [ "-", [ "Ref":"BaseNetworkStackName","VPCID"]] }
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, RouteTableName01 ]
RouteIGW:
Type: "AWS::EC2::Route"
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: { "Fn::ImportValue": !Join [ "-", [ "Ref":"BaseNetworkStackName","InternetGatewayID"]] }
RouteTableId: !Ref RouteTable01
Subnet01:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: { "Fn::ImportValue": !Join [ "-", [ "Ref":"BaseNetworkStackName","VPCID"]] }
AvailabilityZone: ap-northeast-1a
CidrBlock: !FindInMap [ Ref: EnvType, IPAddress, SubnetCider01 ]
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, SubnetName01 ]
Subnet02:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: { "Fn::ImportValue": !Join [ "-", [ "Ref":"BaseNetworkStackName","VPCID"]] }
AvailabilityZone: ap-northeast-1c
CidrBlock: !FindInMap [ Ref: EnvType, IPAddress, SubnetCider02 ]
Tags:
- Key: Name
Value: !FindInMap [ Ref: EnvType, ResourceName, SubnetName02 ]
SubnetRouteTableAssociation01:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
SubnetId: !Ref Subnet01
RouteTableId: !Ref RouteTable01
SubnetNetworkAclAssociation01:
Type: "AWS::EC2::SubnetNetworkAclAssociation"
Properties:
SubnetId: !Ref Subnet01
NetworkAclId: !Ref NetworkAcl01
SubnetRouteTableAssociation02:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
SubnetId: !Ref Subnet02
RouteTableId: !Ref RouteTable01
SubnetNetworkAclAssociation02:
Type: "AWS::EC2::SubnetNetworkAclAssociation"
Properties:
SubnetId: !Ref Subnet02
NetworkAclId: !Ref NetworkAcl01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment