ajout compute

This commit is contained in:
2025-12-04 09:10:40 +01:00
parent f48c698399
commit bdbf44c6c3
5 changed files with 168 additions and 0 deletions

View File

@@ -25,4 +25,13 @@ module "network" {
backend_cidr = var.backend_cidr backend_cidr = var.backend_cidr
database_cidr = var.database_cidr database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges ssh_source_ranges = var.ssh_source_ranges
}
module "compute" {
source = "../../modules/compute"
instance_type = var.instance_type
zone = var.zone
frontend_subnet_id = module.network.subnets.frontend
backend_subnet_id = module.network.subnets.backend
database_subnet_id = module.network.subnets.database
} }

View File

@@ -40,4 +40,16 @@ variable "project_id" {
description = "ID du projet" description = "ID du projet"
type = string type = string
default = "learned-trilogy-478713-j7 " default = "learned-trilogy-478713-j7 "
}
variable "instance_type" {
description = "type de l'instance"
type = string
default = "e2-small"
}
variable "zone" {
description = "Nom de la zone"
type = string
default = "europe-west9-b"
} }

View File

@@ -0,0 +1,92 @@
# À 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 = "vm-frontend"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
access_config {} # IP publique
subnetwork = var.frontend_subnet_id
}
tags = ["frontend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "vm_backend" {
name = "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" "vm_database" {
name = "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"
}
}

View File

@@ -0,0 +1,24 @@
# À vous d'exposer :
# 1. Les IPs internes de toutes les instances
# 2. L'IP publique du frontend
# 3. Les noms des instances
output "ip_internes" {
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 "ip_public_frontend" {
value = google_compute_instance.vm_frontend.network_interface[0].access_config[0].nat_ip
}
output "nom_instances" {
value = {
frontend = google_compute_instance.vm_frontend.name
backend = google_compute_instance.vm_backend.name
database = google_compute_instance.vm_database.name
}
}

View File

@@ -0,0 +1,31 @@
# À vous de définir les variables pour :
# - instance_type
# - zone
# - frontend_subnet_id
# - backend_subnet_id
# - database_subnet_id
variable "instance_type" {
description = "type de l'instance"
type = string
}
variable "zone" {
description = "Nom de la zone"
type = string
}
variable "frontend_subnet_id" {
description = "id du frontend"
type = string
}
variable "backend_subnet_id" {
description = "id du backend"
type = string
}
variable "database_subnet_id" {
description = "id du database"
type = string
}