$ terraform -v
Terraform v0.12.10
+ provider.google v2.17.0
$ cat test.tf
variable "container_view_groups" {
description = "Groups that are GKE Viewers"
type = list(string)
}
resource "google_project_iam_binding" "container-viewer" {
project = "uwit-mci-0001"
role = "roles/container.viewer"
members = formatlist("%s:%s", "group", var.container_view_groups)
}
provider "google" {
version = "~> 2.17.0"
credentials = file("../../.secrets/credential_file")
}
$ cat terraform.tfvars
container_view_groups = [
"[email protected]"
]
Trace output from step 4 of recreation steps below
https://gist.github.com/EricHorst/f7cea376a8a8a55d4e62a32585bf4a82
Manually removed google_project_iam_binding should be recreated.
When a role binding exists and all members are removed, leaving no users bound to that role, then Terraform does not detect it and recreate.
However, if the binding has multiple members and only one is removed, leaving at least one member, then Terraform detects the removed member and re-adds it. (This is not demonstrated here.)
$ terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# google_project_iam_binding.container-viewer will be created
+ resource "google_project_iam_binding" "container-viewer" {
+ etag = (known after apply)
+ id = (known after apply)
+ members = [
+ "group:[email protected]",
]
+ project = "uwit-mci-0001"
+ role = "roles/container.viewer"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
google_project_iam_binding.container-viewer: Creating...
google_project_iam_binding.container-viewer: Still creating... [10s elapsed]
google_project_iam_binding.container-viewer: Creation complete after 16s [id=uwit-mci-0001/roles/container.viewer]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
$ gcloud projects get-iam-policy uwit-mci-0001 --flatten=bindings --filter="bindings.role:roles/container.viewer"
---
bindings:
members:
- group:[email protected]
role: roles/container.viewer
etag: BwWU6FuJJ3E=
version: 1
$ gcloud projects remove-iam-policy-binding uwit-mci-0001 --member=group:[email protected] --role=roles/container.viewer
$ gcloud projects get-iam-policy uwit-mci-0001 --flatten=bindings --filter="bindings.role:roles/container.viewer"
Listed 0 items.
google_project_iam_binding.container-viewer: Refreshing state... [id=uwit-mci-0001/roles/container.viewer]
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
```
Nothing atypical. Executing as a Google service account.
Found the cause of this, and have a possible fix.
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!
Most helpful comment
Found the cause of this, and have a possible fix.