In gcp service account had created manually right now i need to add the members to service account through terraform

0 votes
Dec 1, 2020 in Terraform by poorna
• 120 points

recategorized Dec 1, 2020 by MD 1,796 views

1 answer to this question.

0 votes

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

answered Dec 1, 2020 by MD
• 95,460 points

Related Questions In Terraform

0 votes
1 answer

How to import manually created s3 bucket in Terraform?

Hi@akhtar, Terraform will not able to get the ...READ MORE

answered Sep 11, 2020 in Terraform by MD
• 95,460 points
12,673 views
0 votes
1 answer

How to add a DNS record in GCP using Terraform?

Hi@akhtar, You can use the google_dns_managed_zone resource to ...READ MORE

answered Dec 1, 2020 in Terraform by MD
• 95,460 points
2,114 views
0 votes
1 answer

How to add a route for IGW in AWS using Terraform code?

Hi@akhtar, Terraform has one keyword named route. It allows ...READ MORE

answered Jul 22, 2020 in Terraform by MD
• 95,460 points
4,527 views
0 votes
1 answer

How to create a VPC in GCP Cloud using Terraform code?

Hi@akhtar, You can create your own VPC in ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
1,652 views
0 votes
1 answer
0 votes
1 answer

Error:No credentials loaded. To use your gcloud credentials, run 'gcloud auth application-default login'.

Hi@akhtar, You are trying to connect the GCP ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
4,645 views
0 votes
1 answer

How to use GCP provider in Terraform?

Hi@akhtar, Terraform supports many providers to deploy the ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
709 views
0 votes
1 answer

How to launch an instance in GCP using Terraform?

Hi@akhtar, You can use the google_compute_instance resource in ...READ MORE

answered Sep 12, 2020 in Terraform by MD
• 95,460 points
840 views
0 votes
1 answer

How to create a service account in GCP using Terraform?

Hi@akhtar, You can create a service account in ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
2,431 views
0 votes
1 answer

How to create a service account key in GCP Cloud using Terraform?

Hi@akhtar, You need to create a service account ...READ MORE

answered Sep 13, 2020 in Terraform by MD
• 95,460 points
1,677 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP