diff --git a/tp-cloud/terraform/environments/dev/variables.tf b/tp-cloud/terraform/environments/dev/variables.tf index 4ad4253..1e0797e 100644 --- a/tp-cloud/terraform/environments/dev/variables.tf +++ b/tp-cloud/terraform/environments/dev/variables.tf @@ -1,48 +1,47 @@ variable "project_name" { - description = "ID du projet GCP" + description = "Nom du projet" type = string - default = "iut fbleau tp" + default = "tp-1-docker" } variable "project_id" { - description = "ID du projet GCP" + description = "ID du projet" type = string - default = "iut fbleau tp" + default = "tp-1-docker" } variable "region" { - description = "region du projet" + description = "Région du projet" type = string - default = "europe-west9" + default = "europe-west4" } - variable "frontend_cidr" { - description = "frontend" + description = "cidr du frontend" type = string default = "10.0.1.0/24" } variable "backend_cidr" { - description = "backend" + description = "cidr du backend" type = string default = "10.0.2.0/24" } variable "database_cidr" { - description = "database" + description = "cidr du database" type = string default = "10.0.3.0/24" } variable "ssh_source_ranges" { - description = "acces par ssh" + description = "Accès à internet" type = string default = "0.0.0.0/0" } variable "cidr_range" { - description = "cidr-network" + description = "cidr de network" type = string default = "10.0.0.0/16" -} +} \ No newline at end of file diff --git a/tp-cloud/terraform/modules/compute/main.tf b/tp-cloud/terraform/modules/compute/main.tf index e69de29..07e3161 100644 --- a/tp-cloud/terraform/modules/compute/main.tf +++ b/tp-cloud/terraform/modules/compute/main.tf @@ -0,0 +1,69 @@ +resource "google_compute_instance" "frontend" { + 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" "backend" { + 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" "database" { + 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/tp-cloud/terraform/modules/compute/outputs.tf b/tp-cloud/terraform/modules/compute/outputs.tf index e69de29..ffd300a 100644 --- a/tp-cloud/terraform/modules/compute/outputs.tf +++ b/tp-cloud/terraform/modules/compute/outputs.tf @@ -0,0 +1,21 @@ +output "instance_names" { + description = "Noms des instances" + value = { + frontend = google_compute_instance.frontend.name + backend = google_compute_instance.backend.name + database = google_compute_instance.database.name + } +} + +output "frontend_public_ip" { + value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip +} + +output "private_ip" { + description = "IPs internes de toutes les instances" + value = { + frontend = google_compute_instance.frontend.network_interface[0].network_ip + backend = google_compute_instance.backend.network_interface[0].network_ip + database = google_compute_instance.database.network_interface[0].network_ip + } +} \ No newline at end of file diff --git a/tp-cloud/terraform/modules/compute/variables.tf b/tp-cloud/terraform/modules/compute/variables.tf index e69de29..6840a39 100644 --- a/tp-cloud/terraform/modules/compute/variables.tf +++ b/tp-cloud/terraform/modules/compute/variables.tf @@ -0,0 +1,26 @@ +variable "instance_type" { + description = "les types d'instances" + type = string + default = "e2-micro" +} + +variable "zone" { + description = "zone des instances" + type = string + default = "europe-west4" +} + +variable "frontend_subnet_id" { + description = "L'identifiant du subnet utilisé pour le frontend" + type = string +} + +variable "backend_subnet_id" { + description = "L'identifiant du subnet utilisé pour le backend" + type = string +} + +variable "database_subnet_id" { + description = "L'identifiant du subnet utilisé pour la database" + type = string +} \ No newline at end of file