phillbaker / terraform-provider-elasticsearch

An elasticsearch provider for terraform
https://registry.terraform.io/providers/phillbaker/elasticsearch
Mozilla Public License 2.0
306 stars 134 forks source link

Provider does not tolerate destruction of resources outside of Terraform #366

Open erikeckhardt opened 3 months ago

erikeckhardt commented 3 months ago

Problem

In Terraform, if a resource that was created by Terraform and exists in the state file does NOT exist inside the cloud environment, providers are supposed to treat that as a CREATE operation instead of erroring out like so:

Error: elastic: Error 404 (Not Found): [my-es-domain-snapshots] missing [type=repository_missing_exception]

Even deleting the resources from my .tf source code (leaving the provider block in place) did not work, and that should have been treated as a NO-OP.

Solution

Tolerate resources not being present that are listed in the state file.

Specific example: if a repository can't be found, don't blow up. Just create the repository again (or do nothing if the resource is not in the .tf source).

Rationale

Mistakes happen. Cloud resources can be deleted. After such a deletion today for me in a non-prouction environment, the provider throwing this error meant I had to do tfstate surgery to remove the resources myself, and I also had to update the DynamoDb md5 fingerprint entry to match the new hash of the state file. These would be very painful in a production environment.