# À vous de créer :
# 1. Un compte de service pour Terraform
# 2. Une clé pour ce compte de service
# 3. Les rôles IAM nécessaires
# 4. La configuration OS Login avec votre clé SSH




resource "google_service_account" "my_account" {
    display_name = "terraform"
    account_id = "terraform"

}

resource "google_service_account_key" "key" {
    service_account_id = google_service_account.my_account.name
    public_key_type = "TYPE_X509_PEM_FILE"
}

resource "google_project_iam_binding" "project_iam" {
    project = var.project_id
    role = "roles/viewer"
    members = [
        "serviceAccount:${google_service_account.my_account.email}",
        ]
    depends_on = [ google_service_account.my_account ]
}


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")
}
