This commit is contained in:
2025-12-04 08:58:54 +01:00
parent da5310f034
commit 3227265c7a
3 changed files with 141 additions and 3 deletions

View File

@@ -19,4 +19,90 @@
# - Disque : 20GB
# - Pas d'IP publique
# - Tags : database, ssh
# - OS Login enabled
# - 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"]
}

View File

@@ -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
# 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
]
}

View File

@@ -3,4 +3,28 @@
# - zone
# - frontend_subnet_id
# - backend_subnet_id
# - database_subnet_id
# - 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
}