Wednesday, 12 June 2019

AWS Account and VPC pattern

AWS is very flexible and I have the following patterns for AWS accounts and VPCs:

Accounts:

VPCs come in following T-shirt sizes:
Micro: /23 - 32/subnet
Small: /22 - 64/subnet
Medium: /21 - 128/subnet
Large: /20 - 256/subnet
XLarge: /19 - 512/subnet
*Please note: AWS reserves  five IP addresses per subnet

Below displays Large VPC size:


CloudFormation template, still to be done:
  • add parameter section
  • wherever VPC/subnet CIDR is hardcoded change to input parameter:
      • Old:      "CidrBlock": "10.22.2.0/24"
      • New:     "CidrBlock": { "Ref": "web1CIDR" }
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "vpc0a20ebcd5ad0afcc3": {
      "Type": "AWS::EC2::VPC",
      "Properties": {
        "CidrBlock": "10.22.0.0/20",
        "InstanceTenancy": "default",
        "EnableDnsSupport": "true",
        "EnableDnsHostnames": "false",
        "Tags": [
          {
            "Key": "Name",
            "Value": "SampleVPC"
          }
        ]
      }
    },
    "subnet08211208971298906": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.2.0/24",
        "AvailabilityZone": "ap-southeast-2a",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Web-1"
          }
        ]
      }
    },
    "subnet0e0ed5fb7f7c29273": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.12.0/24",
        "AvailabilityZone": "ap-southeast-2c",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Web-3"
          }
        ]
      }
    },
    "subnet0e57ed3564c6ee0b7": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.10.0/24",
        "AvailabilityZone": "ap-southeast-2c",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Public-3"
          }
        ]
      }
    },
    "subnet0e62c34a812b74226": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.0.0/24",
        "AvailabilityZone": "ap-southeast-2a",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Public-1"
          }
        ]
      }
    },
    "subnet0453eee2fa31e4b2e": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.8.0/24",
        "AvailabilityZone": "ap-southeast-2b",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "App-2"
          }
        ]
      }
    },
    "subnet0b0d8faf6e6beae2d": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.1.0/24",
        "AvailabilityZone": "ap-southeast-2a",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "NAT-1"
          }
        ]
      }
    },
    "subnet0f2da790711ffbb3b": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.5.0/24",
        "AvailabilityZone": "ap-southeast-2b",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Public-2"
          }
        ]
      }
    },
    "subnet0f88525d49526c302": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.13.0/24",
        "AvailabilityZone": "ap-southeast-2c",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "App-3"
          }
        ]
      }
    },
    "subnet0a234a67484d465ac": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.14.0/24",
        "AvailabilityZone": "ap-southeast-2c",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Data-3"
          }
        ]
      }
    },
    "subnet0763e658bc3536b59": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.9.0/24",
        "AvailabilityZone": "ap-southeast-2b",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Data-2"
          }
        ]
      }
    },
    "subnet09a772953c709d0a6": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.6.0/24",
        "AvailabilityZone": "ap-southeast-2b",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "NAT-2"
          }
        ]
      }
    },
    "subnet07a3ad9ebce841b87": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.4.0/24",
        "AvailabilityZone": "ap-southeast-2a",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Data-1"
          }
        ]
      }
    },
    "subnet0f4b780fdca433da5": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.7.0/24",
        "AvailabilityZone": "ap-southeast-2b",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "Web-2"
          }
        ]
      }
    },
    "subnet05e6fe319d522ec7e": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.3.0/24",
        "AvailabilityZone": "ap-southeast-2a",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "App-1"
          }
        ]
      }
    },
    "subnet0737753cb795b3dc6": {
      "Type": "AWS::EC2::Subnet",
      "Properties": {
        "CidrBlock": "10.22.11.0/24",
        "AvailabilityZone": "ap-southeast-2c",
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "NAT-3"
          }
        ]
      }
    },
    "igw0356f970a2bc6cc06": {
      "Type": "AWS::EC2::InternetGateway",
      "Properties": {
        "Tags": [
          {
            "Key": "Name",
            "Value": "ZIGW"
          }
        ]
      }
    },
    "doptb2f3b2d5": {
      "Type": "AWS::EC2::DHCPOptions",
      "Properties": {
        "DomainName": "ap-southeast-2.compute.internal",
        "DomainNameServers": [
          "AmazonProvidedDNS"
        ]
      }
    },
    "acl0046ab3d9eaec62da": {
      "Type": "AWS::EC2::NetworkAcl",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        }
      }
    },
    "rtb07d6510351805bf28": {
      "Type": "AWS::EC2::RouteTable",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "ZVPC-AZ2"
          }
        ]
      }
    },
    "rtb03d3594b759f0d423": {
      "Type": "AWS::EC2::RouteTable",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "ZVPC-AZ3"
          }
        ]
      }
    },
    "rtb017a472d2d8d61ce5": {
      "Type": "AWS::EC2::RouteTable",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "ZVPC-Public"
          }
        ]
      }
    },
    "rtb0d46463a6ab971e4f": {
      "Type": "AWS::EC2::RouteTable",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "Tags": [
          {
            "Key": "Name",
            "Value": "ZVPC-AZ1"
          }
        ]
      }
    },
    "rtb0944f43d86c016a02": {
      "Type": "AWS::EC2::RouteTable",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        }
      }
    },
    "acl1": {
      "Type": "AWS::EC2::NetworkAclEntry",
      "Properties": {
        "CidrBlock": "0.0.0.0/0",
        "Egress": "true",
        "Protocol": "-1",
        "RuleAction": "allow",
        "RuleNumber": "100",
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        }
      }
    },
    "acl2": {
      "Type": "AWS::EC2::NetworkAclEntry",
      "Properties": {
        "CidrBlock": "0.0.0.0/0",
        "Protocol": "-1",
        "RuleAction": "allow",
        "RuleNumber": "100",
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        }
      }
    },
    "subnetacl1": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0453eee2fa31e4b2e"
        }
      }
    },
    "subnetacl2": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet09a772953c709d0a6"
        }
      }
    },
    "subnetacl3": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0737753cb795b3dc6"
        }
      }
    },
    "subnetacl4": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0a234a67484d465ac"
        }
      }
    },
    "subnetacl5": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0f4b780fdca433da5"
        }
      }
    },
    "subnetacl6": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet08211208971298906"
        }
      }
    },
    "subnetacl7": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet07a3ad9ebce841b87"
        }
      }
    },
    "subnetacl8": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0b0d8faf6e6beae2d"
        }
      }
    },
    "subnetacl9": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet05e6fe319d522ec7e"
        }
      }
    },
    "subnetacl10": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0f2da790711ffbb3b"
        }
      }
    },
    "subnetacl11": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0e57ed3564c6ee0b7"
        }
      }
    },
    "subnetacl12": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0763e658bc3536b59"
        }
      }
    },
    "subnetacl13": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0e62c34a812b74226"
        }
      }
    },
    "subnetacl14": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0f88525d49526c302"
        }
      }
    },
    "subnetacl15": {
      "Type": "AWS::EC2::SubnetNetworkAclAssociation",
      "Properties": {
        "NetworkAclId": {
          "Ref": "acl0046ab3d9eaec62da"
        },
        "SubnetId": {
          "Ref": "subnet0e0ed5fb7f7c29273"
        }
      }
    },
    "gw1": {
      "Type": "AWS::EC2::VPCGatewayAttachment",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "InternetGatewayId": {
          "Ref": "igw0356f970a2bc6cc06"
        }
      }
    },
    "subnetroute1": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb07d6510351805bf28"
        },
        "SubnetId": {
          "Ref": "subnet09a772953c709d0a6"
        }
      }
    },
    "subnetroute2": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb03d3594b759f0d423"
        },
        "SubnetId": {
          "Ref": "subnet0737753cb795b3dc6"
        }
      }
    },
    "subnetroute3": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb017a472d2d8d61ce5"
        },
        "SubnetId": {
          "Ref": "subnet0e62c34a812b74226"
        }
      }
    },
    "subnetroute4": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb017a472d2d8d61ce5"
        },
        "SubnetId": {
          "Ref": "subnet0f2da790711ffbb3b"
        }
      }
    },
    "subnetroute5": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb017a472d2d8d61ce5"
        },
        "SubnetId": {
          "Ref": "subnet0e57ed3564c6ee0b7"
        }
      }
    },
    "subnetroute6": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0d46463a6ab971e4f"
        },
        "SubnetId": {
          "Ref": "subnet0b0d8faf6e6beae2d"
        }
      }
    },
    "subnetroute7": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0453eee2fa31e4b2e"
        }
      }
    },
    "subnetroute8": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0e0ed5fb7f7c29273"
        }
      }
    },
    "subnetroute9": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0a234a67484d465ac"
        }
      }
    },
    "subnetroute10": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet08211208971298906"
        }
      }
    },
    "subnetroute11": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet05e6fe319d522ec7e"
        }
      }
    },
    "subnetroute12": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0763e658bc3536b59"
        }
      }
    },
    "subnetroute13": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0f4b780fdca433da5"
        }
      }
    },
    "subnetroute14": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet07a3ad9ebce841b87"
        }
      }
    },
    "subnetroute16": {
      "Type": "AWS::EC2::SubnetRouteTableAssociation",
      "Properties": {
        "RouteTableId": {
          "Ref": "rtb0944f43d86c016a02"
        },
        "SubnetId": {
          "Ref": "subnet0f88525d49526c302"
        }
      }
    },
    "route1": {
      "Type": "AWS::EC2::Route",
      "Properties": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "RouteTableId": {
          "Ref": "rtb07d6510351805bf28"
        }
      }
    },
    "route2": {
      "Type": "AWS::EC2::Route",
      "Properties": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "RouteTableId": {
          "Ref": "rtb03d3594b759f0d423"
        }
      }
    },
    "route3": {
      "Type": "AWS::EC2::Route",
      "Properties": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "RouteTableId": {
          "Ref": "rtb017a472d2d8d61ce5"
        },
        "GatewayId": {
          "Ref": "igw0356f970a2bc6cc06"
        }
      },
      "DependsOn": "gw1"
    },
    "route4": {
      "Type": "AWS::EC2::Route",
      "Properties": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "RouteTableId": {
          "Ref": "rtb0d46463a6ab971e4f"
        }
      }
    },
    "dchpassoc1": {
      "Type": "AWS::EC2::VPCDHCPOptionsAssociation",
      "Properties": {
        "VpcId": {
          "Ref": "vpc0a20ebcd5ad0afcc3"
        },
        "DhcpOptionsId": {
          "Ref": "doptb2f3b2d5"
        }
      }
    }
  },
  "Description": "Zoran's VPC pattern template"
}
https://docs.aws.amazon.com/codebuild/latest/userguide/cloudformation-vpc-template.html
https://github.com/keithsharp/cloudformation-templates/blob/master/vpc-template.yaml

No comments:

Post a Comment