Skip to content

Instantly share code, notes, and snippets.

@Ankit-Kulkarni
Last active October 10, 2018 13:02
Show Gist options
  • Select an option

  • Save Ankit-Kulkarni/7ca8c7ad06cdcd6cfd94c5a3e979eb92 to your computer and use it in GitHub Desktop.

Select an option

Save Ankit-Kulkarni/7ca8c7ad06cdcd6cfd94c5a3e979eb92 to your computer and use it in GitHub Desktop.
AWS cloudformation template to create single VPC, multiple subnets(public and private) with NAT,route tables,network acl's , elasticip for nat , internet gateway for vpc and configure rules for the subnets to talk to internet and talk via NAT(in case of private subnet) in multiple Avalibility zones, an EC2 instance with Elastic ip and install je…
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS cloudformation template to create single VPC, multiple subnets(public and private) with NAT,route tables,network acl's , elasticip for nat , internet gateway for vpc and configure rules for the subnets to talk to internet and talk via NAT(in case of private subnet) in multiple Avalibility zones, An EC2 instance with Elastic ip and install jenkins/nginx/ansible on it.",
"Parameters": {
"VpcCIDR": {
"Description": "Gives the vpc CIDR",
"Type": "String",
"Default": "10.11.0.0/16"
},
"AvailabilityZone1": {
"Description": "Primary Availability zone",
"Type": "AWS::EC2::AvailabilityZone::Name",
"Default": "us-east-1a"
},
"AvailabilityZone2": {
"Description": "Secondary Availability zone",
"Type": "AWS::EC2::AvailabilityZone::Name",
"Default": "us-east-1b"
},
"PublicSubnetCIDR1": {
"Description": "CIDR for AvailabilityZone 1 public subnet",
"Type": "String",
"Default": "10.11.1.0/24"
},
"PrivateSubnetCIDR1": {
"Description": "CIDR for AvailabilityZone 1 private subnet",
"Type": "String",
"Default": "10.11.2.0/24"
},
"PublicSubnetCIDR2": {
"Description": "CIDR for AvailabilityZone 2 public subnet",
"Type": "String",
"Default": "10.11.3.0/24"
},
"PublicSubnetCIDR3": {
"Description": "CIDR for AvailabilityZone 2 public subnet",
"Type": "String",
"Default": "10.11.5.0/24"
},
"PublicSubnetCIDR4": {
"Description": "CIDR for AvailabilityZone 2 public subnet",
"Type": "String",
"Default": "10.11.7.0/24"
},
"PrivateSubnetCIDR2": {
"Description": "CIDR for AvailabilityZone 1 private subnet",
"Type": "String",
"Default": "10.11.4.0/24"
},
"CreatePrivateSubnet1": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create private subnet in availiblity zone 1",
"Type": "String"
},
"CreatePublicSubnet2": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create public subnet 1 in availiblity zone 2",
"Type": "String"
},
"CreatePublicSubnet3": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create public subnet 2 in availiblity zone 1",
"Type": "String"
},
"CreatePublicSubnet4": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create public subnet 2 in availiblity zone 2",
"Type": "String"
},
"CreatePrivateSubnet2": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create private subnet in availiblity zone 2",
"Type": "String"
},
"CreateNAT1": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create NAT gateway for private subnet of availiblity zone 1",
"Type": "String"
},
"CreateNAT2": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "Create NAT gateway for private subnet of availiblity zone 2",
"Type": "String"
},
"InstanceType": {
"Description": "WebServer EC2 instance type",
"Type": "String",
"Default": "t2.nano",
"AllowedValues": [
"t1.micro",
"t2.nano",
"t2.micro",
"t2.small",
"t2.medium",
"t2.large",
"m1.small",
"m1.medium",
"m1.large",
"m1.xlarge",
"m2.xlarge",
"m2.2xlarge",
"m2.4xlarge",
"m3.medium",
"m3.large",
"m3.xlarge",
"m3.2xlarge",
"m4.large",
"m4.xlarge",
"m4.2xlarge",
"m4.4xlarge",
"m4.10xlarge",
"c1.medium",
"c1.xlarge",
"c3.large",
"c3.xlarge",
"c3.2xlarge",
"c3.4xlarge",
"c3.8xlarge",
"c4.large",
"c4.xlarge",
"c4.2xlarge",
"c4.4xlarge",
"c4.8xlarge",
"g2.2xlarge",
"g2.8xlarge",
"r3.large",
"r3.xlarge",
"r3.2xlarge",
"r3.4xlarge",
"r3.8xlarge",
"i2.xlarge",
"i2.2xlarge",
"i2.4xlarge",
"i2.8xlarge",
"d2.xlarge",
"d2.2xlarge",
"d2.4xlarge",
"d2.8xlarge",
"hi1.4xlarge",
"hs1.8xlarge",
"cr1.8xlarge",
"cc2.8xlarge",
"cg1.4xlarge"
],
"ConstraintDescription": "must be a valid EC2 instance type."
},
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription": "must be the name of an existing EC2 KeyPair."
},
"SSHLocation": {
"Description": " The IP address range that can be used to SSH to the EC2 instances",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
},
"Ec2RootVolumeSize": {
"Description": " Ec2 root volume size",
"Type": "String",
"Default": "30"
}
},
"Mappings": {
"AWSInstanceType2Arch": {
"t1.micro": {
"Arch": "HVM64"
},
"t2.nano": {
"Arch": "HVM64"
},
"t2.micro": {
"Arch": "HVM64"
},
"t2.small": {
"Arch": "HVM64"
},
"t2.medium": {
"Arch": "HVM64"
},
"t2.large": {
"Arch": "HVM64"
},
"m1.small": {
"Arch": "HVM64"
},
"m1.medium": {
"Arch": "HVM64"
},
"m1.large": {
"Arch": "HVM64"
},
"m1.xlarge": {
"Arch": "HVM64"
},
"m2.xlarge": {
"Arch": "HVM64"
},
"m2.2xlarge": {
"Arch": "HVM64"
},
"m2.4xlarge": {
"Arch": "HVM64"
},
"m3.medium": {
"Arch": "HVM64"
},
"m3.large": {
"Arch": "HVM64"
},
"m3.xlarge": {
"Arch": "HVM64"
},
"m3.2xlarge": {
"Arch": "HVM64"
},
"m4.large": {
"Arch": "HVM64"
},
"m4.xlarge": {
"Arch": "HVM64"
},
"m4.2xlarge": {
"Arch": "HVM64"
},
"m4.4xlarge": {
"Arch": "HVM64"
},
"m4.10xlarge": {
"Arch": "HVM64"
},
"c1.medium": {
"Arch": "HVM64"
},
"c1.xlarge": {
"Arch": "HVM64"
},
"c3.large": {
"Arch": "HVM64"
},
"c3.xlarge": {
"Arch": "HVM64"
},
"c3.2xlarge": {
"Arch": "HVM64"
},
"c3.4xlarge": {
"Arch": "HVM64"
},
"c3.8xlarge": {
"Arch": "HVM64"
},
"c4.large": {
"Arch": "HVM64"
},
"c4.xlarge": {
"Arch": "HVM64"
},
"c4.2xlarge": {
"Arch": "HVM64"
},
"c4.4xlarge": {
"Arch": "HVM64"
},
"c4.8xlarge": {
"Arch": "HVM64"
},
"g2.2xlarge": {
"Arch": "HVMG2"
},
"g2.8xlarge": {
"Arch": "HVMG2"
},
"r3.large": {
"Arch": "HVM64"
},
"r3.xlarge": {
"Arch": "HVM64"
},
"r3.2xlarge": {
"Arch": "HVM64"
},
"r3.4xlarge": {
"Arch": "HVM64"
},
"r3.8xlarge": {
"Arch": "HVM64"
},
"i2.xlarge": {
"Arch": "HVM64"
},
"i2.2xlarge": {
"Arch": "HVM64"
},
"i2.4xlarge": {
"Arch": "HVM64"
},
"i2.8xlarge": {
"Arch": "HVM64"
},
"d2.xlarge": {
"Arch": "HVM64"
},
"d2.2xlarge": {
"Arch": "HVM64"
},
"d2.4xlarge": {
"Arch": "HVM64"
},
"d2.8xlarge": {
"Arch": "HVM64"
},
"hi1.4xlarge": {
"Arch": "HVM64"
},
"hs1.8xlarge": {
"Arch": "HVM64"
},
"cr1.8xlarge": {
"Arch": "HVM64"
},
"cc2.8xlarge": {
"Arch": "HVM64"
}
},
"AWSRegionArch2AMI": {
"us-east-1": {
"HVM64": "ami-059eeca93cf09eebd",
"HVMG2": "ami-0a584ac55a7631c0c"
},
"us-west-2": {
"HVM64": "ami-a0cfeed8",
"HVMG2": "ami-0e09505bc235aa82d"
},
"us-west-1": {
"HVM64": "ami-0bdb828fd58c52235",
"HVMG2": "ami-066ee5fd4a9ef77f1"
},
"eu-west-1": {
"HVM64": "ami-047bb4163c506cd98",
"HVMG2": "ami-0a7c483d527806435"
},
"eu-west-2": {
"HVM64": "ami-f976839e",
"HVMG2": "NOT_SUPPORTED"
},
"eu-west-3": {
"HVM64": "ami-0ebc281c20e89ba4b",
"HVMG2": "NOT_SUPPORTED"
},
"eu-central-1": {
"HVM64": "ami-0233214e13e500f77",
"HVMG2": "ami-06223d46a6d0661c7"
},
"ap-northeast-1": {
"HVM64": "ami-06cd52961ce9f0d85",
"HVMG2": "ami-053cdd503598e4a9d"
},
"ap-northeast-2": {
"HVM64": "ami-0a10b2721688ce9d2",
"HVMG2": "NOT_SUPPORTED"
},
"ap-northeast-3": {
"HVM64": "ami-0d98120a9fb693f07",
"HVMG2": "NOT_SUPPORTED"
},
"ap-southeast-1": {
"HVM64": "ami-08569b978cc4dfa10",
"HVMG2": "ami-0be9df32ae9f92309"
},
"ap-southeast-2": {
"HVM64": "ami-09b42976632b27e9b",
"HVMG2": "ami-0a9ce9fecc3d1daf8"
},
"ap-south-1": {
"HVM64": "ami-0912f71e06545ad88",
"HVMG2": "ami-097b15e89dbdcfcf4"
},
"us-east-2": {
"HVM64": "ami-0b59bfac6be064b78",
"HVMG2": "NOT_SUPPORTED"
},
"ca-central-1": {
"HVM64": "ami-0b18956f",
"HVMG2": "NOT_SUPPORTED"
},
"sa-east-1": {
"HVM64": "ami-07b14488da8ea02a0",
"HVMG2": "NOT_SUPPORTED"
},
"cn-north-1": {
"HVM64": "ami-0a4eaf6c4454eda75",
"HVMG2": "NOT_SUPPORTED"
},
"cn-northwest-1": {
"HVM64": "ami-6b6a7d09",
"HVMG2": "NOT_SUPPORTED"
}
}
},
"Conditions": {
"CreatePrivateSubnet1": {
"Fn::Equals": [{
"Ref": "CreatePrivateSubnet1"
}, "true"]
},
"CreatePublicSubnet2": {
"Fn::Equals": [{
"Ref": "CreatePublicSubnet2"
}, "true"]
},
"CreatePublicSubnet3": {
"Fn::Equals": [{
"Ref": "CreatePublicSubnet3"
}, "true"]
},
"CreatePublicSubnet4": {
"Fn::Equals": [{
"Ref": "CreatePublicSubnet4"
}, "true"]
},
"CreatePrivateSubnet2": {
"Fn::Equals": [{
"Ref": "CreatePrivateSubnet2"
}, "true"]
},
"CreateNAT1": {
"Fn::Equals": [{
"Ref": "CreateNAT1"
}, "true"]
},
"CreateNAT2": {
"Fn::Equals": [{
"Ref": "CreateNAT2"
}, "true"]
}
},
"Resources": {
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "200356c9-1d6d-45ae-a025-24fe7efac02c"
}
}
},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"InternetGatewayId": {
"Ref": "InternetGateway"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "cc81059e-8206-4178-8417-1ffd1d369f7e"
}
}
},
"NetworkAcl": {
"Type": "AWS::EC2::NetworkAcl",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "84e109b9-eefc-4ded-8cd0-e8dcf5257406"
}
}
},
"InboundNetworkAclEntry": {
"Type": "AWS::EC2::NetworkAclEntry",
"Properties": {
"NetworkAclId": {
"Ref": "NetworkAcl"
},
"RuleNumber": "100",
"Protocol": "-1",
"RuleAction": "allow",
"Egress": "false",
"CidrBlock": "0.0.0.0/0",
"PortRange": {
"From": "-1",
"To": "-1"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "1dc15672-d938-4f2c-b224-191fb84f53b2"
}
}
},
"OutBoundNetworkAclEntry": {
"Type": "AWS::EC2::NetworkAclEntry",
"Properties": {
"NetworkAclId": {
"Ref": "NetworkAcl"
},
"RuleNumber": "102",
"Protocol": "-1",
"RuleAction": "allow",
"Egress": "true",
"CidrBlock": "0.0.0.0/0",
"PortRange": {
"From": "-1",
"To": "-1"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c47472f5-0af8-4abb-b64a-80819a06ae11"
}
}
},
"Vpc1": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref": "VpcCIDR"
},
"Tags": [{
"Key": "createdBy",
"Value": "cloudformation"
}]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
}
}
},
"PublicSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PublicSubnetCIDR1"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePubS1": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route1": {
"Type": "AWS::EC2::Route",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePubS1"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation1": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet1"
},
"RouteTableId": {
"Ref": "RouteTablePubS1"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation1": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet1"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"PublicSubnet2": {
"Type": "AWS::EC2::Subnet",
"Condition": "CreatePublicSubnet2",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PublicSubnetCIDR2"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone2"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePubS2": {
"Type": "AWS::EC2::RouteTable",
"Condition": "CreatePublicSubnet2",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route2": {
"Type": "AWS::EC2::Route",
"Condition": "CreatePublicSubnet2",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePubS2"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation2": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Condition": "CreatePublicSubnet2",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet2"
},
"RouteTableId": {
"Ref": "RouteTablePubS2"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation2": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Condition": "CreatePublicSubnet2",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet2"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"PublicSubnet3": {
"Type": "AWS::EC2::Subnet",
"Condition": "CreatePublicSubnet3",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PublicSubnetCIDR3"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePub10": {
"Type": "AWS::EC2::RouteTable",
"Condition": "CreatePublicSubnet3",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route10": {
"Type": "AWS::EC2::Route",
"Condition": "CreatePublicSubnet3",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePub10"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation10": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Condition": "CreatePublicSubnet3",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet3"
},
"RouteTableId": {
"Ref": "RouteTablePub10"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation10": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Condition": "CreatePublicSubnet3",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet3"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"PublicSubnet4": {
"Type": "AWS::EC2::Subnet",
"Condition": "CreatePublicSubnet4",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PublicSubnetCIDR4"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone2"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePub11": {
"Type": "AWS::EC2::RouteTable",
"Condition": "CreatePublicSubnet4",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route11": {
"Type": "AWS::EC2::Route",
"Condition": "CreatePublicSubnet4",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePub11"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation11": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Condition": "CreatePublicSubnet4",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet4"
},
"RouteTableId": {
"Ref": "RouteTablePub11"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation11": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Condition": "CreatePublicSubnet4",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet4"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"PrivateSubnet1": {
"Type": "AWS::EC2::Subnet",
"Condition": "CreatePrivateSubnet1",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PrivateSubnetCIDR1"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePrivS1": {
"Type": "AWS::EC2::RouteTable",
"Condition": "CreatePrivateSubnet1",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route3": {
"Type": "AWS::EC2::Route",
"Condition": "CreatePrivateSubnet1",
"DependsOn": "NATGateway1",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePrivS1"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "NATGateway1"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation3": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Condition": "CreatePrivateSubnet1",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet1"
},
"RouteTableId": {
"Ref": "RouteTablePrivS1"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation3": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Condition": "CreatePrivateSubnet1",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet1"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"PrivateSubnet2": {
"Type": "AWS::EC2::Subnet",
"Condition": "CreatePrivateSubnet2",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"CidrBlock": {
"Ref": "PrivateSubnetCIDR2"
},
"AvailabilityZone": {
"Ref": "AvailabilityZone2"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
}
}
},
"RouteTablePrivS2": {
"Type": "AWS::EC2::RouteTable",
"Condition": "CreatePrivateSubnet2",
"Properties": {
"VpcId": {
"Ref": "Vpc1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
}
}
},
"Route4": {
"Type": "AWS::EC2::Route",
"Condition": "CreatePrivateSubnet2",
"DependsOn": "NATGateway2",
"Properties": {
"RouteTableId": {
"Ref": "RouteTablePrivS2"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "NATGateway2"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "af10b723-a01b-4daf-b76b-90f7edbf5a4f"
}
}
},
"SubnetRouteTableAssociation4": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Condition": "CreatePrivateSubnet2",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet2"
},
"RouteTableId": {
"Ref": "RouteTablePrivS2"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "c97c162a-c229-43c3-b347-2034cdb74f0b"
}
}
},
"SubnetNetworkAclAssociation4": {
"Type": "AWS::EC2::SubnetNetworkAclAssociation",
"Condition": "CreatePrivateSubnet2",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet2"
},
"NetworkAclId": {
"Ref": "NetworkAcl"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "ca96d204-696f-415d-bf3b-304e22637c21"
}
}
},
"EIPAddress1": {
"Type": "AWS::EC2::EIP",
"Condition": "CreateNAT1",
"DependsOn": "Vpc1",
"Properties": {
"Domain": "vpc"
}
},
"NATGateway1": {
"Type": "AWS::EC2::NatGateway",
"Condition": "CreateNAT1",
"DependsOn": "AttachGateway",
"Properties": {
"AllocationId": {
"Fn::GetAtt": ["EIPAddress1", "AllocationId"]
},
"SubnetId": {
"Ref": "PublicSubnet1"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
}
},
"EIPAddress2": {
"Type": "AWS::EC2::EIP",
"Condition": "CreateNAT2",
"DependsOn": "Vpc1",
"Properties": {
"Domain": "vpc"
}
},
"NATGateway2": {
"Type": "AWS::EC2::NatGateway",
"Condition": "CreateNAT2",
"DependsOn": "AttachGateway",
"Properties": {
"AllocationId": {
"Fn::GetAtt": ["EIPAddress2", "AllocationId"]
},
"SubnetId": {
"Ref": "PublicSubnet2"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "createdBy",
"Value": "cloudformation"
}
]
}
},
"EIPAddressVM1": {
"Type": "AWS::EC2::EIP",
"DependsOn": "EC2Instance1",
"Properties": {
"Domain": "vpc",
"InstanceId": {
"Ref": "EC2Instance1"
}
}
},
"EC2Instance1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"InstanceType": {
"Ref": "InstanceType"
},
"SecurityGroupIds": [{
"Fn::GetAtt": ["InstanceSecurityGroup1", "GroupId"]
}],
"SubnetId": {
"Ref": "PublicSubnet1"
},
"KeyName": {
"Ref": "KeyName"
},
"BlockDeviceMappings": [{
"DeviceName": "/dev/sda1",
"Ebs": {
"DeleteOnTermination": "true",
"VolumeSize": {
"Ref": "Ec2RootVolumeSize"
}
}
}],
"ImageId": {
"Fn::FindInMap": [
"AWSRegionArch2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Arch",
{
"Ref": "InstanceType"
},
"Arch"
]
}
]
},
"UserData": {
"Fn::Base64": {
"Fn::Join": ["", [
"#!/bin/bash \n",
"### This script is passed as userdata for an aws instance and would install \n",
"### jenkins, nginx and ansible on it. \n",
"## scripts output is logged at - /var/log/user-data.log \n",
" \n",
"## author: @ankitkul1890 \n",
" \n",
"set -x \n",
"exec > /var/log/user-data.log 2>&1 \n",
" \n",
"# add keys are repos \n",
"apt-add-repository ppa:ansible/ansible -y \n",
"add-apt-repository ppa:webupd8team/java -y \n",
"wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - \n",
"sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' \n",
"apt-get update \n",
"apt-get install -y software-properties-common nginx ansible \n",
" \n",
"# install jenkins now \n",
"# Ref- https://jenkins.io/doc/book/installing/#debian-ubuntu \n",
"apt-get install openjdk-8-jre-headless -y \n",
"java -version \n",
"apt-get install jenkins -y \n",
"# now configuring nginx file for jenkins \n",
"curl -s -o /etc/nginx/conf.d/jenkins.conf https://gist.githubusercontent.com/Ankit-Kulkarni/93b4ff8d90d14d8b0d8e31f93097ea61/raw/332e720794ebef2ac8567b9fdd9f6e628324e4d1/jenkins-nginx.conf \n",
"InstanceIP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4` \n",
"sed -i \"s/InstancePublicIp/$InstanceIP/g\" /etc/nginx/conf.d/jenkins.conf \n",
"systemctl reload nginx.service \n"
]]
}
}
}
},
"InstanceSecurityGroup1": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH access via port 22",
"SecurityGroupIngress": [{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": {
"Ref": "SSHLocation"
}
},
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "443",
"ToPort": "443",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "Vpc1"
}
}
}
},
"Outputs": {
"InstanceId": {
"Description": "InstanceId of the newly created EC2 instance",
"Value": {
"Ref": "EC2Instance1"
}
},
"AZ": {
"Description": "Availability Zone of the newly created EC2 instance",
"Value": {
"Fn::GetAtt": [
"EC2Instance1",
"AvailabilityZone"
]
}
},
"PublicDNS": {
"Description": "Public DNSName of the newly created EC2 instance",
"Value": {
"Fn::GetAtt": [
"EC2Instance1",
"PublicDnsName"
]
}
},
"IPAttached": {
"Description": "IP attached to EC2 instance",
"Value": {
"Fn::GetAtt": [
"EC2Instance1",
"PublicIp"
]
}
},
"JenkinsUrl": {
"Description": "URL for newly created Jenkins",
"Value": {
"Fn::Join": ["", ["http://", {
"Fn::GetAtt": ["EC2Instance1", "PublicIp"]
}]]
}
},
"VPCCidr": {
"Value": {
"Fn::Join": [
" ", [
"vpc cidr block is ",
{
"Fn::GetAtt": [
"Vpc1",
"CidrBlock"
]
}
]
]
},
"Description": "CIDR range of newly created VPC "
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"200356c9-1d6d-45ae-a025-24fe7efac02c": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 900,
"y": 90
},
"z": 1,
"embeds": []
},
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba": {
"size": {
"width": 780,
"height": 780
},
"position": {
"x": 60,
"y": 90
},
"z": 1,
"embeds": [
"cf312194-ef0b-46ae-b9af-69f426cb9e49",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"e18aa9aa-98b9-4c64-bab1-845a594350b6",
"ef30b7de-a329-445b-9761-6465d2eaabc8"
]
},
"cf312194-ef0b-46ae-b9af-69f426cb9e49": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 570,
"y": 150
},
"z": 2,
"parent": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"embeds": [],
"iscontainedinside": [
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
]
},
"84e109b9-eefc-4ded-8cd0-e8dcf5257406": {
"size": {
"width": 420,
"height": 330
},
"position": {
"x": 90,
"y": 150
},
"z": 2,
"parent": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"embeds": [
"fbc08a1d-e87e-499c-8dd3-925e3d3b0955",
"c47472f5-0af8-4abb-b64a-80819a06ae11",
"dd51f13b-d9de-467d-8d45-22e8015dae0d",
"6647e38a-dd88-43c9-8b0a-de9f4cb4fcde",
"1dc15672-d938-4f2c-b224-191fb84f53b2"
],
"iscontainedinside": [
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
]
},
"8bf6defe-f0d2-40c9-9ee1-d12b18b2e720": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 120,
"y": 210
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"fbc08a1d-e87e-499c-8dd3-925e3d3b0955": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 240,
"y": 210
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"c47472f5-0af8-4abb-b64a-80819a06ae11": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 120,
"y": 330
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"dd51f13b-d9de-467d-8d45-22e8015dae0d": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 240,
"y": 330
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"6647e38a-dd88-43c9-8b0a-de9f4cb4fcde": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 360,
"y": 210
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"1dc15672-d938-4f2c-b224-191fb84f53b2": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 360,
"y": 330
},
"z": 3,
"parent": "84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"embeds": [],
"iscontainedinside": [
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406",
"84e109b9-eefc-4ded-8cd0-e8dcf5257406"
]
},
"e18aa9aa-98b9-4c64-bab1-845a594350b6": {
"size": {
"width": 240,
"height": 240
},
"position": {
"x": 390,
"y": 540
},
"z": 2,
"parent": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"embeds": [
"af10b723-a01b-4daf-b76b-90f7edbf5a4f"
],
"iscontainedinside": [
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
]
},
"cc81059e-8206-4178-8417-1ffd1d369f7e": {
"source": {
"id": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
},
"target": {
"id": "200356c9-1d6d-45ae-a025-24fe7efac02c"
},
"z": 1
},
"af10b723-a01b-4daf-b76b-90f7edbf5a4f": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 420,
"y": 600
},
"z": 3,
"parent": "e18aa9aa-98b9-4c64-bab1-845a594350b6",
"embeds": [],
"isassociatedwith": [
"200356c9-1d6d-45ae-a025-24fe7efac02c"
],
"iscontainedinside": [
"e18aa9aa-98b9-4c64-bab1-845a594350b6",
"e18aa9aa-98b9-4c64-bab1-845a594350b6",
"e18aa9aa-98b9-4c64-bab1-845a594350b6",
"e18aa9aa-98b9-4c64-bab1-845a594350b6"
],
"dependson": [
"cc81059e-8206-4178-8417-1ffd1d369f7e"
]
},
"ef30b7de-a329-445b-9761-6465d2eaabc8": {
"size": {
"width": 240,
"height": 240
},
"position": {
"x": 90,
"y": 540
},
"z": 2,
"parent": "1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"embeds": [
"a89d0de1-370e-4d3b-aaa5-3d48c3cf9afc"
],
"iscontainedinside": [
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba",
"1d419f55-fa77-463e-baaf-b9e3ba6b38ba"
]
},
"a89d0de1-370e-4d3b-aaa5-3d48c3cf9afc": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 120,
"y": 600
},
"z": 3,
"parent": "ef30b7de-a329-445b-9761-6465d2eaabc8",
"embeds": [],
"iscontainedinside": [
"ef30b7de-a329-445b-9761-6465d2eaabc8",
"ef30b7de-a329-445b-9761-6465d2eaabc8",
"ef30b7de-a329-445b-9761-6465d2eaabc8",
"ef30b7de-a329-445b-9761-6465d2eaabc8"
],
"dependson": [
"cc81059e-8206-4178-8417-1ffd1d369f7e"
]
},
"958f5285-a46e-4aa9-918a-712c1296b546": {
"size": {
"width": 60,
"height": 60
},
"position": {
"x": 900,
"y": 210
},
"z": 1,
"embeds": [],
"isassociatedwith": [
"a89d0de1-370e-4d3b-aaa5-3d48c3cf9afc"
],
"dependson": [
"cc81059e-8206-4178-8417-1ffd1d369f7e"
]
},
"ca96d204-696f-415d-bf3b-304e22637c21": {
"source": {
"id": "84e109b9-eefc-4ded-8cd0-e8dcf5257406"
},
"target": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
},
"z": 2
},
"c97c162a-c229-43c3-b347-2034cdb74f0b": {
"source": {
"id": "e18aa9aa-98b9-4c64-bab1-845a594350b6"
},
"target": {
"id": "ef30b7de-a329-445b-9761-6465d2eaabc8"
},
"z": 2
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment