diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf index a4f4814..8fb034a 100644 --- a/terraform/modules/compute/main.tf +++ b/terraform/modules/compute/main.tf @@ -19,4 +19,90 @@ # - Disque : 20GB # - Pas d'IP publique # - Tags : database, ssh -# - OS Login enabled \ No newline at end of file +# - OS Login enabled + +resource "google_compute_instance" "frontend" { +name = "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 {} +} + + +metadata = { +enable-oslogin = "TRUE" +} + + +tags = ["frontend", "ssh"] +} + + +resource "google_compute_instance" "backend" { +name = "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 +} + + +metadata = { +enable-oslogin = "TRUE" +} + + +tags = ["backend", "ssh"] +} + + +resource "google_compute_instance" "database" { +name = "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 +} + + +metadata = { +enable-oslogin = "TRUE" +} + + +tags = ["database", "ssh"] +} \ No newline at end of file diff --git a/terraform/modules/compute/outputs.tf b/terraform/modules/compute/outputs.tf index 4a91aa9..26a0294 100644 --- a/terraform/modules/compute/outputs.tf +++ b/terraform/modules/compute/outputs.tf @@ -1,4 +1,32 @@ # À vous d'exposer : # 1. Les IPs internes de toutes les instances # 2. L'IP publique du frontend -# 3. Les noms des instances \ No newline at end of file +# 3. Les noms des instances + +output "frontend_internal_ip" { + value = google_compute_instance.frontend.network_interface[0].network_ip +} + + +output "backend_internal_ip" { + value = google_compute_instance.backend.network_interface[0].network_ip +} + + +output "database_internal_ip" { + value = google_compute_instance.database.network_interface[0].network_ip +} + + +output "frontend_public_ip" { + value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip +} + + +output "instance_names" { + value = [ + google_compute_instance.frontend.name, + google_compute_instance.backend.name, + google_compute_instance.database.name + ] +} \ No newline at end of file diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf index 76a14cc..a605992 100644 --- a/terraform/modules/compute/variables.tf +++ b/terraform/modules/compute/variables.tf @@ -3,4 +3,28 @@ # - zone # - frontend_subnet_id # - backend_subnet_id -# - database_subnet_id \ No newline at end of file +# - database_subnet_id + +variable "instance_type" { +type = string +} + + +variable "zone" { +type = string +} + + +variable "frontend_subnet_id" { +type = string +} + + +variable "backend_subnet_id" { +type = string +} + + +variable "database_subnet_id" { +type = string +} \ No newline at end of file