forked from pierront/but3-iac
ajout du network
This commit is contained in:
85
terraform/modules/compute/main.tf
Normal file
85
terraform/modules/compute/main.tf
Normal file
@@ -0,0 +1,85 @@
|
||||
// Récupération de l'image Debian 11
|
||||
data "google_compute_image" "debian_11" {
|
||||
family = "debian-11"
|
||||
project = "debian-cloud"
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "frontend" {
|
||||
name = "frontend-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
|
||||
tags = ["frontend", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = data.google_compute_image.debian_11.self_link
|
||||
size = 10 // 10GB
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.frontend_subnet_id
|
||||
|
||||
// IP publique
|
||||
access_config {}
|
||||
}
|
||||
|
||||
// OS Login activé
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
resource "google_compute_instance" "backend" {
|
||||
name = "backend-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
|
||||
tags = ["backend", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = data.google_compute_image.debian_11.self_link
|
||||
size = 10 // 10GB
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.backend_subnet_id
|
||||
// Pas d'access_config -> pas d'IP publique
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
resource "google_compute_instance" "database" {
|
||||
name = "database-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
|
||||
tags = ["database", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = data.google_compute_image.debian_11.self_link
|
||||
size = 20 // 20GB
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.database_subnet_id
|
||||
// Pas d'access_config -> pas d'IP publique
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
26
terraform/modules/compute/outputs.tf
Normal file
26
terraform/modules/compute/outputs.tf
Normal file
@@ -0,0 +1,26 @@
|
||||
// 1. IPs internes de toutes les instances
|
||||
output "internal_ips" {
|
||||
description = "IPs internes des instances frontend, backend et database"
|
||||
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 créées"
|
||||
value = {
|
||||
frontend = google_compute_instance.frontend.name
|
||||
backend = google_compute_instance.backend.name
|
||||
database = google_compute_instance.database.name
|
||||
}
|
||||
}
|
||||
|
||||
25
terraform/modules/compute/variables.tf
Normal file
25
terraform/modules/compute/variables.tf
Normal file
@@ -0,0 +1,25 @@
|
||||
variable "instance_type" {
|
||||
description = "Type de machine)"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "Zone de déploiement"
|
||||
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