vpc
AWS VPC with public and private subnets spread across the availability zones you pass, one of each per AZ.
Optional, all off by default and priced accordingly: NAT gateways for private-subnet egress
(enable_nat_gateway), VPC flow logs to a CloudWatch log group with its own IAM role (enable_flow_logs),
and S3 / DynamoDB gateway endpoints that keep that traffic off the NAT at no cost
(enable_dynamodb_gateway_endpoint). Subnet CIDRs are validated against azs at plan time.
Usage
module "vpc" {
source = "github.com/rafaelcarvajal05/terraform-stacks//modules/vpc?ref=v0.1.0"
name = "my-app"
cidr_block = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
public_subnet_cidrs = ["10.0.0.0/24", "10.0.1.0/24"]
private_subnet_cidrs = ["10.0.10.0/24", "10.0.11.0/24"]
enable_nat_gateway = true
enable_flow_logs = true
enable_dynamodb_gateway_endpoint = true
tags = {
Environment = "prod"
}
}
See examples/vpc-basic for a runnable, zero-cost configuration.
Requirements
Providers
Modules
No modules.
Resources
| Name |
Description |
Type |
Default |
Required |
| azs |
Availability zones to spread the subnets across. One public and one private subnet is created per AZ. |
list(string) |
n/a |
yes |
| cidr_block |
IPv4 CIDR block for the VPC, e.g. 10.0.0.0/16. |
string |
n/a |
yes |
| name |
Name prefix used for every resource created by the module (also applied as the Name tag). |
string |
n/a |
yes |
| private_subnet_cidrs |
CIDR blocks for the private subnets, one per entry in azs (same order). The count is checked against azs at plan time. |
list(string) |
n/a |
yes |
| public_subnet_cidrs |
CIDR blocks for the public subnets, one per entry in azs (same order). The count is checked against azs at plan time. |
list(string) |
n/a |
yes |
| enable_dynamodb_gateway_endpoint |
Create a DynamoDB gateway VPC endpoint associated with every route table (free, keeps DynamoDB traffic off the NAT). |
bool |
false |
no |
| enable_flow_logs |
Create a CloudWatch Logs log group, an IAM role and a VPC flow log that publishes the VPC traffic to it. |
bool |
false |
no |
| enable_nat_gateway |
Create NAT gateway(s) so private subnets get outbound internet access. |
bool |
false |
no |
| enable_s3_gateway_endpoint |
Create an S3 gateway VPC endpoint associated with every route table (free, keeps S3 traffic off the NAT). |
bool |
true |
no |
| flow_logs_kms_key_arn |
ARN of a KMS key used to encrypt the flow logs log group. When null the log group uses the default CloudWatch Logs encryption. The key policy must allow the CloudWatch Logs service. |
string |
null |
no |
| flow_logs_retention_in_days |
Retention in days of the flow logs CloudWatch log group. Only used when enable_flow_logs is true. Must be a value accepted by CloudWatch Logs. |
number |
365 |
no |
| flow_logs_traffic_type |
Type of traffic captured by the flow log: ACCEPT, REJECT or ALL. Only used when enable_flow_logs is true. |
string |
"ALL" |
no |
| single_nat_gateway |
When enable_nat_gateway is true, create a single shared NAT gateway (cheaper) instead of one per AZ (highly available). |
bool |
true |
no |
| tags |
Tags applied to every resource. A Name tag is added per resource. |
map(string) |
{} |
no |
Outputs