This repository contains a Terraform module for creating and managing AWS VPC networks, including subnets, Internet Gateways, Network ACLs, and NAT Gateways.
- Terraform module to create VPC subnets.
- Module source: app.terraform.io/subhamay-bhattacharyya/vpc-subnets/aws
- Version: 1.0.0
project-name
: The name of the project.vpc-cidr
: The CIDR block for the VPC (e.g., "10.0.0.0/16").enable-dns-hostnames
: Boolean to enable/disable DNS hostnames in the VPC.enable-dns-support
: Boolean to enable/disable DNS support in the VPC.subnet-configuration
: A map defining the CIDR blocks for public and private subnets.ci-build
: A string representing the CI build identifier.
module "vpc_subnets" {
source = "app.terraform.io/subhamay-bhattacharyya/vpc-subnets/aws"
version = "1.0.0"
project-name = "your-project-name"
vpc-cidr = "your-vpc-cidr-range"
subnet-configuration = "your-subnet-configuration"
ci-build = "your-ci-build-string"
}
public-subnet-count = 1
private-subnet-count = 1
Use local variables to configure the subnet CIDR blocks
locals {
public-cidrs = var.public-subnet-count > 0 ? [for i in range(0, var.public-subnet-count * 2 - 1, 2) : cidrsubnet(var.vpc-cidr, 8, i)] : []
private-cidrs = var.private-subnet-count > 0 ? [for i in range(1, var.private-subnet-count * 2, 2) : cidrsubnet(var.vpc-cidr, 8, i)] : []
}
locals {
subnet-configuration = {
public = local.public-cidrs
private = local.private-cidrs
}
}
DNS hostname and DNS support are enabled by default. To override the default values, use false in the .tfvars file
Use local variables to configure the default tags. The default resource tags are implemented using the CI/CD Pipeline. The following mao just refers to it.
locals {
tags = {
Environment = var.environment-name
ProjectName = var.project-name
GitHubRepository = var.github-repo
GitHubRef = var.github-ref
GitHubURL = var.github-url
GitHubSHA = var.github-sha
}
}
- To create only public subnets only pass
private-subnet-count=0
- To create only private subnets only pass
public-subnet-count=0
- Internet gateway will be created only if atleast one public subnet is created.
Name | Description | Type | Default | Required |
---|---|---|---|---|
project-name | The name of the project | string | n/a | yes |
vpc-cidr | The CIDR block for the VPC | string | 10.0.0.0/16 | yes |
enable-dns-hostnames | Boolean to enable/disable DNS hostnames in the VPC | bool | true | no |
enable-dns-support | Boolean to enable/disable DNS support in the VPC | bool | true | no |
subnet-configuration | A map defining the CIDR blocks for public and private subnets | map | n/a | yes |
ci-build | A string representing the CI build identifier | string | "" | yes |
Name | Description | Type | Default | Required |
---|---|---|---|---|
public | The CIDR blocks for the public subnets | list | n/a | yes |
private | The CIDR blocks for the private subnets | list | n/a | yes |
Name | Description |
---|---|
az-list | The list of availability zones in the region |
vpc-id | VPC Id |
subnet-configuration | Configuration for public and private subnets |
internet-gateway-id | The ID of the Internet Gateway |
public-subnet-ids | The IDs of the public subnets |
private-subnet-ids | The IDs of the private subnets |
public-route-table-ids | The IDs of the public route tables |
private-route-table-ids | The IDs of the private route tables |
network-acl-id | The ID of the Network ACL |
public-nacl-ids | The IDs of the public network ACL associations |
private-nacl-ids | The IDs of the private network ACL associations |