forked from pierront/but3-iac
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
This commit is contained in:
74
terraform/modules/compute/main.tf
Normal file
74
terraform/modules/compute/main.tf
Normal file
@@ -0,0 +1,74 @@
|
||||
# compute/main.tf
|
||||
|
||||
resource "google_compute_instance" "frontend" {
|
||||
name = "frontend-instance"
|
||||
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
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
|
||||
tags = ["frontend", "ssh"]
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "backend" {
|
||||
name = "backend-instance"
|
||||
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
|
||||
# Pas d'IP publique
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
|
||||
tags = ["backend", "ssh"]
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "database" {
|
||||
name = "database-instance"
|
||||
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
|
||||
# Pas d'IP publique
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
|
||||
tags = ["database", "ssh"]
|
||||
}
|
||||
|
||||
27
terraform/modules/compute/outputs.tf
Normal file
27
terraform/modules/compute/outputs.tf
Normal file
@@ -0,0 +1,27 @@
|
||||
# compute/outputs.tf
|
||||
|
||||
# 1. IPs internes de toutes les instances
|
||||
output "internal_ips" {
|
||||
description = "IPs internes des 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
|
||||
}
|
||||
}
|
||||
|
||||
# 2. IP publique du frontend
|
||||
output "frontend_public_ip" {
|
||||
description = "IP publique de l'instance frontend"
|
||||
value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip
|
||||
}
|
||||
|
||||
# 3. Noms des instances
|
||||
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
|
||||
}
|
||||
}
|
||||
27
terraform/modules/compute/variables.tf
Normal file
27
terraform/modules/compute/variables.tf
Normal file
@@ -0,0 +1,27 @@
|
||||
# compute/variables.tf
|
||||
|
||||
variable "instance_type" {
|
||||
description = "Type d'instance GCE à utiliser"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone dans laquelle déployer les instances"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "frontend_subnet_id" {
|
||||
description = "ID du sous-réseau frontend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "backend_subnet_id" {
|
||||
description = "ID du sous-réseau backend"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "database_subnet_id" {
|
||||
description = "ID du sous-réseau database"
|
||||
type = string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user