forked from pierront/but3-iac
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
This commit is contained in:
36
terraform/modules/iam/main.tf
Normal file
36
terraform/modules/iam/main.tf
Normal file
@@ -0,0 +1,36 @@
|
||||
# iam/main.tf
|
||||
|
||||
# 1. Compte de service pour Terraform
|
||||
resource "google_service_account" "terraform_sa" {
|
||||
account_id = "terraform-sa"
|
||||
display_name = "Terraform Service Account"
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
# 2. Clé pour ce compte de service
|
||||
resource "google_service_account_key" "terraform_sa_key" {
|
||||
service_account_id = google_service_account.terraform_sa.id
|
||||
public_key_type = "TYPE_X509_PEM_FILE"
|
||||
}
|
||||
|
||||
# 3. Rôles IAM nécessaires
|
||||
resource "google_project_iam_member" "terraform_sa_roles" {
|
||||
for_each = toset([
|
||||
"roles/compute.admin",
|
||||
"roles/iam.serviceAccountUser",
|
||||
"roles/oslogin.admin",
|
||||
"roles/viewer"
|
||||
])
|
||||
|
||||
project = var.project_id
|
||||
role = each.value
|
||||
member = "serviceAccount:${google_service_account.terraform_sa.email}"
|
||||
}
|
||||
|
||||
# 4. Configuration OS Login avec clé SSH
|
||||
resource "google_os_login_ssh_public_key" "terraform_sa_ssh" {
|
||||
username = "terraform"
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
15
terraform/modules/iam/outputs.tf
Normal file
15
terraform/modules/iam/outputs.tf
Normal file
@@ -0,0 +1,15 @@
|
||||
# iam/outputs.tf
|
||||
|
||||
# 1. Email du compte de service
|
||||
output "service_account_email" {
|
||||
description = "Email du compte de service Terraform"
|
||||
value = google_service_account.terraform_sa.email
|
||||
}
|
||||
|
||||
# 2. Clé du compte de service (sensitive)
|
||||
output "service_account_key" {
|
||||
description = "Clé privée du compte de service Terraform"
|
||||
value = google_service_account_key.terraform_sa_key.private_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
7
terraform/modules/iam/variables.tf
Normal file
7
terraform/modules/iam/variables.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
# iam/variables.tf
|
||||
|
||||
variable "project_id" {
|
||||
description = "ID du projet GCP"
|
||||
type = string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user