Browse Source

init commit

master
art.dambrine 4 years ago
commit
1b48e88872
  1. 22
      .gitignore
  2. 10
      .pre-commit-config.yaml
  3. 87
      README.md
  4. 4
      TP Terraform - AWS.md
  5. BIN
      docs/1-vpc.png
  6. BIN
      docs/2-vpc-azs.png
  7. BIN
      docs/3-vpc-azs-subnets.png
  8. BIN
      docs/4-vpc-azs-subnets-gw.png
  9. BIN
      docs/5-vpc-azs-subnets-gw-routing.png
  10. 6
      main.tf
  11. 0
      outputs.tf
  12. 4
      variables.tf
  13. 4
      versions.tf

22
.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

10
.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

87
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] <command> [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 |
|:----------------------|:--------------------------------|:------------------------------------------------------------|
| `<availability_zone>` | `[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_name>-vpc` | | `mycloud-vpc` |
| Subnets | `<vpc_name>-private-<availability_zone>` | | `mycloud-private-us-east-1b` |
| | `<vpc_name>-public-<availability_zone>` | | `mycloud-public-us-east-1b` |
| Route Tables | `<vpc_name>-private-<availability_zone>` | | `mycloud-private-us-east-1b` |
| | `<vpc_name>-public` | | `mycloud-public` |
| Internet Gateway | `<vpc_name>-igw` | | `mycloud-igw` |
| Nat Gateway | `<vpc_name>-nat-<availability_zone>` | | `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)

4
TP Terraform - AWS.md

@ -0,0 +1,4 @@
# TP Terraform - AWS
https://infrastructure.aws

BIN
docs/1-vpc.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
docs/2-vpc-azs.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
docs/3-vpc-azs-subnets.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
docs/4-vpc-azs-subnets-gw.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
docs/5-vpc-azs-subnets-gw-routing.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

6
main.tf

@ -0,0 +1,6 @@
### Module Main
provider "aws" {
region = var.aws_region
}

0
outputs.tf

4
variables.tf

@ -0,0 +1,4 @@
variable "aws_region" {
type = string
default = "us-east-1"
}

4
versions.tf

@ -0,0 +1,4 @@
terraform {
required_version = ">= 0.12"
}
Loading…
Cancel
Save