forked from pierront/but3-iac
iam debut
This commit is contained in:
@@ -34,3 +34,9 @@ module "compute" {
|
||||
backend_subnet_id = module.network.subnet_ids["backend"]
|
||||
database_subnet_id = module.network.subnet_ids["database"]
|
||||
}
|
||||
|
||||
module "iam" {
|
||||
source = "../../modules/iam"
|
||||
project_id = var.project_id
|
||||
ssh_public_key_path = "/home/adriendick18/.ssh/id_ed25519.pub"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
resource "google_service_account" "terraform_sa" {
|
||||
account_id = "terraform"
|
||||
display_name = "Service Account Terraform"
|
||||
}
|
||||
|
||||
resource "google_service_account_key" "terraform_sa_key" {
|
||||
service_account_id = google_service_account.terraform_sa.name
|
||||
public_key_type = "TYPE_X509_PEM_FILE"
|
||||
}
|
||||
|
||||
resource "google_project_iam_binding" "terraform_sa_viewer" {
|
||||
project = var.project_id
|
||||
role = "roles/viewer"
|
||||
|
||||
members = [
|
||||
"serviceAccount:${google_service_account.terraform_sa.email}"
|
||||
]
|
||||
}
|
||||
|
||||
data "google_client_openid_userinfo" "me" {}
|
||||
|
||||
resource "google_os_login_ssh_public_key" "me_ssh_key" {
|
||||
user = data.google_client_openid_userinfo.me.email
|
||||
key = file(var.ssh_public_key_path)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
output "service_account_email" {
|
||||
value = google_service_account.terraform_sa.email
|
||||
}
|
||||
|
||||
output "service_account_key" {
|
||||
value = google_service_account_key.terraform_sa_key.private_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
variable "project_id" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_public_key_path" {
|
||||
type = string
|
||||
description = "Chemin vers la clé publique SSH"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user