Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"activate_api_identities"throwing error that email can't be null #751

Open
katiyuki opened this issue Sep 29, 2022 · 5 comments
Open

"activate_api_identities"throwing error that email can't be null #751

katiyuki opened this issue Sep 29, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers P3 medium priority issues triaged Scoped and ready for work

Comments

@katiyuki
Copy link

TL;DR

I am using "activate_api_identities" with api "cloudfunctions.googleapis.com" so I can create the "appspot" google managed service account, and assign roles to it. terraform plan fails with:

on .terraform/modules/project-factory/modules/project_services/main.tf line 84, in resource "google_project_iam_member" "project_service_identity_roles":"
member = "serviceAccount:${each.value.email}
each.value.email is null
The expression result is null. Cannot include a null value in a string template

Expected behavior

terraform plan to succeed, with use of activate_api_identities", mapping API to roles

Observed behavior

on .terraform/modules/project-factory/modules/project_services/main.tf line 84, in resource "google_project_iam_member" "project_service_identity_roles":"
member = "serviceAccount:${each.value.email}
each.value.email is null
The expression result is null. Cannot include a null value in a string template

Terraform Configuration

variable "activate_api_identities" {
  type = list(object({
    api   = string
    roles = list(string)
  }))
  description = "The list of service identities (Google Managed service account for the API) to force-create for the project (e.g. in order to grant additional roles)."
  default     = []
}

-------
module "project-factory" {
  count   = var.create_project ? 1 : 0
  source  = "terraform-google-modules/project-factory/google"
  version = "13.0.0"
  ...
  activate_api_identities = var.activate_api_identities
}
----------
activate_api_identities = [
  {
    api = "cloudfunctions.googleapis.com"
    roles = [
      "roles/editor",
      "roles/artifactregistry.repoAdmin",
      "roles/cloudbuild.builds.builder",
      "roles/cloudfunctions.invoker",
      "roles/run.serviceAgent",
      "roles/secretmanager.secretAccessor",
      "roles/storage.admin",
      "roles/workflows.invoker"
    ]
  },
  {
    api = "compute.googleapis.com"
    roles = [
      "roles/editor"
    ]
  }
]

Terraform Version

terraform {
  required_version = "~> 1.0"

  backend "gcs" {}
}

Additional information

No response

@katiyuki katiyuki added the bug Something isn't working label Sep 29, 2022
@katiyuki
Copy link
Author

when I removed the "compute.googleapis.com" part in "activate_api_identities" list, terraform plan ran successfully.

why?

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Nov 28, 2022
@bharathkkb
Copy link
Member

@katiyuki this maybe because the compute API does not return the service identity. Usually a way to check if a service supports returns an identity is by running the gcloud command gcloud beta services identity create --service=cloudfunctions.googleapis.com --format json. In this case within the module, I think we should filter out any each.value.email that is null.

@bharathkkb bharathkkb added good first issue Good for newcomers triaged Scoped and ready for work P3 medium priority issues and removed Stale labels Nov 29, 2022
abhikaddy added a commit to abhikaddy/terraform-google-project-factory that referenced this issue Oct 3, 2023
@imrannayer
Copy link
Contributor

It is needed for very few APIs like healthcare etc. There is no way to find which API is supported. It should not be used unless user is aware of the API which needs it.

@imrannayer
Copy link
Contributor

I have added in the variable description that it only APIs which are supported by command gcloud beta services identity create

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers P3 medium priority issues triaged Scoped and ready for work
Projects
None yet
3 participants