ajout iam

This commit is contained in:
2025-12-04 10:56:55 +01:00
parent 267629f179
commit afe8f23f95
4 changed files with 54 additions and 50 deletions

View File

@@ -34,4 +34,9 @@ module "compute" {
frontend_subnet_id = module.network.subnets.frontend
backend_subnet_id = module.network.subnets.backend
database_subnet_id = module.network.subnets.database
}
module "iam" {
source ="../../modules/iam"
project_id = var.peoject_id
}

View File

@@ -0,0 +1,28 @@
output "ip_internes" {
value = module.compute.ip_internes
}
output "ip_public_frontend" {
value = module.compute.ip_public_frontend
}
output "nom_instances" {
value = module.compute.nom_instances
}
output "service_account_email" {
value = module.iam.service_account_email
}
output "service_account_key" {
sensitive = true
value = module.iam.service_account_key
}
output "vpc" {
value = module.network.vpc
}
output "subnets" {
value = module.network.subnets
}

View File

@@ -1,26 +1,27 @@
# SERVICE ACCOUNT
resource "google_service_account" "sa" {
account_id = var.service_account_id
display_name = var.service_account_display_name
resource "google_service_account" "service_account" {
account_id = "terraform"
display_name = "terraform"
}
# 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
resource "google_service_account_key" "mykey" {
service_account_id = google_service_account.service_account.name
public_key_type = "TYPE_X509_PEM_FILE"
}
# IAM BINDING : attache le rôle custom au service account
resource "google_project_iam_member" "sa_role_binding" {
resource "google_project_iam_binding" "custom_service_account" {
project = var.project_id
role = google_project_iam_custom_role.custom_role.name
member = "serviceAccount:${google_service_account.sa.email}"
role = "roles/viewer"
members = [
"serviceAccount:${google_service_account.service_account.email}",
]
}
data "google_client_openid_userinfo" "me" {
}
resource "google_os_login_ssh_public_key" "cache" {
user = data.google_client_openid_userinfo.me.email
project = var.project_id
key = file("~/.ssh/id_ed25519.pub")
}

View File

@@ -2,33 +2,3 @@ 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)
}