From 249504829a6ec1940c62b621f77872c3469701b1 Mon Sep 17 00:00:00 2001 From: dick Date: Thu, 4 Dec 2025 10:46:51 +0100 Subject: [PATCH] presque fini (je pense) --- terraform/environments/dev/main.tf | 32 ++++++++++++++++++------- terraform/environments/dev/variables.tf | 14 +++++------ terraform/modules/compute/main.tf | 2 +- terraform/modules/compute/variables.tf | 19 +++++++++------ terraform/modules/iam/variables.tf | 5 ++-- terraform/modules/network/main.tf | 20 ++++++++-------- terraform/modules/network/outputs.tf | 4 +++- terraform/modules/network/variables.tf | 19 +++++---------- 8 files changed, 64 insertions(+), 51 deletions(-) diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf index 3c35ea6..10ec7f5 100644 --- a/terraform/environments/dev/main.tf +++ b/terraform/environments/dev/main.tf @@ -4,6 +4,10 @@ terraform { source = "hashicorp/google" version = "~> 6.12.0" } + local = { + source = "hashicorp/local" + version = "~> 2.5.0" + } } } @@ -15,21 +19,19 @@ provider "google" { 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 + 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 - } module "compute" { source = "../../modules/compute" - project_name = var.project_name - zone = var.zone - instance_type = var.instance_type - + project_name = var.project_name + zone = var.zone + instance_type = var.instance_type frontend_subnet_id = module.network.subnet_ids["frontend"] backend_subnet_id = module.network.subnet_ids["backend"] database_subnet_id = module.network.subnet_ids["database"] @@ -41,3 +43,15 @@ module "iam" { ssh_public_key_path = "/home/adriendick18/.ssh/id_ed25519.pub" } +data "google_client_openid_userinfo" "me" {} + +resource "local_file" "ansible_cfg" { + filename = "${path.module}/ansible.cfg" + + content = templatefile( + "${path.module}/../../templates/ansile.cfg.tpl", + { + remote_user = data.google_client_openid_userinfo.me.email + } + ) +} diff --git a/terraform/environments/dev/variables.tf b/terraform/environments/dev/variables.tf index 4a31da2..b1a3064 100644 --- a/terraform/environments/dev/variables.tf +++ b/terraform/environments/dev/variables.tf @@ -1,7 +1,6 @@ -# Commentaire variable "project_name" { type = string - description = "but3-iac" + description = "Nom logique du projet" default = "projet-virtualisation" } @@ -38,14 +37,13 @@ variable "database_cidr" { variable "ssh_source_ranges" { type = string description = "Plages d’adresses autorisées à se connecter en SSH" - default = "0.0.0.0/0" - + default = "0.0.0.0/0" } -variable "project_id"{ - description = "id du projet" - type = string - default = "projet-virtualisation-478713" +variable "project_id" { + description = "ID du projet GCP" + type = string + default = "projet-virtualisation-478713" } variable "instance_type" { diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf index 96a2a68..5e7cae1 100644 --- a/terraform/modules/compute/main.tf +++ b/terraform/modules/compute/main.tf @@ -53,7 +53,7 @@ resource "google_compute_instance" "database" { boot_disk { initialize_params { image = "debian-cloud/debian-11" - size = 10 + size = 20 } } diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf index aa736fd..e434705 100644 --- a/terraform/modules/compute/variables.tf +++ b/terraform/modules/compute/variables.tf @@ -1,24 +1,29 @@ variable "project_name" { - type = string + description = "Nom du projet / préfixe pour les VMs" + type = string } variable "instance_type" { - type = string + description = "Type de machine à utiliser pour les instances" + type = string } variable "zone" { - type = string + description = "Zone où déployer les instances" + type = string } variable "frontend_subnet_id" { - type = string + description = "ID du sous-réseau frontend" + type = string } variable "backend_subnet_id" { - type = string + description = "ID du sous-réseau backend" + type = string } variable "database_subnet_id" { - type = string + description = "ID du sous-réseau database" + type = string } - diff --git a/terraform/modules/iam/variables.tf b/terraform/modules/iam/variables.tf index e88ddbb..db4cac2 100644 --- a/terraform/modules/iam/variables.tf +++ b/terraform/modules/iam/variables.tf @@ -1,8 +1,9 @@ variable "project_id" { - type = string + description = "ID du projet GCP" + type = string } variable "ssh_public_key_path" { - type = string description = "Chemin vers la clé publique SSH" + type = string } diff --git a/terraform/modules/network/main.tf b/terraform/modules/network/main.tf index b51c7f2..5bbaa2a 100644 --- a/terraform/modules/network/main.tf +++ b/terraform/modules/network/main.tf @@ -25,11 +25,11 @@ resource "google_compute_subnetwork" "database_network" { } resource "google_compute_firewall" "ssh_firewall" { - name = "${var.project_name}-ssh" - network = google_compute_network.vpc.name - direction = "INGRESS" - priority = 1000 - target_tags = ["ssh"] + name = "${var.project_name}-ssh" + network = google_compute_network.vpc.name + direction = "INGRESS" + priority = 1000 + target_tags = ["ssh"] source_ranges = [var.ssh_source_ranges] allow { @@ -39,11 +39,11 @@ resource "google_compute_firewall" "ssh_firewall" { } resource "google_compute_firewall" "frontend_firewall" { - name = "${var.project_name}-frontend-http-https" - network = google_compute_network.vpc.name - direction = "INGRESS" - priority = 1000 - target_tags = ["frontend"] + name = "${var.project_name}-frontend-http-https" + network = google_compute_network.vpc.name + direction = "INGRESS" + priority = 1000 + target_tags = ["frontend"] source_ranges = ["0.0.0.0/0"] allow { diff --git a/terraform/modules/network/outputs.tf b/terraform/modules/network/outputs.tf index 685ca8a..027ce01 100644 --- a/terraform/modules/network/outputs.tf +++ b/terraform/modules/network/outputs.tf @@ -1,8 +1,10 @@ output "vpc_id" { - value = google_compute_network.vpc.id + description = "ID du VPC créé" + value = google_compute_network.vpc.id } output "subnet_ids" { + description = "Map des IDs des sous-réseaux" value = { frontend = google_compute_subnetwork.frontend_network.id backend = google_compute_subnetwork.backend_network.id diff --git a/terraform/modules/network/variables.tf b/terraform/modules/network/variables.tf index dec9325..069afc4 100644 --- a/terraform/modules/network/variables.tf +++ b/terraform/modules/network/variables.tf @@ -1,36 +1,29 @@ variable "project_name" { + description = "Nom du projet / préfixe des ressources réseau" type = string - description = "but3-iac-dick" - } variable "region" { + description = "Région GCP" type = string - description = "Région dans laquelle déployer les ressources" - } variable "frontend_cidr" { - description = "CIDR for frontend subnet" + description = "CIDR pour le subnet frontend" type = string - } variable "backend_cidr" { - description = "CIDR for backend subnet" + description = "CIDR pour le subnet backend" type = string - } variable "database_cidr" { - description = "CIDR for database subnet" + description = "CIDR pour le subnet database" type = string - } variable "ssh_source_ranges" { + description = "Plage IP autorisée pour le SSH" type = string - description = "Plages d’adresses autorisées à se connecter en SSH" - - }