Skip to content

Commit

Permalink
feat: add sub module to create network for atlantis
Browse files Browse the repository at this point in the history
  • Loading branch information
nimisha-gj committed Jul 13, 2024
1 parent 2f9b6cf commit 7e60cb2
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 0 deletions.
Empty file added modules/network/.header.md
Empty file.
55 changes: 55 additions & 0 deletions modules/network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.5.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.5.0 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_internet_gateway.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway) | resource |
| [aws_route.public_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource |
| [aws_route.public_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource |
| [aws_route_table.private_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table.private_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table.public_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table.public_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table_association.private_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_route_table_association.private_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_route_table_association.public_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_route_table_association.public_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_subnet.private_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_subnet.private_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_subnet.public_1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_subnet.public_2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_vpc.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | List of Availability zone where the subnet must reside. | `list(string)` | <pre>[<br> "us-east-1a",<br> "us-east-1b"<br>]</pre> | no |
| <a name="input_private_subnet_cidrs"></a> [private\_subnet\_cidrs](#input\_private\_subnet\_cidrs) | List of IPv4 CIDR block for private subnets. | `list(string)` | <pre>[<br> "10.0.3.0/24",<br> "10.0.4.0/24"<br>]</pre> | no |
| <a name="input_public_subnet_cidrs"></a> [public\_subnet\_cidrs](#input\_public\_subnet\_cidrs) | List of IPv4 CIDR block for public subnets. | `list(string)` | <pre>[<br> "10.0.1.0/24",<br> "10.0.2.0/24"<br>]</pre> | no |
| <a name="input_vpc_cidr_block"></a> [vpc\_cidr\_block](#input\_vpc\_cidr\_block) | (Optional) The IPv4 CIDR block for the VPC. | `string` | `"10.0.0.0/16"` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_private_subnet_ids"></a> [private\_subnet\_ids](#output\_private\_subnet\_ids) | The ID of the private subnets. |
| <a name="output_public_subnet_ids"></a> [public\_subnet\_ids](#output\_public\_subnet\_ids) | The ID of the public subnets. |
| <a name="output_vpc_cidr_block"></a> [vpc\_cidr\_block](#output\_vpc\_cidr\_block) | CIDR block range of the VPC |
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | The ID of VPC. |
12 changes: 12 additions & 0 deletions modules/network/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
locals {
vpc_name = "atlantis-ecs-vpc"
public_1_subnet_name = "atlantis-ecs-vpc-public-subnet-1"
private_1_subnet_name = "atlantis-ecs-vpc-private-subnet-1"
private_1_route_table_name = "atlantis-ecs-vpc-private-route-table-1"
public_1_route_table_name = "atlantis-ecs-vpc-public-route-table-1"
public_2_subnet_name = "atlantis-ecs-vpc-public-subnet-2"
private_2_subnet_name = "atlantis-ecs-vpc-private-subnet-2"
private_2_route_table_name = "atlantis-ecs-vpc-private-route-table-2"
public_2_route_table_name = "atlantis-ecs-vpc-public-route-table-2"
igw_name = "atlantis-ecs-vpc-internet-gateway"
}
116 changes: 116 additions & 0 deletions modules/network/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
provider "aws" {
region = "us-east-1"
}

resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr_block
tags = {
Name = local.vpc_name
}
}

resource "aws_internet_gateway" "this" {
vpc_id = aws_vpc.main.id
tags = {
Name = local.igw_name
}
}


resource "aws_route" "public_1" {
route_table_id = aws_route_table.public_1.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.this.id
}


resource "aws_subnet" "public_1" {
cidr_block = var.public_subnet_cidrs[0]
vpc_id = aws_vpc.main.id
availability_zone = var.availability_zones[1]
tags = {
Name = local.public_1_subnet_name
}
}

resource "aws_route_table" "public_1" {
vpc_id = aws_vpc.main.id
tags = {
Name = local.public_1_route_table_name
}
}

resource "aws_route_table_association" "public_1" {
subnet_id = aws_subnet.public_1.id
route_table_id = aws_route_table.public_1.id
}

resource "aws_route" "public_2" {
route_table_id = aws_route_table.public_2.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.this.id
}

resource "aws_subnet" "public_2" {
cidr_block = var.public_subnet_cidrs[1]
vpc_id = aws_vpc.main.id
availability_zone = var.availability_zones[1]
tags = {
Name = local.public_2_subnet_name
}
}

resource "aws_route_table" "public_2" {
vpc_id = aws_vpc.main.id
tags = {
Name = local.public_2_route_table_name
}
}

resource "aws_route_table_association" "public_2" {
subnet_id = aws_subnet.public_2.id
route_table_id = aws_route_table.public_2.id
}

resource "aws_subnet" "private_1" {
cidr_block = var.private_subnet_cidrs[0]
vpc_id = aws_vpc.main.id
availability_zone = var.availability_zones[0]
tags = {
Name = local.private_1_subnet_name
}
}

resource "aws_route_table" "private_1" {
vpc_id = aws_vpc.main.id
tags = {
Name = local.private_1_route_table_name
}
}

resource "aws_route_table_association" "private_1" {
subnet_id = aws_subnet.private_1.id
route_table_id = aws_route_table.private_1.id
}


resource "aws_subnet" "private_2" {
cidr_block = var.private_subnet_cidrs[1]
vpc_id = aws_vpc.main.id
availability_zone = var.availability_zones[0]
tags = {
Name = local.private_2_subnet_name
}
}

resource "aws_route_table" "private_2" {
vpc_id = aws_vpc.main.id
tags = {
Name = local.private_2_route_table_name
}
}

resource "aws_route_table_association" "private_2" {
subnet_id = aws_subnet.private_2.id
route_table_id = aws_route_table.private_2.id
}
19 changes: 19 additions & 0 deletions modules/network/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "vpc_id" {
description = "The ID of VPC."
value = aws_vpc.main.id
}

output "public_subnet_ids" {
description = "The ID of the public subnets."
value = [aws_subnet.public_1.id, aws_subnet.public_2.id]
}

output "private_subnet_ids" {
description = "The ID of the private subnets."
value = [aws_subnet.private_1.id, aws_subnet.private_2.id]
}

output "vpc_cidr_block" {
description = "CIDR block range of the VPC"
value = aws_vpc.main.cidr_block
}
23 changes: 23 additions & 0 deletions modules/network/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "vpc_cidr_block" {
description = "(Optional) The IPv4 CIDR block for the VPC."
type = string
default = "10.0.0.0/16"
}

variable "public_subnet_cidrs" {
description = "List of IPv4 CIDR block for public subnets."
type = list(string)
default = ["10.0.1.0/24", "10.0.2.0/24"]
}

variable "private_subnet_cidrs" {
description = "List of IPv4 CIDR block for private subnets."
type = list(string)
default = ["10.0.3.0/24", "10.0.4.0/24"]
}

variable "availability_zones" {
description = "List of Availability zone where the subnet must reside."
type = list(string)
default = ["us-east-1a", "us-east-1b"]
}
10 changes: 10 additions & 0 deletions modules/network/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.6"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.5.0"
}
}
}

0 comments on commit 7e60cb2

Please sign in to comment.