forked from pierront/but3-iac
ajout des configs terraform
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
output "frontend_public_ip" {
|
||||
description = "IP publique du Frontend pour les tests HTTP/HTTPS."
|
||||
value = module.compute.frontend_public_ip
|
||||
}
|
||||
|
||||
output "internal_ips" {
|
||||
description = "Map des IPs internes pour la configuration Ansible."
|
||||
value = module.compute.internal_ips
|
||||
}
|
||||
|
||||
output "gcp_user_for_ssh" {
|
||||
description = "Nom d'utilisateur pour se connecter en SSH via OS Login."
|
||||
value = regex("^(.*)@", var.gcp_user_email)[0]
|
||||
}
|
||||
|
||||
output "service_account_email" {
|
||||
description = "Email du compte de service Terraform."
|
||||
value = module.iam.service_account_email
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
locals {
|
||||
disk_config = {
|
||||
frontend = 10
|
||||
backend = 10
|
||||
database = 20
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "frontend_instance" {
|
||||
project = var.project_id
|
||||
name = "frontend-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
tags = ["frontend", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = var.image
|
||||
size = local.disk_config.frontend
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.frontend_subnet_id
|
||||
access_config {
|
||||
# IP publique (éphémère)
|
||||
}
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "backend_instance" {
|
||||
project = var.project_id
|
||||
name = "backend-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
tags = ["backend", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = var.image
|
||||
size = local.disk_config.backend
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.backend_subnet_id
|
||||
# Pas de bloc access_config pour IP interne seulement
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "database_instance" {
|
||||
project = var.project_id
|
||||
name = "database-instance"
|
||||
machine_type = var.instance_type
|
||||
zone = var.zone
|
||||
tags = ["database", "ssh"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = var.image
|
||||
size = local.disk_config.database
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
subnetwork = var.database_subnet_id
|
||||
# Pas de bloc access_config pour IP interne seulement
|
||||
}
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
output "frontend_public_ip" {
|
||||
description = "L'IP publique de l'instance frontend."
|
||||
value = google_compute_instance.frontend_instance.network_interface[0].access_config[0].nat_ip
|
||||
}
|
||||
|
||||
output "internal_ips" {
|
||||
description = "Map des IPs internes de toutes les instances."
|
||||
value = {
|
||||
frontend = google_compute_instance.frontend_instance.network_interface[0].network_ip
|
||||
backend = google_compute_instance.backend_instance.network_interface[0].network_ip
|
||||
database = google_compute_instance.database_instance.network_interface[0].network_ip
|
||||
}
|
||||
}
|
||||
|
||||
output "instance_names" {
|
||||
description = "Map des noms des instances."
|
||||
value = {
|
||||
frontend = google_compute_instance.frontend_instance.name
|
||||
backend = google_compute_instance.backend_instance.name
|
||||
database = google_compute_instance.database_instance.name
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
variable "project_id" {
|
||||
description = "L'ID du projet GCP."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "instance_type" {
|
||||
description = "Le type de machine (machine type) pour les instances (ex: e2-small)."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "La zone GCP où déployer les instances."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "image" {
|
||||
description = "L'image du système d'exploitation à utiliser (ex: debian-cloud/debian-11)."
|
||||
type = string
|
||||
default = "debian-cloud/debian-11"
|
||||
}
|
||||
|
||||
variable "frontend_subnet_id" {
|
||||
description = "L'ID du sous-réseau frontend."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "backend_subnet_id" {
|
||||
description = "L'ID du sous-réseau backend."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "database_subnet_id" {
|
||||
description = "L'ID du sous-réseau database."
|
||||
type = string
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
resource "google_service_account" "terraform_sa" {
|
||||
project = var.project_id
|
||||
account_id = var.service_account_name
|
||||
display_name = "Terraform Deployment SA"
|
||||
}
|
||||
|
||||
resource "google_project_iam_member" "sa_roles" {
|
||||
for_each = toset([
|
||||
"roles/compute.admin",
|
||||
"roles/iam.serviceAccountUser"
|
||||
])
|
||||
project = var.project_id
|
||||
role = each.key
|
||||
member = "serviceAccount:${google_service_account.terraform_sa.email}"
|
||||
}
|
||||
|
||||
resource "google_project_iam_member" "oslogin_roles" {
|
||||
for_each = toset([
|
||||
"roles/compute.osLogin",
|
||||
"roles/iam.serviceAccountUser"
|
||||
])
|
||||
project = var.project_id
|
||||
role = each.key
|
||||
member = "user:${var.gcp_user_email}"
|
||||
}
|
||||
|
||||
resource "google_os_login_ssh_public_key" "user_ssh_key" {
|
||||
user = var.gcp_user_email
|
||||
key = var.ssh_public_key
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
output "service_account_email" {
|
||||
description = "L'email du compte de service créé."
|
||||
value = google_service_account.terraform_sa.email
|
||||
}
|
||||
|
||||
# La clé n'est pas exposée ici mais l'output est là pour l'exercice (décommenter si nécessaire)
|
||||
/*
|
||||
output "service_account_key" {
|
||||
description = "La clé privée encodée du compte de service."
|
||||
value = google_service_account_key.terraform_sa_key.private_key_base64
|
||||
sensitive = true
|
||||
}
|
||||
*/
|
||||
@@ -1,20 +0,0 @@
|
||||
variable "project_id" {
|
||||
description = "L'ID du projet GCP."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "service_account_name" {
|
||||
description = "Nom du compte de service Terraform."
|
||||
type = string
|
||||
default = "terraform-deployer"
|
||||
}
|
||||
|
||||
variable "gcp_user_email" {
|
||||
description = "Votre adresse e-mail GCP (pour OS Login)."
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_public_key" {
|
||||
description = "Votre clé publique SSH (contenu du fichier ~/.ssh/id_ed25519.pub)."
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user