Browse Source

1st part TP ok

master
art.dambrine 4 years ago
parent
commit
d0db52d90c
  1. 19
      .terraform.lock.hcl
  2. 17
      TP Terraform - AWS.md
  3. 41
      main.tf
  4. 3
      outputs.tf
  5. 23
      variables.tf

19
.terraform.lock.hcl

@ -0,0 +1,19 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "3.26.0"
hashes = [
"h1:0i78FItlPeiomd+4ThZrtm56P5K33k7/6dnEe4ZePI0=",
"zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb",
"zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300",
"zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b",
"zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535",
"zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587",
"zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d",
"zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea",
"zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4",
"zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58",
"zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01",
]
}

17
TP Terraform - AWS.md

@ -2,3 +2,20 @@
https://infrastructure.aws
Mise en place de l'envirronement de dev
```
terraform init
terraform plan
```
## Importation de AWS vers notre code Terraform
Exemple avec un vpc :
```
terraform import aws_vpc.main <vpc-id>
```

41
main.tf

@ -4,3 +4,44 @@ provider "aws" {
region = var.aws_region
}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
tags = {
Name = "${var.vpc_name}-vpc",
Terraform = true,
Environment = "production"
}
}
## Fonction super utile pour le calc de ss réseaux
# cidrsubnet("172.22.0.0/16",4,iterate_value)
resource "aws_subnet" "private" {
for_each = var.azs
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr, 4, each.value)
availability_zone = "${var.aws_region}${each.key}"
map_public_ip_on_launch = false
tags = {
Name = "${var.vpc_name}-private-${var.aws_region}${each.key}"
}
}
resource "aws_subnet" "public" {
for_each = var.azs
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(var.vpc_cidr, 4, 15 - each.value)
availability_zone = "${var.aws_region}${each.key}"
map_public_ip_on_launch = true
tags = {
Name = "${var.vpc_name}-public-${var.aws_region}${each.key}"
}
}

3
outputs.tf

@ -0,0 +1,3 @@
output "vpc_id" {
value = aws_vpc.main.id
}

23
variables.tf

@ -2,3 +2,26 @@ variable "aws_region" {
type = string
default = "us-east-1"
}
variable "vpc_name" {
type = string
default = "my-could"
description = "VPC name"
}
variable "vpc_cidr" {
type = string
default = "172.22.0.0/16"
description = "VPC Cidr block"
}
variable "azs" {
type = map(any)
default = {
"a" = 0,
"b" = 1,
"c" = 2,
"d" = 3
}
description = "Availability zones to create within subnet"
}

Loading…
Cancel
Save