Cloudformation Template For a Simple VPC

This template will create a VPC in the Oregon Region.  The VPC will have 6 subnets, 3 public and 3 private.  It also creates a docker security group.  On launch it will ask you for the Name of your VPC and you can fill in the CIDR blocks for each subnet.  This is meant to be an example.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "VPCName": {
      "Description": "The name of this VPC. Keep it short. It will be prefixed to subnets and Security Group Names.",
      "Type": "String",
      "MinLength": "1",
      "MaxLength": "64",
      "AllowedPattern": "[a-zA-Z][a-zA-Z0-9-]*",
      "ConstraintDescription": "must begin with a letter and contain only alphanumeric characters and a dash."
    },
    "CIDRVPC": {
      "Description": "CIDR for VPC",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.0.0/16",
      "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."
    },
    "CIDRPubA": {
      "Description": "CIDR for PubA Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.1.0/24",
      "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."
    },
    "CIDRPubB": {
      "Description": "CIDR for PubB Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.2.0/24",
      "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."
    },
    "CIDRPubC": {
      "Description": "CIDR for PubC Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.3.0/24",
      "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."
    },
    "CIDRPrivA": {
      "Description": "CIDR for PrivA Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.4.0/24",
      "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."
    },
    "CIDRPrivB": {
      "Description": "CIDR for PrivB Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.5.0/24",
      "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."
    },
    "CIDRPrivC": {
      "Description": "CIDR for PrivC Subnet",
      "Type": "String",
      "MinLength": "9",
      "MaxLength": "18",
      "Default": "10.0.6.0/24",
      "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."
    }
  },
  "Resources": {
    "myVPC": {
      "Type": "AWS::EC2::VPC",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRVPC"
        },
        "InstanceTenancy": "default",
        "EnableDnsSupport": "true",
        "EnableDnsHostnames": "true",
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Ref": "VPCName"
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "df930d11-1853-4cdb-ab96-8f7e3fb33f55"
        }
      }
    },
    "subnetdfb76387": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPubA"
        },
        "AvailabilityZone": "us-west-2a",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PubA"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "1bec0779-5f7d-4d6f-af08-42ce74b36df6"
        }
      }
    },
    "subnetb01cbde8": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPubC"
        },
        "AvailabilityZone": "us-west-2c",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PubC"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "85f3d5bc-8a01-42f3-a87c-3cb1ce2deedd"
        }
      }
    },
    "subnet7adf9b1e": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPubB"
        },
        "AvailabilityZone": "us-west-2b",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PubB"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "fa6a4a95-fe6b-470d-98a8-531b66eed9bb"
        }
      }
    },
    "subnet781fbe20": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPrivC"
        },
        "AvailabilityZone": "us-west-2c",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PrivC"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "b1f95ef3-775a-4448-9808-d6dbb626016f"
        }
      }
    },
    "subnet8023bff6": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPrivA"
        },
        "AvailabilityZone": "us-west-2a",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PrivA"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "915c955e-8c41-4143-ba07-c1f62fd8d502"
        }
      }
    },
    "subnete3df9b87": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": {
          "Ref": "CIDRPrivB"
        },
        "AvailabilityZone": "us-west-2b",
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-PrivB"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "511adbf2-b989-4a3d-9046-67757cda0b53"
        }
      }
    },
    "igwee85708a": {
      "Type": "AWS::EC2::InternetGateway",
      "Properties": {
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-igw"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "6875b37e-487e-42b8-99f2-da9223c6f582"
        }
      }
    },
    "dopt19f4197d": {
      "Type": "AWS::EC2::DHCPOptions",
      "Properties": {
        "Tags": [
          {
            "Key": "Name",
            "Value": "dopt-ddns-lambda"
          }
        ],
        "DomainName": "nxt.panosoft.com",
        "DomainNameServers": [
          "AmazonProvidedDNS"
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "6abf5033-1687-4fac-b239-76787120ce85"
        }
      }
    },
    "sgDocker": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "GroupDescription": {
          "Fn::Join": [
            "",
            [
              {
                "Ref": "VPCName"
              },
              "-Docker"
            ]
          ]
        },
        "VpcId": {
          "Ref": "myVPC"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": {
              "Fn::Join": [
                "",
                [
                  {
                    "Ref": "VPCName"
                  },
                  "-Docker"
                ]
              ]
            }
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "22ba5afd-d475-4a7e-9836-e6387b6bdc4e"
        }
      }
    },

    "gw1": {
      "Type": "AWS::EC2::VPCGatewayAttachment",
      "Properties": {
        "VpcId": {
          "Ref": "myVPC"
        },
        "InternetGatewayId": {
          "Ref": "igwee85708a"
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "8b5e07b6-edfc-4b8f-afa1-afc4cc495746"
        }
      }
    },
    "dchpassoc1": {
      "Type": "AWS::EC2::VPCDHCPOptionsAssociation",
      "Properties": {
        "VpcId": {
          "Ref": "myVPC"
        },
        "DhcpOptionsId": {
          "Ref": "dopt19f4197d"
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "4ca071fb-808a-4814-b76e-b90d8211dca5"
        }
      }
    },
    "ingress1": {
      "Type": "AWS::EC2::SecurityGroupIngress",
      "Properties": {
        "GroupId": {
          "Ref": "sgDocker"
        },
        "IpProtocol": "tcp",
        "FromPort": "22",
        "ToPort": "22",
        "CidrIp": "0.0.0.0/0"
      }
    }
  },
  "Description": "",
  "Metadata": {
    "AWS::CloudFormation::Designer": {
      "38a04af1-7bb2-498a-b2d2-af6fc2342ad2": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 810,
          "y": 560
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "00124c64-42c5-4a85-b7f2-4148d7e7f01c": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 810,
          "y": 210
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "44bb3fb6-4fbc-469d-88b4-47c3b08ea26a": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 810,
          "y": 330
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "22ba5afd-d475-4a7e-9836-e6387b6bdc4e": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 810,
          "y": 450
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "6abf5033-1687-4fac-b239-76787120ce85": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 1080,
          "y": 570
        },
        "z": 1,
        "embeds": []
      },
      "6875b37e-487e-42b8-99f2-da9223c6f582": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 1080,
          "y": 690
        },
        "z": 1,
        "embeds": []
      },
      "df930d11-1853-4cdb-ab96-8f7e3fb33f55": {
        "size": {
          "width": 960,
          "height": 960
        },
        "position": {
          "x": 60,
          "y": 90
        },
        "z": 1,
        "embeds": [
          "38a04af1-7bb2-498a-b2d2-af6fc2342ad2",
          "00124c64-42c5-4a85-b7f2-4148d7e7f01c",
          "44bb3fb6-4fbc-469d-88b4-47c3b08ea26a",
          "22ba5afd-d475-4a7e-9836-e6387b6bdc4e",
          "511adbf2-b989-4a3d-9046-67757cda0b53",
          "915c955e-8c41-4143-ba07-c1f62fd8d502",
          "b1f95ef3-775a-4448-9808-d6dbb626016f",
          "fa6a4a95-fe6b-470d-98a8-531b66eed9bb",
          "85f3d5bc-8a01-42f3-a87c-3cb1ce2deedd",
          "1bec0779-5f7d-4d6f-af08-42ce74b36df6"
        ]
      },
      "4ca071fb-808a-4814-b76e-b90d8211dca5": {
        "source": {
          "id": "6abf5033-1687-4fac-b239-76787120ce85"
        },
        "target": {
          "id": "df930d11-1853-4cdb-ab96-8f7e3fb33f55"
        },
        "z": 1
      },
      "8b5e07b6-edfc-4b8f-afa1-afc4cc495746": {
        "source": {
          "id": "6875b37e-487e-42b8-99f2-da9223c6f582"
        },
        "target": {
          "id": "df930d11-1853-4cdb-ab96-8f7e3fb33f55"
        },
        "z": 1
      },
      "181abe75-98b6-4567-abaf-cee5f5f498d2": {
        "size": {
          "width": 60,
          "height": 60
        },
        "position": {
          "x": 420,
          "y": 510
        },
        "z": 3,
        "parent": "7bf0af2d-3a8f-4120-89bd-1578c54ce37e",
        "embeds": []
      },
      "511adbf2-b989-4a3d-9046-67757cda0b53": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 140,
          "y": 360
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "915c955e-8c41-4143-ba07-c1f62fd8d502": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 320,
          "y": 360
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "b1f95ef3-775a-4448-9808-d6dbb626016f": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 490,
          "y": 360
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "fa6a4a95-fe6b-470d-98a8-531b66eed9bb": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 310,
          "y": 170
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "85f3d5bc-8a01-42f3-a87c-3cb1ce2deedd": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 480,
          "y": 180
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      },
      "1bec0779-5f7d-4d6f-af08-42ce74b36df6": {
        "size": {
          "width": 150,
          "height": 150
        },
        "position": {
          "x": 140,
          "y": 170
        },
        "z": 2,
        "parent": "df930d11-1853-4cdb-ab96-8f7e3fb33f55",
        "embeds": []
      }
    }
  }
}
Example Template

 

Follow by Email
Facebook
Google+
http://cloudlady911.com/index.php/2016/08/04/cloudformation-template-for-a-simple-vpc/
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *