Hi@poorna,
You can find one resource named google_service_account_iam_member in Terraform. This resource is used to assign users to a service account. You can use the below script as well.
data "google_compute_default_service_account" "default" {
}
resource "google_service_account" "sa" {
account_id = "my-service-account"
display_name = "A service account that Jane can use"
}
resource "google_service_account_iam_member" "admin-account-iam" {
service_account_id = google_service_account.sa.name
role = "roles/iam.serviceAccountUser"
member = "user:jane@example.com"
}
# Allow SA service account use the default GCE account
resource "google_service_account_iam_member" "gce-default-account-iam" {
service_account_id = data.google_compute_default_service_account.default.name
role = "roles/iam.serviceAccountUser"
member = "serviceAccount:${google_service_account.sa.email}"
}
You can also go through the official document of Terraform for better understanding.
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account_iam