Skip to content

Instantly share code, notes, and snippets.

@msato0731
Last active July 6, 2018 23:28
Show Gist options
  • Save msato0731/4362981f917626a7c1154be86562ca5e to your computer and use it in GitHub Desktop.
Save msato0731/4362981f917626a7c1154be86562ca5e to your computer and use it in GitHub Desktop.
# VPC
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ProjectId:
Description: "Project name id."
Type: String
AllowedPattern: '^[a-zA-Z0-9-/:-@\[-\`\{-\~]+$'
ConstraintDescription: "InvalidValue[ProjectId]"
Default: cfn
EnvironmentType:
Description: The environment type
Type: String
Default: test
AllowedValues:
- prod
- test
ConstraintDescription: must be a prod or test
Mappings:
prod:
VPC:
VpcCidrBlock: 10.0.0ß.0/16
Subnet:
PublicSubnet1: 10.0.1.0/24
test:
VPC:
VpcCidrBlock: 10.1.0.0/16
Subnet:
PublicSubnet1: 10.1.1.0/24
Resources:
VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: !FindInMap [ !Ref EnvironmentType, VPC, VpcCidrBlock ]
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: "default"
Tags:
- Key: Name
Value: !Sub "${ProjectId}-${EnvironmentType}-vpc"
PublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
CidrBlock: !FindInMap [ !Ref EnvironmentType, Subnet, PublicSubnet1 ]
MapPublicIpOnLaunch: false
AvailabilityZone: ap-northeast-1a
Tags:
- Key: Name
Value: !Sub "${ProjectId}-${EnvironmentType}-PublicSubnet1"
VpcId: !Ref VPC
Outputs:
MyVPC:
Value: !Ref VPC
Export:
Name: !Sub "${ProjectId}-${EnvironmentType}-vpc"
PublicSubnet1:
Value: !Ref PublicSubnet1
Export:
Name: !Sub "${ProjectId}-${EnvironmentType}-PublicSubnet1"
# SecurityGroup
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ProjectId:
Description: "Project name id."
Type: String
AllowedPattern: '^[a-zA-Z0-9-/:-@\[-\`\{-\~]+$'
ConstraintDescription: "InvalidValue[ProjectId]"
Default: cfn
EnvironmentType:
Description: The environment type
Type: String
Default: test
AllowedValues:
- prod
- test
ConstraintDescription: must be a prod or test
Resources:
# WEBServer SecurityGroup
SecurityGroupForWeb:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupName: !Sub "${ProjectId}-${EnvironmentType}-Web-SG"
GroupDescription: >-
SG for Web Server
# Inbound SecurityGroup
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: SSH
FromPort: 22
IpProtocol: tcp
ToPort: 22
- CidrIp: 0.0.0.0/0
Description: HTTP
FromPort: 80
IpProtocol: tcp
ToPort: 80
- CidrIp: 0.0.0.0/0
Description: HTTPS
FromPort: 443
IpProtocol: tcp
ToPort: 443
VpcId: {"Fn::ImportValue": !Sub "${ProjectId}-${EnvironmentType}-vpc"}
Tags:
- Key: Name
Value: !Sub "${ProjectId}-${EnvironmentType}-Web-SG"
Outputs:
SecurityGroupForWeb:
Value: !Ref SecurityGroupForWeb
Export:
Name: !Sub "${ProjectId}-${EnvironmentType}-SecurityGroupForWeb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment