2025-12-03 16:11:01 +00:00
|
|
|
resource "google_service_account" "terraform_sa" {
|
2025-12-04 08:58:12 +00:00
|
|
|
account_id = "terraform"
|
2025-12-03 16:11:01 +00:00
|
|
|
project = var.project_id
|
|
|
|
|
display_name = "Terraform Service Account"
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-04 08:58:12 +00:00
|
|
|
|
2025-12-03 16:11:01 +00:00
|
|
|
resource "google_service_account_key" "terraform_sa_key" {
|
|
|
|
|
service_account_id = google_service_account.terraform_sa.name
|
2025-12-04 08:58:12 +00:00
|
|
|
private_key_type = "TYPE_GOOGLE_CREDENTIALS_FILE" //TYPE_X509_PEM_FILE fonctionne pas
|
2025-12-03 16:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 08:58:12 +00:00
|
|
|
|
|
|
|
|
resource "google_project_iam_binding" "viewer_binding" {
|
2025-12-03 16:11:01 +00:00
|
|
|
project = var.project_id
|
2025-12-04 08:58:12 +00:00
|
|
|
role = "roles/viewer"
|
|
|
|
|
|
|
|
|
|
members = [
|
|
|
|
|
"serviceAccount:${google_service_account.terraform_sa.email}"
|
|
|
|
|
]
|
2025-12-03 16:11:01 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-04 08:58:12 +00:00
|
|
|
data "google_client_openid_userinfo" "me" {}
|
|
|
|
|
|
2025-12-03 16:11:01 +00:00
|
|
|
resource "google_os_login_ssh_public_key" "ssh_key" {
|
|
|
|
|
project = var.project_id
|
2025-12-04 08:58:12 +00:00
|
|
|
user = data.google_client_openid_userinfo.me.email
|
|
|
|
|
key = file(pathexpand("~/.ssh/id_ed25519.pub"))
|
2025-12-03 16:11:01 +00:00
|
|
|
}
|
2025-12-04 08:58:12 +00:00
|
|
|
|
2025-12-04 09:41:31 +00:00
|
|
|
resource "google_project_iam_custom_role" "custom_viewer" {
|
|
|
|
|
role_id = "customBasicViewer"
|
|
|
|
|
title = "Custom Basic Viewer"
|
|
|
|
|
project = var.project_id
|
|
|
|
|
description = "Role custom pour TP"
|
|
|
|
|
|
|
|
|
|
permissions = [
|
|
|
|
|
"compute.instances.get",
|
|
|
|
|
"compute.instances.list",
|
|
|
|
|
]
|
|
|
|
|
}
|