forked from pierront/but3-iac
commit de test
This commit is contained in:
23
tp-cloud/terraform/environments/dev/main.tf
Normal file
23
tp-cloud/terraform/environments/dev/main.tf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
google = {
|
||||||
|
source = "hashicorp/google"
|
||||||
|
version = "~> 6.12.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "google" {
|
||||||
|
project = var.project_id
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
module "network" {
|
||||||
|
source = "../../modules/network"
|
||||||
|
project_name = var.project_name
|
||||||
|
region = var.region
|
||||||
|
frontend_cidr = var.frontend_cidr
|
||||||
|
backend_cidr = var.backend_cidr
|
||||||
|
database_cidr = var.database_cidr
|
||||||
|
ssh_source_ranges = var.ssh_source_ranges
|
||||||
|
}
|
||||||
0
tp-cloud/terraform/environments/dev/outputs.tf
Normal file
0
tp-cloud/terraform/environments/dev/outputs.tf
Normal file
0
tp-cloud/terraform/environments/dev/variables.tf
Normal file
0
tp-cloud/terraform/environments/dev/variables.tf
Normal file
0
tp-cloud/terraform/modules/compute/main.tf
Normal file
0
tp-cloud/terraform/modules/compute/main.tf
Normal file
0
tp-cloud/terraform/modules/compute/outputs.tf
Normal file
0
tp-cloud/terraform/modules/compute/outputs.tf
Normal file
0
tp-cloud/terraform/modules/compute/variables.tf
Normal file
0
tp-cloud/terraform/modules/compute/variables.tf
Normal file
0
tp-cloud/terraform/modules/iam/main.tf
Normal file
0
tp-cloud/terraform/modules/iam/main.tf
Normal file
0
tp-cloud/terraform/modules/iam/outputs.tf
Normal file
0
tp-cloud/terraform/modules/iam/outputs.tf
Normal file
0
tp-cloud/terraform/modules/iam/variables.tf
Normal file
0
tp-cloud/terraform/modules/iam/variables.tf
Normal file
89
tp-cloud/terraform/modules/network/main.tf
Normal file
89
tp-cloud/terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
# VPC
|
||||||
|
resource "google_compute_network" "vpc" {
|
||||||
|
name = "mon-vpc"
|
||||||
|
auto_create_subnetworks = false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sous-réseau
|
||||||
|
# front-end
|
||||||
|
resource "google_compute_subnetwork" "front-end" {
|
||||||
|
name = "front-end"
|
||||||
|
network = google_compute_subnetwork.frontend.id
|
||||||
|
ip_cidr_range = "10.0.1.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# back-end
|
||||||
|
resource "google_compute_subnetwork" "back-end" {
|
||||||
|
name = "back-end"
|
||||||
|
network = google_compute_subnetwork.backend.id
|
||||||
|
ip_cidr_range = "10.0.1.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# data-base
|
||||||
|
resource "google_compute_subnetwork" "data-base" {
|
||||||
|
name = "data-base"
|
||||||
|
network = google_compute_network.database.id
|
||||||
|
ip_cidr_range = "10.0.1.0/24"
|
||||||
|
region = "europe-west1"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Règles de Pare-feu
|
||||||
|
|
||||||
|
# - HTTP/HTTPS vers frontend
|
||||||
|
resource "google_compute_firewall" "allow_http" {
|
||||||
|
name = "allow-http"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["80", "443"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
target_tags = ["front-end"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# - SSH vers toutes les instances
|
||||||
|
resource "google_compute_firewall" "SSH" {
|
||||||
|
name = "SSH"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["22"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# - Port 8000 de frontend vers backend
|
||||||
|
resource "google_compute_firewall" "front-back" {
|
||||||
|
name = "front to back"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["8000"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["front-end"]
|
||||||
|
target_tags = ["back-end"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# - Port 3306 de backend vers database
|
||||||
|
resource "google_compute_firewall" "back-base" {
|
||||||
|
name = "back to front"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["3306"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["back-end"]
|
||||||
|
target_tags = ["data-base"]
|
||||||
|
}
|
||||||
|
|
||||||
17
tp-cloud/terraform/modules/network/outputs.tf
Normal file
17
tp-cloud/terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
output "vpc_terraform" {
|
||||||
|
description = "ID du VPC créé"
|
||||||
|
value = google_compute_instance.vpc.id
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
output "subnet_ids" {
|
||||||
|
description = "Map des IDs des sous-réseaux"
|
||||||
|
value = {
|
||||||
|
|
||||||
|
frontend = google_compute_subnetwork.frontend.id
|
||||||
|
backend = google_compute_subnetwork.backend.id
|
||||||
|
database = google_compute_subnetwork.database.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
29
tp-cloud/terraform/modules/network/variables.tf
Normal file
29
tp-cloud/terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
description = "Nom du projet"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
description = "Région"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_cidr" {
|
||||||
|
description = "CIDR du frontend"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_cidr" {
|
||||||
|
description = "CIDR du backend"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_cidr" {
|
||||||
|
description = "CIDR de la database"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_source_ranges" {
|
||||||
|
description = "Plages IP autorisées pour SSH"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
0
tp-cloud/terraform/templates/ansible.cfg.tpl
Normal file
0
tp-cloud/terraform/templates/ansible.cfg.tpl
Normal file
Reference in New Issue
Block a user