Skip to content
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

Don't run a terraform destroy if there are no resources to clean up #1187

Open
KashifSaadat opened this issue Jan 17, 2024 · 1 comment · Fixed by #1194
Open

Don't run a terraform destroy if there are no resources to clean up #1187

KashifSaadat opened this issue Jan 17, 2024 · 1 comment · Fixed by #1194

Comments

@KashifSaadat
Copy link
Member

Sometimes when creating a Configuration resource, the module it is pointing to may be invalid for whatever reason causing the plan to fail. If you then attempt to delete the Configuration resource before fixing the module (to get a successful plan), then the terraform destroy action would also fail for the same reason. This leaves the Configuration resource stuck in a Deleting state and means you need to either:

  • Drop the finalizer to get rid of the object (not recommended, could orphan objects)
  • Fix the module on the same ref that the Configuration resource is pointing to, and then trigger some modification on the Configuration object so that the destroy action runs again

It would instead be better if Terranetes could analyse the state file, and if there are no resources detected it would clean up without initiating a terraform destroy.

@jon-shanks
Copy link
Member

jon-shanks commented Jan 17, 2024

@KashifSaadat it sounds like the issue is:

  • If resources are trying to be created but fail, then the resource status should also be marked as not ready
  • Resource statuses need to reflect accurately what has happened i.e. the plan failed or the create failed etc.
  • If the plan failed, then there is nothing to technically created we need to understand what type of failure happened:
  • IF the module failed because of some init, then it also means the init will fail even on a destroy
  • we need to handle this properly so that we a user can clean the resource up to rerun an apply

We may need to think through a way of managing something that never got created due to failures and be able to manage it well i.e. do a tf list resources and if it's empty then we can safely clean up forcibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants