diff --git a/terraform/environments/dev/main.tf b/terraform/environments/dev/main.tf index c1d85fe..356d1f4 100644 --- a/terraform/environments/dev/main.tf +++ b/terraform/environments/dev/main.tf @@ -21,4 +21,14 @@ module "network" { backend_cidr = var.backend_cidr database_cidr = var.database_cidr ssh_source_ranges = var.ssh_source_ranges +} + +module "compute" { + source = "../../modules/compte" + + instance_type = var.instance_type + zone = var.zone + frontend_subnet_id = var.frontend_subnet_id + backend_subnet_id = var.backend_subnet_id + database_subnet_id = var.database_subnet_id } \ No newline at end of file diff --git a/terraform/environments/dev/variables.tf b/terraform/environments/dev/variables.tf index 3e49b06..cd24df4 100644 --- a/terraform/environments/dev/variables.tf +++ b/terraform/environments/dev/variables.tf @@ -39,4 +39,18 @@ variable "project_id" { description = "id du projet" type = string default = "model-cirrus-478713-u8" -} \ No newline at end of file +} + + +variable "instance_type" { + description = "Nom du projet cidr" + type = string + default = "" +} + + +variable "zone" { + description = "Nom du projet cidr" + type = string + default = "value" +} diff --git a/terraform/modules/compute/main.tf b/terraform/modules/compute/main.tf index e69de29..92db240 100644 --- a/terraform/modules/compute/main.tf +++ b/terraform/modules/compute/main.tf @@ -0,0 +1,100 @@ +# À vous de créer : + +# 1. Instance frontend : +# - Image : debian-11 +# - Disque : 10GB +# - IP publique +# - Tags : frontend, ssh +# - OS Login enabled + +# 2. Instance backend : +# - Image : debian-11 +# - Disque : 10GB +# - Pas d'IP publique (interne seulement) +# - Tags : backend, ssh +# - OS Login enabled + +# 3. Instance database : +# - Image : debian-11 +# - Disque : 20GB +# - Pas d'IP publique +# - Tags : database, ssh +# - OS Login enabled + + + + + +resource "google_compute_instance" "vm_frontend" { + name = "frontend" + machine_type = "e2-medium" + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 10 + } + } + + network_interface { + access_config {} # IP publique + subnetwork = google_compute_subnetwork.subnet.id + } + + tags = ["frontend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + + + +resource "google_compute_instance" "vm_backend" { + name = "ma-vm" + machine_type = "e2-medium" + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 10 + } + } + + network_interface { + subnetwork = google_compute_subnetwork.subnet.id + } + + tags = ["backend", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} + + + +resource "google_compute_instance" "vm_database" { + name = "ma-vm" + machine_type = "e2-medium" + zone = var.zone + + boot_disk { + initialize_params { + image = "debian-cloud/debian-11" + size = 20 + } + } + + network_interface { + subnetwork = google_compute_subnetwork.subnet.id + } + + tags = ["database", "ssh"] + + metadata = { + enable-oslogin = "TRUE" + } +} diff --git a/terraform/modules/compute/outputs.tf b/terraform/modules/compute/outputs.tf index e69de29..358b3dc 100644 --- a/terraform/modules/compute/outputs.tf +++ b/terraform/modules/compute/outputs.tf @@ -0,0 +1,28 @@ +# À vous d'exposer : +# 1. Les IPs internes de toutes les instances +# 2. L'IP publique du frontend +# 3. Les noms des instances + + +output "instance_internal_ips" { + description = "IPs internes de toutes les instances" + value = { + frontend = google_compute_instance.vm_frontend.network_interface[0].network_ip + backend = google_compute_instance.vm_backend.network_interface[0].network_ip + database = google_compute_instance.vm_database.network_interface[0].network_ip + } +} + +output "frontend_public_ip" { + description = "IP publique de l'instance frontend" + value = google_compute_instance.vm_frontend.network_interface[0].access_config[0].nat_ip +} + +output "instance_names" { + description = "Noms de toutes les instances" + value = { + frontend = google_compute_instance.vm_frontend.name + backend = google_compute_instance.vm_backend.name + database = google_compute_instance.vm_database.name + } +} \ No newline at end of file diff --git a/terraform/modules/compute/variables.tf b/terraform/modules/compute/variables.tf index e69de29..23b8058 100644 --- a/terraform/modules/compute/variables.tf +++ b/terraform/modules/compute/variables.tf @@ -0,0 +1,40 @@ +# À vous de définir les variables pour : +# - instance_type +# - zone +# - frontend_subnet_id +# - backend_subnet_id +# - database_subnet_id + +variable "instance_type" { + description = "Nom du projet cidr" + type = string +} + + +variable "zone" { + description = "Nom du projet cidr" + type = string +} + + +variable "frontend_subnet_id" { + description = "Nom du projet cidr" + type = string +} + + + +variable "backend_subnet_id" { + description = "Nom du projet cidr" + type = string +} + + +variable "database_subnet_id" { + description = "Nom du projet cidr" + type = string +} + + + +