terraform-provider-google: google_bigquery_dataset_iam_member doesn't handle deleted members
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-magicianuser, 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
Terraform v0.13.5
+ provider registry.terraform.io/hashicorp/google v3.48.0
+ provider registry.terraform.io/hashicorp/google-beta v3.48.0
Affected Resource(s)
- google_bigquery_dataset_iam_member
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:
Error: Error applying IAM policy for Bigquery Dataset <account>/<dataset>: Failed to parse BigQuery Dataset IAM member type: deleted:serviceAccount:<service-account>@<account>.iam.gserviceaccount.com?uid=100543859842954111727
Steps to Reproduce
provider "google" {
version = "~> 3.49.0"
}
resource "google_bigquery_dataset" "test_dataset" {
dataset_id = "test_dataset"
friendly_name = "test_dataset"
description = "this is a test dataset"
location = "europe-west2"
}
resource "google_service_account" "test_service_account" {
account_id = "test-bigquery"
}
resource "google_bigquery_dataset_iam_member" "service_account" {
dataset_id = google_bigquery_dataset.test_dataset.dataset_id
role = "roles/bigquery.dataOwner"
member = "user:${google_service_account.test_service_account.email}"
}
terraform apply(ignore the error you get from thegoogle_bigquery_dataset_iam_member, that’s because we’re usinguserinstead ofserviceAccountwhich is incorrect TF code, but it’s useful to demonstrate this bug)- Change the
account_idattribute ofgoogle_service_account.test_service_accountto something else (e.g.test-bigquery-2) terraform applyagain
Important Factoids
References
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 18
Hi @joerayme, here are the steps to reproduce it:
google_bigquery_dataset_iam_member(in the example below I had to create thegoogle_bigquery_dataset_iam_memberresources after applying other resources to avoid the Terraform error: The “for_each” value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created.)The diff of
terraform applyis correct:However, when applying changes I get this error:
Interesting enough, the bug doesn’t seem to happen if using two separate
google_bigquery_dataset_iam_memberresources (i.e. not using thefor_each)@edwardmedia GCP added the
deleted:prefix after a change in September 14, 2020. This was quite an important change as people received information about it by email. These are some interesting parts from the email that I received at that time:I think that the error
Failed to parse BigQuery Dataset IAM member type: deleted:serviceAccount:<service-account>@<account>.iam.gserviceaccount.comis a clear indication that action needs to be taken in the provider to be compliant with Google’s guidelinesExactly. 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.
@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
deleted:entry from the IAM policy than apply the new one.