forked from pierront/but3-iac
ajout iam
This commit is contained in:
@@ -1,5 +1,26 @@
|
|||||||
# À vous de créer :
|
# SERVICE ACCOUNT
|
||||||
# 1. Un compte de service pour Terraform
|
|
||||||
# 2. Une clé pour ce compte de service
|
resource "google_service_account" "sa" {
|
||||||
# 3. Les rôles IAM nécessaires
|
account_id = var.service_account_id
|
||||||
# 4. La configuration OS Login avec votre clé SSH
|
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}"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
# À vous d'exposer :
|
output "service_account_email" {
|
||||||
# 1. L'email du compte de service
|
description = "Email du service account créé"
|
||||||
# 2. La clé du compte de service (sensitive = true)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,2 +1,34 @@
|
|||||||
# À vous de définir :
|
variable "project_id" {
|
||||||
# - project_id (string)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user