From 93bb97f5044df560efe9fb6a43111897ec745560 Mon Sep 17 00:00:00 2001 From: SimonSayeBabu Date: Fri, 6 Dec 2024 14:42:49 +0100 Subject: [PATCH] google ta mere --- terraform/environments/dev/main.tf | 13 +++++ terraform/modules/compute/main.tf | 69 ++++++++++++++++++++++++++ terraform/modules/compute/variables.tf | 24 +++++++++ terraform/modules/network/main.tf | 2 +- terraform/modules/network/outputs.tf | 11 ++++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf index 5387a8a..6306a77 100644 --- a/terraform/environments/dev/main.tf +++ b/terraform/environments/dev/main.tf @@ -25,4 +25,17 @@ module "network" { backend_cidr = var.backend_cidr database_cidr = var.database_cidr ssh_source_ranges = var.ssh_source_ranges +} + +module "compute" { + source = "../../modules/compute" + + # Variables d'en"trée + instance_type = "e2-micro" + zone = "europe-west1-a" + + # Autres variables spécifiques au module + frontend_subnet_id = module.network.id_subnetwork["frontend"] + backend_subnet_id = module.network.id_subnetwork["backend"] + database_subnet_id = module.network.id_subnetwork["database"] } \ No newline at end of file diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf index e69de29..52a54c6 100644 --- a/terraform/modules/compute/main.tf +++ b/terraform/modules/compute/main.tf @@ -0,0 +1,69 @@ +resource "google_compute_instance" "vmfrontend" { + name = "ma-vm-frontend" + machine_type = var.instance_type + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 10 + } + } + + network_interface { + subnetwork = var.frontend_subnet_id + access_config {} # IP publique + } + + tags = ["frontend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + +resource "google_compute_instance" "vmbackend" { + name = "ma-vm-backend" + machine_type = var.instance_type + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 10 + } + } + + network_interface { + subnetwork = var.backend_subnet_id + } + + tags = ["backend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + +resource "google_compute_instance" "vmdatabase" { + name = "ma-vm-database" + machine_type = var.instance_type + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 20 + } + } + + network_interface { + subnetwork = var.database_subnet_id + } + + tags = ["database", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} \ No newline at end of file diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf index e69de29..8e0fd0b 100644 --- a/terraform/modules/compute/variables.tf +++ b/terraform/modules/compute/variables.tf @@ -0,0 +1,24 @@ + +variable "instance_type" { + description = "type d'instance" + type = string +} + +variable "zone" { + description = "zone du projet" + type = string +} + +variable "frontend_subnet_id" { + description = "id du subnet du frontend projet" + type = string +} + +variable "backend_subnet_id" { + description = "id du subnet du backend projet" + type = string +} +variable "database_subnet_id" { + description = "id du subnet du database projet" + type = string +} \ No newline at end of file diff --git a/terraform/modules/network/main.tf b/terraform/modules/network/main.tf index bf5f858..61cc3fa 100644 --- a/terraform/modules/network/main.tf +++ b/terraform/modules/network/main.tf @@ -34,7 +34,7 @@ resource "google_compute_firewall" "allow-http-https" { } source_ranges = ["0.0.0.0/0"] - target_tags = ["web"] + target_tags = ["frontend"] } resource "google_compute_firewall" "allow-ssh" { diff --git a/terraform/modules/network/outputs.tf b/terraform/modules/network/outputs.tf index e69de29..53a163c 100644 --- a/terraform/modules/network/outputs.tf +++ b/terraform/modules/network/outputs.tf @@ -0,0 +1,11 @@ +output "id_vpc" { + value = google_compute_network.vpc.id +} + +output "id_subnetwork" { + value = { + frontend = google_compute_subnetwork.frontend.id, + backend = google_compute_subnetwork.backend.id, + database = google_compute_subnetwork.database.id + } +} \ No newline at end of file