{
  "AWSTemplateFormatVersion" : "2010-09-09",

  "Description" : "AWS Template to create a a VPC with one subnet",

  "Parameters" : {
   "ResourceName": {
        "Description" : "Resource name",
        "Type"        : "String"
    }
  },

  "Resources" : {
    "VPC" : {
      "Type" : "AWS::EC2::VPC",
      "Properties" : {
        "CidrBlock" : "172.20.0.0/16",
        "EnableDnsSupport" : true,
        "EnableDnsHostnames" : true,
        "Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ResourceName"} } ]
      }
    },

    "Subnet" : {
      "Type" : "AWS::EC2::Subnet",
      "Properties" : {
        "AvailabilityZone" : { "Fn::Select" : [ "0", { "Fn::GetAZs" : "" } ] },
        "VpcId" : { "Ref" : "VPC" },
        "CidrBlock" : "172.20.32.0/19",
	"MapPublicIpOnLaunch" : true,
        "Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ResourceName"} } ]
      }
    },

    "InternetGateway" : {
      "Type" : "AWS::EC2::InternetGateway",
      "Properties" : {
        "Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ResourceName"} } ]
      }
    },

    "AttachGateway" : {
       "Type" : "AWS::EC2::VPCGatewayAttachment",
       "Properties" : {
         "VpcId" : { "Ref" : "VPC" },
         "InternetGatewayId" : { "Ref" : "InternetGateway" }
       }
    },

   "RouteTable" : {
      "Type" : "AWS::EC2::RouteTable",
      "Properties" : {
        "VpcId" : {"Ref" : "VPC"},
        "Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ResourceName"} } ]
      }
    },

   "GatewayRoute" : {
      "Type" : "AWS::EC2::Route",
      "DependsOn" : ["InternetGateway", "AttachGateway"],
      "Properties" : {
       "RouteTableId" : { "Ref" : "RouteTable" },
       "DestinationCidrBlock" : "0.0.0.0/0",
       "GatewayId" : { "Ref" : "InternetGateway" }
     }
   }, 

   "SubnetRouteTableAssociation" : {
      "Type" : "AWS::EC2::SubnetRouteTableAssociation",
      "Properties" : {
        "SubnetId" : { "Ref" : "Subnet" },
        "RouteTableId" : { "Ref" : "RouteTable" }
      }
    },

   "sgnode": {
      "Type": "AWS::EC2::SecurityGroup",
      "DependsOn": "VPC",
      "Properties": {
        "GroupDescription": "vpc node sg",
        "VpcId": { "Ref": "VPC" },
        "Tags" : [ {"Key" : "Name", "Value" : { "Ref" : "ResourceName"} } ]
      }
    },

    "sgnodeingress0": {
      "Type": "AWS::EC2::SecurityGroupIngress",
      "DependsOn": "sgnode",
      "Properties": {
        "GroupId": { "Ref": "sgnode" },
        "IpProtocol": "-1",
        "FromPort": "0",
        "ToPort": "65535",
        "SourceSecurityGroupId": { "Ref": "sgnode" }
      }
    },

    "sgnodeingress1": {
      "Type": "AWS::EC2::SecurityGroupIngress",
      "DependsOn": "sgnode",
      "Properties": {
        "GroupId": { "Ref": "sgnode" },
        "IpProtocol": "tcp",
        "FromPort": "22",
        "ToPort": "22",
	"CidrIp": "0.0.0.0/0"
      }
    }
  },

  "Outputs" : {
    "VpcId" : {
      "Value" : { "Ref" : "VPC" },
      "Description" : "VPC ID"
    },

    "SubnetId" : {
      "Value" : { "Ref" : "Subnet" },
      "Description" : "Subnet ID"
    },

    "SgId" : {
      "Value" : { "Ref" : "sgnode" },
      "Description" : "Sg ID"
    }
  }
}
