-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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_bigquery_dataset_iam_member doesn't handle deleted members #7896
Comments
@joerayme can you provide the config along with the repro steps? |
Hi @joerayme, here are the steps to reproduce it:
terraform {
required_version = ">= 0.13"
required_providers {
google = "~> 3.49.0"
google-beta = "~> 3.49.0"
}
}
resource "google_service_account" a_service_account {
account_id = "a-service-account"
}
resource "google_service_account" another_service_account {
account_id = "another-service-account"
}
resource "google_bigquery_dataset" a_dataset {
dataset_id = "a_dataset"
location = "US"
}
locals {
service_accounts = [
google_service_account.a_service_account.email,
google_service_account.another_service_account.email,
]
}
resource google_bigquery_dataset_iam_member "reader" {
for_each = toset(local.service_accounts)
dataset_id = google_bigquery_dataset.a_dataset.dataset_id
member = "serviceAccount:${each.key}"
role = "roles/bigquery.dataViewer"
}
terraform {
required_version = ">= 0.13"
required_providers {
google = "~> 3.49.0"
google-beta = "~> 3.49.0"
}
}
resource "google_service_account" a_service_account {
account_id = "a-service-account"
}
// I DELETED THIS MANUALLY
//resource "google_service_account" another_service_account {
// account_id = "another-service-account"
//}
resource "google_bigquery_dataset" a_dataset {
dataset_id = "a_dataset"
location = "US"
}
locals {
service_accounts = [
// google_service_account.a_service_account.email,
// google_service_account.another_service_account.email,
]
}
resource google_bigquery_dataset_iam_member "reader" {
for_each = toset(local.service_accounts)
dataset_id = google_bigquery_dataset.a_dataset.dataset_id
member = "serviceAccount:${each.key}"
role = "roles/bigquery.dataViewer"
} The diff of
However, when applying changes I get this error:
Interesting enough, the bug doesn't seem to happen if using two separate |
@ralbertazzi is this the same issue as @joerayme originally reported? As you mentioned, this can't be repro by using two separate resources. The issue is likely beyond the provider plugin, which is in the area about how to use the By introducing the dynamic code & variables, basically you break the relationship between resources. Have you tried by adding |
@edwardmedia which explicit dependency should I define in By the way, we have this problem in a project in which we assign permissions to many service accounts from other projects. This means that if somebody in project B deletes a service account, our Terraform definition in project A (the one with Could the issue be related to the Terraform provider not being able to correctly parse |
I've added more detailed steps to reproduce the problem I encountered in the original issue above ☝️ I think it's probably a simpler version of @ralbertazzi 's. The issue here is when changes are made that are outside of perfectly-written Terraform which is managing both the service account and the full IAM policy of the bigquery (and possibly other types) resource. Let me know if that makes sense. |
@joerayme on a side note, I also think that this will fail in the context of this toy example, but that could be a separate issue:
The reason why you want to perform step 5 (i.e. reassign the permission) is that GCP internally trackes IAM using service account IDs, which are unique even across re-creation of a seervice account with the same name. But, when applying, I think that GCP will complain about the unfeasible existence of both the deleted and the new member in the IAM policy, which is refused. To make it work you first have to remove the |
@ralbertazzi this is not the use case for Terraform. You should try to avoid manual updating resources. If you have to, you may run |
@edwardmedia unfortunately this happens in our organization. We usually have one Terraform configuration per project, but in some projects we assign IAM roles to service accounts from other projects (i.e. managed in another Terraform configuration), which means that we don't have full visibility of what happens in other projects. |
@joerayme @ralbertazzi up to now, I don't see anything breaks in the provider plugin. Closing the issue then. Feel free to reopen the issue if you need further conversation. Thank you |
@joerayme what if we are tracking some dataset permissions with
|
Exactly. This exact issue has cropped up for us; it's why I opened the ticket. Things happen and my Terraform shouldn't break because someone accidentally deleted a service account or even offboarded a member of staff that's managed by some other bit of Terraform. Deleted members are handled elsewhere and a bug related to this was even opened pre-emptively (#7278) so I don't see why this should be any different. |
Oops, I meant to tag @edwardmedia instead 😄 but yes, that's my concern. |
@edwardmedia GCP added the
I think that the error |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Community Note
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 tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
Debug Output
gist showing the output after the apply confirmation has been given: https://gist.github.com/joerayme/0f9ec66b4db461eece6690ceee0879e5
Panic Output
Expected Behavior
It should have ignored the deleted user
Actual Behavior
It failed to correctly manage the BigQuery dataset IAM policy with the following error:
Steps to Reproduce
terraform apply
(ignore the error you get from thegoogle_bigquery_dataset_iam_member
, that's because we're usinguser
instead ofserviceAccount
which is incorrect TF code, but it's useful to demonstrate this bug)account_id
attribute ofgoogle_service_account.test_service_account
to something else (e.g.test-bigquery-2
)terraform apply
againImportant Factoids
References
The text was updated successfully, but these errors were encountered: