feat(initial release): first version of the module

Deploy private and public subnets for each AZ as well as internet gateway for public subnets and NAT
gateway for private subnets

BREAKING CHANGE: first version of the module
main
Flavien Henrion 2022-09-21 11:43:47 +02:00
parent 5cb8219192
commit 951d58e66c
7 changed files with 251 additions and 1 deletions

17
.drone.yaml Normal file
View File

@ -0,0 +1,17 @@
kind: pipeline
type: docker
name: release
steps:
- name: semantic-release
image: node:16
commands:
- npm install -g semantic-release conventional-changelog-conventionalcommits @saithodev/semantic-release-gitea @semantic-release/changelog
- semantic-release
trigger:
event:
- pull_request
branch:
- beta
- main

15
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,15 @@
repos:
- repo: https://github.com/terraform-docs/terraform-docs
rev: "v0.16.0"
hooks:
- id: terraform-docs-go
args: ["markdown", "table", "--output-file", "README.md", "."]
types_or: [terraform]
- repo: local
hooks:
- id: terraform-fmt
name: terraform-fmt
pass_filenames: false
types_or: [terraform]
language: system
entry: terraform fmt

36
.releaserc.json Normal file
View File

@ -0,0 +1,36 @@
{
"branches": [
"main",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@saithodev/semantic-release-gitea",
{
"giteaUrl": "https://coincoingit.fr",
"assets": [
{
"path": "CHANGELOG.md",
"label": "Complete changelog"
},
{
"path": "README.md",
"label": "Release README"
}
]
}
]
],
"preset": "conventionalcommits"
}

View File

@ -1,4 +1,54 @@
# aws_network_terraform
Terraform module to provision a vpc with public and private subnets for each AZ.
Provision a internet gateway for public subnets and a NAT gateway for private subnets.
Provision a internet gateway for public subnets and a NAT gateway for private subnets.
<!-- BEGIN_TF_DOCS -->
## Requirements
No requirements.
## Providers
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
## Modules
No modules.
## Resources
| Name | Type |
|------|------|
| [aws_eip.nat](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eip) | resource |
| [aws_internet_gateway.main](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway) | resource |
| [aws_nat_gateway.nat](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/nat_gateway) | resource |
| [aws_route_table.private_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table.public_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table) | resource |
| [aws_route_table_association.private_routes](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_route_table_association.public_routes](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route_table_association) | resource |
| [aws_subnet.private_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
| [aws_subnet.public_subnets](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 |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_env"></a> [env](#input\_env) | n/a | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | n/a | `map(string)` | <pre>{<br> "Owner": "Flavien Henrion",<br> "Project": "Coincoincloud"<br>}</pre> | no |
| <a name="input_vpc_cidr"></a> [vpc\_cidr](#input\_vpc\_cidr) | n/a | `string` | `"10.0.0.0/16"` | no |
## Outputs
| Name | Description |
|------|-------------|
| <a name="output_private_subnets_cidrs"></a> [private\_subnets\_cidrs](#output\_private\_subnets\_cidrs) | n/a |
| <a name="output_private_subnets_ids"></a> [private\_subnets\_ids](#output\_private\_subnets\_ids) | n/a |
| <a name="output_public_subnets_cidrs"></a> [public\_subnets\_cidrs](#output\_public\_subnets\_cidrs) | n/a |
| <a name="output_public_subnets_ids"></a> [public\_subnets\_ids](#output\_public\_subnets\_ids) | n/a |
| <a name="output_vpc_cidr"></a> [vpc\_cidr](#output\_vpc\_cidr) | n/a |
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | n/a |
<!-- END_TF_DOCS -->

93
main.tf Normal file
View File

@ -0,0 +1,93 @@
data "aws_availability_zones" "available" {}
#-------------VPC and Internet Gateway------------------------------------------
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
tags = merge(var.tags, { Name = "${var.env}-vpc" })
}
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
tags = merge(var.tags, { Name = "${var.env}-igw" })
}
#-------------Public Subnets and Routing----------------------------------------
resource "aws_subnet" "public_subnets" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index + 1)
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
tags = merge(var.tags, {
Name = "${var.env}-public-${count.index + 1}",
Tier = "public"
})
}
resource "aws_route_table" "public_subnets" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
tags = merge(var.tags, { Name = "${var.env}-route-public-subnets" })
}
resource "aws_route_table_association" "public_routes" {
count = length(aws_subnet.public_subnets[*].id)
route_table_id = aws_route_table.public_subnets.id
subnet_id = aws_subnet.public_subnets[count.index].id
}
#-----NAT Gateways with Elastic IPs--------------------------
resource "aws_eip" "nat" {
count = length(data.aws_availability_zones.available.names)
vpc = true
tags = merge(var.tags, { Name = "${var.env}-nat-gw-${count.index + 1}" })
}
resource "aws_nat_gateway" "nat" {
count = length(data.aws_availability_zones.available.names)
allocation_id = aws_eip.nat[count.index].id
subnet_id = aws_subnet.public_subnets[count.index].id
tags = merge(var.tags, { Name = "${var.env}-nat-gw-${count.index + 1}" })
}
#--------------Private Subnets and Routing-------------------------
resource "aws_subnet" "private_subnets" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index + 11)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = merge(var.tags, {
Name = "${var.env}-private-${count.index + 1}",
Tier = "private"
})
}
resource "aws_route_table" "private_subnets" {
count = length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat[count.index].id
}
tags = merge(var.tags, { Name = "${var.env}-route-private-subnet-${count.index + 1}" })
}
resource "aws_route_table_association" "private_routes" {
count = length(data.aws_availability_zones.available.names)
route_table_id = aws_route_table.private_subnets[count.index].id
subnet_id = aws_subnet.private_subnets[count.index].id
}
#==============================================================

23
outputs.tf Normal file
View File

@ -0,0 +1,23 @@
output "vpc_id" {
value = aws_vpc.main.id
}
output "vpc_cidr" {
value = aws_vpc.main.cidr_block
}
output "public_subnets_ids" {
value = aws_subnet.public_subnets[*].id
}
output "public_subnets_cidrs" {
value = aws_subnet.public_subnets[*].cidr_block
}
output "private_subnets_ids" {
value = aws_subnet.private_subnets[*].id
}
output "private_subnets_cidrs" {
value = aws_subnet.private_subnets[*].cidr_block
}

16
variables.tf Normal file
View File

@ -0,0 +1,16 @@
variable "env" {
type = string
}
variable "vpc_cidr" {
type = string
default = "10.0.0.0/16"
}
variable "tags" {
type = map(string)
default = {
Owner = "Flavien Henrion"
Project = "Coincoincloud"
}
}