Last active
February 28, 2017 12:11
-
-
Save Noppy/337571e61a8cba0d3da6e6a2ffffd0b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description" : "Creates an VPC, 2 public subnets, 2 private subnets, and an Amazon EC2 instance.EC2 instance is Amazon Linux and ts2.nano", | |
"Parameters" : { | |
"KeyName": { | |
"Description" : "Name of an existing EC2 key pair for SSH access to the EC2 instance.", | |
"Type": "AWS::EC2::KeyPair::KeyName" | |
} | |
}, | |
"Resources": { | |
"MainVPC": { | |
"Type": "AWS::EC2::VPC", | |
"Properties": { | |
"CidrBlock": "10.0.0.0/16", | |
"EnableDnsSupport": "true", | |
"EnableDnsHostnames": "true", | |
"InstanceTenancy": "default", | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
} | |
] | |
} | |
}, | |
"InetGW": { | |
"Type": "AWS::EC2::InternetGateway", | |
"Properties": { | |
"Tags" : [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"AttachInetGW": { | |
"Type": "AWS::EC2::VPCGatewayAttachment", | |
"Properties": { | |
"InternetGatewayId": { | |
"Ref": "InetGW" | |
}, | |
"VpcId": { | |
"Ref": "MainVPC" | |
} | |
}, | |
"DependsOn": [ | |
"MainVPC", | |
"InetGW" | |
] | |
}, | |
"PubAsub": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"CidrBlock": "10.0.1.0/24", | |
"AvailabilityZone": { | |
"Fn::Select": [ | |
"0", | |
{ | |
"Fn::GetAZs": { | |
"Ref": "AWS::Region" | |
} | |
} | |
] | |
}, | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
}, | |
{ | |
"Key" : "Name", | |
"Value" : "PubAsub" | |
}, { | |
"Key" : "Network", | |
"Value" : "Public" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"PubBsub": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"CidrBlock": "10.0.2.0/24", | |
"AvailabilityZone": { | |
"Fn::Select": [ | |
"1", | |
{ | |
"Fn::GetAZs": { | |
"Ref": "AWS::Region" | |
} | |
} | |
] | |
}, | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
}, | |
{ | |
"Key" : "Name", | |
"Value" : "PubBsub" | |
}, | |
{ | |
"Key" : "Network", | |
"Value" : "Public" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"PrivateAsub": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"CidrBlock": "10.0.11.0/24", | |
"AvailabilityZone": { | |
"Fn::Select": [ | |
"0", | |
{ | |
"Fn::GetAZs": { | |
"Ref": "AWS::Region" | |
} | |
} | |
] | |
}, | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
}, | |
{ | |
"Key" : "Name", | |
"Value" : "PrivateAsub" | |
}, { | |
"Key" : "Network", | |
"Value" : "Private" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"PrivateBsub": { | |
"Type": "AWS::EC2::Subnet", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"CidrBlock": "10.0.12.0/24", | |
"AvailabilityZone": { | |
"Fn::Select": [ | |
"1", | |
{ | |
"Fn::GetAZs": { | |
"Ref": "AWS::Region" | |
} | |
} | |
] | |
}, | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
}, | |
{ | |
"Key" : "Name", | |
"Value" : "PrivateBsub" | |
}, | |
{ | |
"Key" : "Network", | |
"Value" : "Private" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"InternetRouteTable": { | |
"Type": "AWS::EC2::RouteTable", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"Tags": [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"InternetRote": { | |
"Type": "AWS::EC2::Route", | |
"Properties": { | |
"RouteTableId": { | |
"Ref": "InternetRouteTable" | |
}, | |
"DestinationCidrBlock" : "0.0.0.0/0", | |
"GatewayId": { | |
"Ref": "InetGW" | |
} | |
}, | |
"DependsOn": [ | |
"AttachInetGW" | |
] | |
}, | |
"PubSubRouteTableAssociationA" : { | |
"Type" : "AWS::EC2::SubnetRouteTableAssociation", | |
"Properties" : { | |
"SubnetId" : { "Ref" : "PubAsub" }, | |
"RouteTableId" : { "Ref" : "InternetRouteTable" } | |
} | |
}, | |
"PubSubRouteTableAssociationB" : { | |
"Type" : "AWS::EC2::SubnetRouteTableAssociation", | |
"Properties" : { | |
"SubnetId" : { "Ref" : "PubBsub" }, | |
"RouteTableId" : { "Ref" : "InternetRouteTable" } | |
} | |
}, | |
"WebSecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"GroupDescription": "Allow access from HTTP and HTTPS traffic", | |
"SecurityGroupIngress": [ | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "80", | |
"ToPort": "80", | |
"CidrIp": "0.0.0.0/0" | |
}, | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "443", | |
"ToPort": "443", | |
"CidrIp": "0.0.0.0/0" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"SSHSecurityGroup": { | |
"Type": "AWS::EC2::SecurityGroup", | |
"Properties": { | |
"VpcId": { | |
"Ref": "MainVPC" | |
}, | |
"GroupDescription": "Allow access from SSH traffic", | |
"SecurityGroupIngress": [ | |
{ | |
"IpProtocol": "tcp", | |
"FromPort": "22", | |
"ToPort": "22", | |
"CidrIp": "0.0.0.0/0" | |
} | |
] | |
}, | |
"DependsOn": [ | |
"MainVPC" | |
] | |
}, | |
"WebServer1" : { | |
"Type" : "AWS::EC2::Instance", | |
"Properties" : { | |
"ImageId" : "ami-56d4ad31", | |
"InstanceType" : "t2.micro", | |
"KeyName" : { "Ref" : "KeyName" }, | |
"NetworkInterfaces": [ | |
{ | |
"AssociatePublicIpAddress": "true", | |
"DeviceIndex": "0", | |
"SubnetId" : { "Ref" : "PubAsub" }, | |
"GroupSet": [ | |
{ "Ref" : "SSHSecurityGroup" }, | |
{ "Ref" : "WebSecurityGroup" } | |
] | |
} | |
], | |
"BlockDeviceMappings" : [ | |
{ | |
"DeviceName" : "/dev/xvdb", | |
"Ebs" : { | |
"DeleteOnTermination": "true", | |
"VolumeType" : "gp2", | |
"Encrypted" : "false", | |
"VolumeSize" : "20" | |
} | |
} | |
], | |
"Tags" : [ | |
{ | |
"Key" : "Application", | |
"Value" : { "Ref" : "AWS::StackName"} | |
}, | |
{ | |
"Key" : "Name", | |
"Value" : "WebServer" | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment