Management VPC
Overview
This service contains code to deploy a Virtual Private Cloud (VPC) on AWS that can be used for administrative and management purposes, such as CI/CD services. The primary difference between this and the application VPC is this one has two subnet tiers (public and private) while the application VPC has three (public, private, and persistence). In this management VPC, we assume that there are no data stores that need to be separated in to a dedicated persistence tier.
VPC architecture
Features
- The VPC itself.
- Subnets, which are isolated subdivisions within the VPC. There are 2 "tiers" of subnets, public and private, spanning multiple availability zones.
- Route tables, which provide routing rules for the subnets.
- Internet Gateways to route traffic to the public Internet from public subnets.
- NATs to route traffic to the public Internet from private subnets.
Learn
note
This repo is a part of the Gruntwork Service Catalog, a collection of reusable, battle-tested, production ready infrastructure code. If you’ve never used the Service Catalog before, make sure to read How to use the Gruntwork Service Catalog!
Under the hood, this is all implemented using Terraform modules from the Gruntwork terraform-aws-vpc repo. If you are a subscriber and don’t have access to this repo, email support@gruntwork.io.
Core concepts
To understand core concepts like what’s a VPC, how subnets are configured, how network ACLs work, and more, see the documentation in the terraform-aws-vpc repo.
Repo organization
- modules: The main implementation code for this repo, broken down into multiple standalone, orthogonal submodules.
- examples: This folder contains working examples of how to use the submodules.
- test: Automated tests for the modules and examples.
Deploy
Non-production deployment (quick start for learning)
If you just want to try this repo out for experimenting and learning, check out the following resources:
- examples/for-learning-and-testing folder: The
examples/for-learning-and-testing
folder contains standalone sample code optimized for learning, experimenting, and testing (but not direct production usage).
Production deployment
If you want to deploy this repo in production, check out the following resources:
- examples/for-production folder: The
examples/for-production
folder contains sample code optimized or direct usage in production. This is code from the Gruntwork Reference Architecture, and it shows you how we build an end-to-end, integrated tech stack on top of the Gruntwork Service Catalog. - How to deploy a production-grade VPC on AWS
- How to configure a production-grade CI/CD workflow for application and infrastructure code: step-by-step guide on how to configure CI / CD for your apps and infrastructure.
Reference
- Inputs
- Outputs
apply_default_nacl_rules
— If true, will apply the default NACL rules indefault_nacl_ingress_rules
anddefault_nacl_egress_rules
on the default NACL of the VPC. Note that every VPC must have a default NACL - when this is false, the original default NACL rules managed by AWS will be used.
associate_default_nacl_to_subnets
— If true, will associate the default NACL to the public, private, and persistence subnets created by this module. Only used ifapply_default_nacl_rules
is true. Note that this does not guarantee that the subnets are associated with the default NACL. Subnets can only be associated with a single NACL. The default NACL association will be dropped if the subnets are associated with a custom NACL later.
availability_zone_exclude_ids
— List of excluded Availability Zone IDs.
availability_zone_exclude_names
— List of excluded Availability Zone names.
availability_zone_state
— Allows to filter list of Availability Zones based on their current state. Can be either "available", "information", "impaired" or "unavailable". By default the list includes a complete set of Availability Zones to which the underlying AWS account has access, regardless of their state.
aws_region
— The AWS region to deploy into
cidr_block
— The IP address range of the VPC in CIDR notation. A prefix of /16 is recommended. Do not use a prefix higher than /27. Examples include '10.100.0.0/16', '10.200.0.0/16', etc.
create_flow_logs
— If you set this variable to false, this module will not create VPC Flow Logs resources. This is used as a workaround because Terraform does not allow you to use the 'count' parameter on modules. By using this parameter, you can optionally create or not create the resources within this module.
create_network_acls
— If set to false, this module will NOT create Network ACLs. This is useful if you don't want to use Network ACLs or you want to provide your own Network ACLs outside of this module.
custom_tags
— A map of tags to apply to the VPC, Subnets, Route Tables, and Internet Gateway. The key is the tag name and the value is the tag value. Note that the tag 'Name' is automatically added by this module but may be optionally overwritten by this variable.
custom_tags_vpc_only
— A map of tags to apply just to the VPC itself, but not any of the other resources. The key is the tag name and the value is the tag value. Note that tags defined here will override tags defined ascustom_tags
in case of conflict.
default_nacl_egress_rules
— The egress rules to apply to the default NACL in the VPC. This is the security group that is used by any subnet that doesn't have its own NACL attached. The value for this variable must be a map where the keys are a unique name for each rule and the values are objects with the same fields as the egress block in theaws_default_network_acl
resource:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_network_acl
.
default_nacl_ingress_rules
— The ingress rules to apply to the default NACL in the VPC. This is the NACL that is used by any subnet that doesn't have its own NACL attached. The value for this variable must be a map where the keys are a unique name for each rule and the values are objects with the same fields as the ingress block in theaws_default_network_acl
resource:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_network_acl
.
default_security_group_egress_rules
— The egress rules to apply to the default security group in the VPC. This is the security group that is used by any resource that doesn't have its own security group attached. The value for this variable must be a map where the keys are a unique name for each rule and the values are objects with the same fields as the egress block in theaws_default_security_group
resource:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group
#egress-block.
default_security_group_ingress_rules
— The ingress rules to apply to the default security group in the VPC. This is the security group that is used by any resource that doesn't have its own security group attached. The value for this variable must be a map where the keys are a unique name for each rule and the values are objects with the same fields as the ingress block in theaws_default_security_group
resource:https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group
#ingress-block.
enable_default_security_group
— If set to false, the default security groups will NOT be created.
kms_key_arn
— The ARN of a KMS key to use for encrypting VPC the flow log. A new KMS key will be created if this is not supplied.
kms_key_deletion_window_in_days
— The number of days to retain this KMS Key (a Customer Master Key) after it has been marked for deletion. Setting to null defaults to the provider default, which is the maximum possible value (30 days).
kms_key_user_iam_arns
— VPC Flow Logs will be encrypted with a KMS Key (a Customer Master Key). The IAM Users specified in this list will have access to this key.
nat_gateway_custom_tags
— A map of tags to apply to the NAT gateways, on top of thecustom_tags
. The key is the tag name and the value is the tag value. Note that tags defined here will override tags defined ascustom_tags
in case of conflict.
num_availability_zones
— How many AWS Availability Zones (AZs) to use. One subnet of each type (public, private app) will be created in each AZ. Note that this must be less than or equal to the total number of AZs in a region. A value of null means all AZs should be used. For example, if you specify 3 in a region with 5 AZs, subnets will be created in just 3 AZs instead of all 5. Defaults to 3.
num_nat_gateways
— The number of NAT Gateways to launch for this VPC. The management VPC defaults to 1 NAT Gateway to save on cost, but to increase redundancy, you can adjust this to add additional NAT Gateways.
private_subnet_bits
— Takes the CIDR prefix and adds these many bits to it for calculating subnet ranges. MAKE SURE if you change this you also change the CIDR spacing or you may hit errors. See cidrsubnet interpolation in terraform config for more information.
private_subnet_cidr_blocks
— A map listing the specific CIDR blocks desired for each private subnet. The key must be in the form AZ-0, AZ-1, ... AZ-n where n is the number of Availability Zones. If left blank, we will compute a reasonable CIDR block for each subnet.
private_subnet_custom_tags
— A map of tags to apply to the private Subnet, on top of thecustom_tags
. The key is the tag name and the value is the tag value. Note that tags defined here will override tags defined ascustom_tags
in case of conflict.
public_subnet_bits
— Takes the CIDR prefix and adds these many bits to it for calculating subnet ranges. MAKE SURE if you change this you also change the CIDR spacing or you may hit errors. See cidrsubnet interpolation in terraform config for more information.
public_subnet_cidr_blocks
— A map listing the specific CIDR blocks desired for each public subnet. The key must be in the form AZ-0, AZ-1, ... AZ-n where n is the number of Availability Zones. If left blank, we will compute a reasonable CIDR block for each subnet.
public_subnet_custom_tags
— A map of tags to apply to the public Subnet, on top of thecustom_tags
. The key is the tag name and the value is the tag value. Note that tags defined here will override tags defined ascustom_tags
in case of conflict.
subnet_spacing
— The amount of spacing between the different subnet types
vpc_name
— The name of the VPC. Defaults to mgmt.
nat_gateway_public_ips
— The public IP address(es) of the NAT gateway(s) of the mgmt VPC.
num_availability_zones
— The number of availability zones used by the mgmt VPC.
private_subnet_arns
— The private subnet ARNs of the mgmt VPC.
private_subnet_cidr_blocks
— The private subnet CIDR blocks of the mgmt VPC.
private_subnet_ids
— The private subnet IDs of the mgmt VPC.
private_subnet_route_table_ids
— The ID of the private subnet route table of the mgmt VPC.
public_subnet_arns
— The public subnet ARNs of the mgmt VPC.
public_subnet_cidr_blocks
— The public subnet CIDR blocks of the mgmt VPC.
public_subnet_ids
— The public subnet IDs of the mgmt VPC.
public_subnet_route_table_id
— The ID of the public subnet route table of the mgmt VPC.
vpc_cidr_block
— The CIDR block of the mgmt VPC.
vpc_id
— The ID of the mgmt VPC.
vpc_name
— The name of the mgmt VPC.
vpc_ready
— Indicates whether or not the VPC has finished creating