commit 1b48e888725897626da0a35c04e8a0dd0c19799a Author: art.dambrine Date: Fri Jan 29 08:40:06 2021 +0100 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60d079c --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ + +# Created by https://www.gitignore.io/api/terraform + +### Terraform ### +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +*.tfvars + + +# End of https://www.gitignore.io/api/terraform diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8cce7f9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: git://github.com/antonbabenko/pre-commit-terraform + sha: v1.39.0 + hooks: + - id: terraform_fmt + + - repo: git://github.com/pre-commit/pre-commit-hooks + sha: v3.2.0 + hooks: + - id: check-merge-conflict diff --git a/README.md b/README.md new file mode 100644 index 0000000..b33d6a0 --- /dev/null +++ b/README.md @@ -0,0 +1,87 @@ +# Terraform AWS VPC + +## :package: Install Terraform + +Install Terraform by following the [documentation](https://www.terraform.io/downloads.html) + +Make sure `terraform` is working properly + +```hcl +$ terraform +Usage: terraform [--version] [--help] [args] + +The available commands for execution are listed below. +The most common, useful commands are shown first, followed by +less common or more advanced commands. If you're just getting +started with Terraform, stick with the common commands. For the +other commands, please read the help and docs before usage. + +Common commands: + apply Builds or changes infrastructure + console Interactive console for Terraform interpolations +# ... +``` + +*Based on [standard module structure](https://www.terraform.io/docs/modules/create.html#standard-module-structure) guidelines* + +## :triangular_ruler: Naming Convention + +Common variables referenced in naming standards + +| Variable | RegExp | Example | +|:----------------------|:--------------------------------|:------------------------------------------------------------| +| `` | `[a-z]{2}-[a-z]{1,}-[1-2][a-f]` | `us-east-1a`, `us-west-2c`, `eu-west-1a`, `ap-northeast-1c` | + +--- + +## AWS - Resource Naming Standards + +| AWS Resource | Resource Naming | Comment | Example | +|:-----------------|:-----------------------------------------|:--------|:---------------------------------| +| VPC | `-vpc` | | `mycloud-vpc` | +| Subnets | `-private-` | | `mycloud-private-us-east-1b` | +| | `-public-` | | `mycloud-public-us-east-1b` | +| Route Tables | `-private-` | | `mycloud-private-us-east-1b` | +| | `-public` | | `mycloud-public` | +| Internet Gateway | `-igw` | | `mycloud-igw` | +| Nat Gateway | `-nat-` | | `mycloud-nat-us-east-1b` | + + +## 1. Create a `VPC` + +The really first stage for bootstrapping an AWS account is to create a `VPC` + +* [aws_vpc](https://www.terraform.io/docs/providers/aws/r/vpc.html) + +![VPC AZs](./docs/2-vpc-azs.png) + +## 2. Create `public` and `private` Subnets + +Then create `public` and `private` subnets in each `AZs` (`us-east-1a`, `us-east-1b`, `us-east-1c`) + +* [aws_subnet](https://www.terraform.io/docs/providers/aws/r/subnet.html) + +![VPC AZs Subnets](./docs/3-vpc-azs-subnets.png) + +## 3. Create `internet` and `nat` Gateways + +Create one `internet gateway` so that the `VPC` can communicate with the outisde world. For instances located in `private` subnets, we will need `NAT` instances to be setup in each `availability zones` + +* [aws_internet_gateway](https://www.terraform.io/docs/providers/aws/r/internet_gateway.html) +* [aws_ami](https://www.terraform.io/docs/providers/aws/d/ami.html) +* [aws_key_pair](https://www.terraform.io/docs/providers/aws/r/key_pair.html) +* [aws_instance](https://www.terraform.io/docs/providers/aws/r/instance.html) +* [aws_eip](https://www.terraform.io/docs/providers/aws/r/eip.html) +* [aws_eip_association](https://www.terraform.io/docs/providers/aws/r/eip_association.html) + +![VPC AZs Subnets GW](./docs/4-vpc-azs-subnets-gw.png) + +## 4. Create `route tables` and `routes` + +Finaly, link the infrastructure together by creating `route tables` and `routes` so that servers from `public` and `private` subnets can send their traffic to the respective gateway, either the `internet gateway` or the `NAT` ones. + +* [aws_route_table](https://www.terraform.io/docs/providers/aws/r/route_table.html) +* [aws_route](https://www.terraform.io/docs/providers/aws/r/route.html) +* [aws_route_table_association](https://www.terraform.io/docs/providers/aws/r/route_table_association.html) + +![VPC AZs Subnets GW Routes](./docs/5-vpc-azs-subnets-gw-routing.png) diff --git a/TP Terraform - AWS.md b/TP Terraform - AWS.md new file mode 100644 index 0000000..02752d4 --- /dev/null +++ b/TP Terraform - AWS.md @@ -0,0 +1,4 @@ +# TP Terraform - AWS + +https://infrastructure.aws + diff --git a/docs/1-vpc.png b/docs/1-vpc.png new file mode 100644 index 0000000..c6fc4b5 Binary files /dev/null and b/docs/1-vpc.png differ diff --git a/docs/2-vpc-azs.png b/docs/2-vpc-azs.png new file mode 100644 index 0000000..427eea6 Binary files /dev/null and b/docs/2-vpc-azs.png differ diff --git a/docs/3-vpc-azs-subnets.png b/docs/3-vpc-azs-subnets.png new file mode 100644 index 0000000..cd36f45 Binary files /dev/null and b/docs/3-vpc-azs-subnets.png differ diff --git a/docs/4-vpc-azs-subnets-gw.png b/docs/4-vpc-azs-subnets-gw.png new file mode 100644 index 0000000..af34746 Binary files /dev/null and b/docs/4-vpc-azs-subnets-gw.png differ diff --git a/docs/5-vpc-azs-subnets-gw-routing.png b/docs/5-vpc-azs-subnets-gw-routing.png new file mode 100644 index 0000000..d3b8c01 Binary files /dev/null and b/docs/5-vpc-azs-subnets-gw-routing.png differ diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..96771af --- /dev/null +++ b/main.tf @@ -0,0 +1,6 @@ +### Module Main + +provider "aws" { + region = var.aws_region +} + diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..647f418 --- /dev/null +++ b/variables.tf @@ -0,0 +1,4 @@ +variable "aws_region" { + type = string + default = "us-east-1" +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +}