Search code examples
terraformterraform-provider-gcp

how can we add project number from variable in terraform gcp resource iam binding


Below is my terraform resource. how can we add project number from variable in terraform gcp resource iam binding because if i will run same terraform for other account, i have to change it manually.

resource "google_project_iam_binding" "project" {
  project = var.projectid
  role    = "roles/container.admin"

  members = [
    "serviceAccount:[email protected]",
  ]
}

Solution

  • The project number is found in the google_project data-source.

    So when this one is added:

    data "google_project" "project" {}
    

    it should be accessible using:

    data.google_project.project.number