I run following terraform. I made a mistake of using google_storage_bucket_iam_policy
instead of google_storage_bucket_iam_binding
so instead of adding new policy, it replaced all of existing policy.
data "google_iam_policy" "deploy-script-admin-policy" {
binding {
role = "roles/storage.objectAdmin"
members = [
"serviceAccount:${google_service_account.deploy-script.email}",
]
}
}
# deploy script can read/write to a bucket
resource "google_storage_bucket_iam_policy" "policy" {
bucket = "my-bucket"
policy_data = data.google_iam_policy.deploy-script-admin-policy.policy_data
}
Now I cannot run terraform plan because I lost access to my own bucket. I get error message like <my email> does not have storage.buckets.get access to the Google Cloud Storage bucket., forbidden
.
I went to GCP console and tried to either delete or update permission of this bucket but it won't work either since bucket permission doesn't allow it (I have owner and storage.admin role).
How can I recover from this situation? I don't mind deleting the bucket if that's the only option.
EDIT: I don't know what happened, but maybe GCP has some way of auto-recover from such situation. For some reason I was able to edit bucket again from console after a while...