|
1 | | -# AWS VPC Module |
2 | | -Terraform AWS VPC Module |
| 1 | +# Hashicorp Terraform AWS VPC Module |
| 2 | +Terraform AWS VPC Module by Source4Learn(An Opensource Community to learn and share knowledge) |
| 3 | + |
| 4 | + |
| 5 | +## AWS VPC Module Usage |
| 6 | +This AWS VPC Module will creates 1/2/3 tier resources as per user inputs: |
| 7 | +- Subnets ["Public", "Private", "Storage"] |
| 8 | +- Route Tables ["Public", "Private", "Storage"] |
| 9 | +- Security Gruoups |
| 10 | +- Internet Gateway |
| 11 | +- NAT Gateway |
| 12 | +- Elatic IPs |
| 13 | +- Network ACLs |
| 14 | +- VPC Endpoints |
| 15 | + |
| 16 | +Example: Single tier AWS VPC architecture having only Public Subnet with required resources. |
| 17 | + |
| 18 | +```terraform |
| 19 | +resource "aws_vpc" "vpc" { |
| 20 | + cidr_block = "10.0.0.0/20" |
| 21 | +
|
| 22 | + tags = { |
| 23 | + Name = "my-vpc" |
| 24 | + Environment = "my-environment" |
| 25 | + } |
| 26 | +} |
| 27 | +
|
| 28 | +# AWS VPC Internet Gateway |
| 29 | +resource "aws_internet_gateway" "igw" { |
| 30 | + vpc_id = aws_vpc.vpc.id |
| 31 | +
|
| 32 | + tags = { |
| 33 | + Name = "my-igw" |
| 34 | + Environment = "my-environment" |
| 35 | + } |
| 36 | +} |
| 37 | +
|
| 38 | +# AWS VPC Subnets Module - Public Subnet |
| 39 | +module "public_subnet" { |
| 40 | + source = "./modules/subnets" |
| 41 | + vpc_id = aws_vpc.vpc.id |
| 42 | + aws_internet_gateway_id = aws_internet_gateway.igw.id |
| 43 | + cidr = "10.0.0.0/20" |
| 44 | + subnet_bits = "4" |
| 45 | + prefix = "my-subnet" |
| 46 | + environment = "my-environment" |
| 47 | + subnet_type = ["public"] |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +In adadition to above example, users can provision 2/3 tier AWS VPC architecture. |
| 52 | + |
| 53 | +```terraform |
| 54 | +module "nat_gateway" { |
| 55 | + source = "./modules/nat-gateways" |
| 56 | + prefix = "my-nat-gateway" |
| 57 | + environment = "my-environment" |
| 58 | + public_subnet_ids = module.public_subnet.public_subnet_ids |
| 59 | +} |
| 60 | +
|
| 61 | +module "private_subnet" { |
| 62 | + source = "./modules/subnets" |
| 63 | + vpc_id = aws_vpc.vpc.id |
| 64 | + aws_nat_gateway_id = module.nat_gateway.nat_gateway_ids |
| 65 | + cidr = "10.0.0.0/20" |
| 66 | + subnet_bits = "4" |
| 67 | + prefix = "my-subnet" |
| 68 | + environment = "my-environment" |
| 69 | + subnet_type = ["private", "storage"] |
| 70 | +} |
| 71 | +
|
| 72 | +module "security_group" { |
| 73 | + source = "./modules/security-groups" |
| 74 | + vpc_id = aws_vpc.vpc.id |
| 75 | + prefix = "my-security-group" |
| 76 | + environment = "my-environment" |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Requirements |
| 81 | + |
| 82 | +| Name | Version | |
| 83 | +|------|---------| |
| 84 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 | |
| 85 | + |
| 86 | +## Providers |
| 87 | + |
| 88 | +| Name | Version | |
| 89 | +|------|---------| |
| 90 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a | |
| 91 | + |
| 92 | +## Modules |
| 93 | + |
| 94 | +| Name | Source | Version | |
| 95 | +|------|--------|---------| |
| 96 | +| <a name="module_nat_gateway"></a> [nat\_gateway](#module\_nat\_gateway) | ./modules/nat-gateways | | |
| 97 | +| <a name="module_private_subnet"></a> [private\_subnet](#module\_private\_subnet) | ./modules/subnets | | |
| 98 | +| <a name="module_public_subnet"></a> [public\_subnet](#module\_public\_subnet) | ./modules/subnets | | |
| 99 | +| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | ./modules/security-groups | | |
| 100 | + |
| 101 | +## Resources |
| 102 | + |
| 103 | +| Name | Type | |
| 104 | +|------|------| |
| 105 | +| [aws_internet_gateway.igw](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway) | resource | |
| 106 | +| [aws_vpc.vpc](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) | resource | |
| 107 | + |
| 108 | +## Inputs |
| 109 | + |
| 110 | +| Name | Description | Type | Default | Required | |
| 111 | +|------|-------------|------|---------|:--------:| |
| 112 | +| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Default Region | `string` | n/a | yes | |
| 113 | +| <a name="input_cidr"></a> [cidr](#input\_cidr) | CIDR block value to define the size of the AWS VPC | `string` | `"10.0.0.0/20"` | no | |
| 114 | +| <a name="input_environment"></a> [environment](#input\_environment) | To apply generic environment to AWS VPC Resources | `string` | n/a | yes | |
| 115 | +| <a name="input_prefix"></a> [prefix](#input\_prefix) | To apply generic naming to AWS VPC Resources | `string` | n/a | yes | |
| 116 | +| <a name="input_subnet_bits"></a> [subnet\_bits](#input\_subnet\_bits) | Subnet bits for cidrsubnet interpolation or Size we need to define for the Subnet (cidr of VPC + Subnet bits) | `string` | n/a | yes | |
| 117 | + |
| 118 | +## Outputs |
| 119 | + |
| 120 | +| Name | Description | |
| 121 | +|------|-------------| |
| 122 | +| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | Terraform Output | |
0 commit comments