diff --git a/terraform/modules/iam/main.tf b/terraform/modules/iam/main.tf index a4b77c1..2006c04 100644 --- a/terraform/modules/iam/main.tf +++ b/terraform/modules/iam/main.tf @@ -1,5 +1,26 @@ -# À vous de créer : -# 1. Un compte de service pour Terraform -# 2. Une clé pour ce compte de service -# 3. Les rôles IAM nécessaires -# 4. La configuration OS Login avec votre clé SSH \ No newline at end of file +# SERVICE ACCOUNT + +resource "google_service_account" "sa" { + account_id = var.service_account_id + display_name = var.service_account_display_name +} + + +# CUSTOM ROLE (optionnel) + +resource "google_project_iam_custom_role" "custom_role" { + role_id = var.custom_role_id + title = var.custom_role_title + description = var.custom_role_description + permissions = var.custom_role_permissions + project = var.project_id +} + + +# IAM BINDING : attache le rôle custom au service account + +resource "google_project_iam_member" "sa_role_binding" { + project = var.project_id + role = google_project_iam_custom_role.custom_role.name + member = "serviceAccount:${google_service_account.sa.email}" +} diff --git a/terraform/modules/iam/outputs.tf b/terraform/modules/iam/outputs.tf index c73acc0..78f0813 100644 --- a/terraform/modules/iam/outputs.tf +++ b/terraform/modules/iam/outputs.tf @@ -1,3 +1,9 @@ -# À vous d'exposer : -# 1. L'email du compte de service -# 2. La clé du compte de service (sensitive = true) \ No newline at end of file +output "service_account_email" { + description = "Email du service account créé" + value = google_service_account.sa.email +} + +output "custom_role_name" { + description = "Nom du rôle IAM personnalisé" + value = google_project_iam_custom_role.custom_role.name +} diff --git a/terraform/modules/iam/variables.tf b/terraform/modules/iam/variables.tf index 5ac1614..a0a5e4a 100644 --- a/terraform/modules/iam/variables.tf +++ b/terraform/modules/iam/variables.tf @@ -1,2 +1,34 @@ -# À vous de définir : -# - project_id (string) \ No newline at end of file +variable "project_id" { + description = "ID du projet GCP" + type = string +} + +variable "service_account_id" { + description = "Identifiant du service account (ex: my-sa)" + type = string +} + +variable "service_account_display_name" { + description = "Nom affiché du service account" + type = string +} + +variable "custom_role_id" { + description = "ID du rôle personnalisé" + type = string +} + +variable "custom_role_title" { + description = "Titre du rôle personnalisé" + type = string +} + +variable "custom_role_description" { + description = "Description du rôle personnalisé" + type = string +} + +variable "custom_role_permissions" { + description = "Permissions du rôle personnalisé" + type = list(string) +}