Making Terraform destroy Idempotent when using remote state

I have 2 workspaces (workspace_aworkspace_b) in TFC that I plan/apply and destroy as part of GitHub Actions pipeline.

workspace_b uses remote state from workspace_a:
data.terraform_remote_state.workspace_a.outputs.location

First time I run the destroy pipeline: destroy workspace_b followed by destroy workspace_a everything is fine.

However if I re-run the destroy pipeline it fails because terraform cannot lookup the remote state of workspace_a.

What’s the best way to make the pipeline Idempotent so we can re-run destroy without data.terraform_remote_state failing?

Terraform is everything but idempotent. I’ve been struggling with its reliability for a while now, most of its providers suffer from the same. It will only improve if the plugin SDK makes it easier to test and if Terraform Registry makes idempotency a hard requirement.

1 Like