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

google_service_account expects <project-id>, google_project output gives project/<project-id> #9623

Closed
arivictor opened this issue Jul 23, 2021 · 4 comments
Assignees
Labels

Comments

@arivictor
Copy link

arivictor commented Jul 23, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.0.3
+ provider registry.terraform.io/hashicorp/google v3.76.0

Affected Resource(s)

  • google_project
  • google_service_account

Potentially others that expect project ID to be a certain format that conflicts with what the project resource outputs.

Terraform Configuration Files

resource "google_service_account" "service-account" {
  account_id = "example"
  project    = google_project. example.id # .id returns projects/xxxxx
}

resource "google_project" "example" {
  name       = "example"
  project_id = "example"
}

Expected Behavior

I expect google_service_account to accept the output format of .id from google_project. Or I would expect google_project's .id attribute to return just the project ID without any prepended text.

Actual Behavior

google_project's .id attribute returns the project ID with projects/ prepended. This is not accepted by google_service_account. Terraform errors as the url is malformed:

<p>The requested URL <code>/v1/projects/projects/example/serviceAccounts?alt=json&amp;prettyPrint=false</code>

As you can see it prepends projects/ to the input which already has projects/<project-id>.

want: /v1/projects/example/serviceAccounts
got: /v1/projects/projects/example/serviceAccounts

Steps to Reproduce

  1. Configure a project
resource "google_project" "example" {
  name       = "example"
  project_id = "example"
}
  1. Configure a service account in that project
resource "google_service_account" "service-account" {
  account_id = "example"
  project    = google_project.example.id
}
  1. Apply
terraform apply

Important Factoids

  1. Can use the projects .number attribute but this forces a replacement on apply and then eventually errors and causes a bug.
  2. Current workaround is using replace(google_project.example.id, "projects/", ""). Ideally id would be just id.
@arivictor arivictor added the bug label Jul 23, 2021
@edwardmedia
Copy link
Contributor

@arivictor id is more a global identifier. Here is the doc that might be helpful to follow. There could be exceptions.

Does below name or project_id work for you?

resource "google_service_account" "service-account" {
  account_id = "example"
  project    = google_project.example.name 
  # project    = google_project.example.project_id 
}

@edwardmedia
Copy link
Contributor

@arivictor is this still an issue?

@edwardmedia
Copy link
Contributor

@arivictor closing assuming this is no longer an issue

@github-actions
Copy link

github-actions bot commented Sep 4, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants