-
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_project_iam_binding & google_project_service incorrect destruction order #1356
Comments
Hi, thanks for the detailed error report. I'm sorry that you had trouble with the google provider, but unfortunately there's not going to be much we can do to make this process less painful. It seems like there are three issues here: Deletion OrderTerraform's deletion order is the reverse of its creation order, which is entirely based on the dependency graph. Unfortunately, cross-resource dependencies of this sort are not expressible in a terraform provider - you need to handle this on your end, ideally by having all your resources transitively depend on IAM's dangerousnessAn IAM policy is extremely dangerous, because without touching the Output warningsI agree with you that that's an unnecessary warning - that issue is best filed with Terraform core because it's not specific to the google provider. |
Deletion OrderThank you for this, I had always assumed terraform had some basic behind the scenes order config such as 'Delete compute resources before permissions resources' etc. In my case I am now using implicit dependencies because there is no dependencies ( IAM' dangerousnessMy case was a combination of not realising that binding was authoritative (which is in the docs) , using the permission in development (spin up and teardown) and ordering as mentioned. Probably easier for you to add to the docs as I'm not setup to contrib atm. Also you can reword / oragnise my comments into something that coherent with the current content. This would be my contribution of a note (or equivalent) to be applied for all three resources.
And I would probably consider adding the same Output warningsI will raise an issue on the main terraform and link back to here when I get around to it. On reflection and actually 'reading' (not scanning) the docs for these resources they make a lot of sense and the warnings are there, perhaps just not as explicitly. I think adding some additional explicit warnings should close off this ticket. The ordering is not 'wrong', its just difficult to get right. |
Our IAM docs have been updated since this was opened, but I tried to apply the spirit of it to #1735. I opted not to call out the dependency ordering info, as that's already covered in the getting started guide for Terraform, so I think it's inappropriate to document it at the provider level. I also worry about losing the forest for the trees in our documentation by being too verbose; after all, a warning to be careful about order of deletion could apply to most our resources, which could return errors if they're not deleted in the proper order. I think that information is better suited in the getting started guide, and that the provider focus on documenting what's unique to the provider. |
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 👉 hashibot-feedback@hashicorp.com. Thanks! |
Terraform Version
Affected Resource(s)
Terraform Configuration Files
The following is an extract but gets the gist for the main issue here:
Debug Output
The plan to destroy:
terraform plan -var-file=inputs.tfvars -out plan -destroy
Apply output
Expected Behavior
The resources
google_project_iam_binding
andgoogle_project_service
should have been the very last resources to be deleted. Ie.google_project_service
google_project_iam_binding
- This has to be last becausegoogle_project_iam_binding
will overwrite the 'owner' role when re-applying terraform. So if you try and add people using this, it will remove owners not provided in here. Hence all owners are assigned using a count with this feature. Including the service account that I use to create the project and everything else.tl;dr -
google_project_iam_binding
overwrites role membership rather than appending. I should have usedgoogle_project_iam_member
insteadActual Behavior
Terraform seemed to go free range and just start deleting things. The two most important resources are deleted first! Which leads to subsequent issues of:
Steps to Reproduce
depends_on
flaws + my infra is all based on various modules. (see my hcl example for reference)Important Factoids
IAM
I initially only used
google_project_iam_binding
to add owners (I did not use the service account in here). However after creation of the project and adding this permission, I tried to reapply and noticed that it was going to remove the service account, and add the new permissions instead.Hence why in this scenario, I added the service account into this object (using count) as well as the additional members.
I used
google_project_iam_binding
rather thangoogle_project_iam_policy
explicitly because I noted this warning:Obviously it seems you can also lock yourself out with the
google_project_iam_binding
resource if not used correctly (I'm guessing there are some simple tricks to avoid what I have done). Perhaps the warning should be for all resources as I assumed it was specific topolicy
.Outputs
There's also an error there around a data object:
Perhaps this might indicate an ordering issue or issue with data objects. In my case the data object is used post nope_pool creation. This is to trap all instance_group_urls.
I actually don't care about this during destruction. I can't think of a scenario where I would be. I've had this issue a little while and usually something like
export TF_WARN_OUTPUT_ERRORS=1
will ignore this - but the default behaviour in this scenario I think should be just to ignore the output entirely. Im destroying it, which should mean 'I accept there's not going to be an output because there will be no data when the cluster is destroyed'.It looks like its trying to get data on something its destroyed in in the process of destroying. Perhaps the simple fix is to add a flag to not lookup data object on destroy?
My Modules
My modules all work when used inside a project and giving the code for that means much more copy paste. And it doesn't add anything particular to this issue.
References
#1292 - Slightly related in the discussion about how dependency on deletion is formed.
service
andiam_member
resources both seem to get deleted early on.The text was updated successfully, but these errors were encountered: