Terraform: Terraform should clean up state when deposed instances already terminated

Created on 22 Dec 2016  ยท  6Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.8.2

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_instance

Debug Output

```Error applying plan:

3 error(s) occurred:

  • aws_instance.apps (deposed #0): Error terminating instance: InvalidInstanceID.NotFound: The instance ID 'i-b4f898ac' does not exist
    status code: 400, request id: 47dc08fc-78f0-4efc-96d5-2c9d84f7b4a7
  • aws_instance.apps (deposed #0): Error terminating instance: InvalidInstanceID.NotFound: The instance ID 'i-b7f898af' does not exist
    status code: 400, request id: 371d0501-ba5b-43b6-a61a-01a0b4d3ff6c
  • aws_instance.symq (deposed #0): Error terminating instance: InvalidInstanceID.NotFound: The instance ID 'i-86f89e9e' does not exist
    status code: 400, request id: 9ad8ff69-cbe5-47ee-8c7e-19e65e214236
    ```

Expected Behavior

If tf is trying to destroy instances, and those instances don't exist, this should not be a fatal error.

Actual Behavior

TF halted after it couldn't destroy the nonexistent deposed instances.

bug provideaws

Most helpful comment

Experiencing this issue with Terraform v0.11.7 We are currently blocked on missing deposed resources. Is there a way to clean them up manually?

All 6 comments

Hi @kojiromike, and thanks for filing this!

This is an interesting situation... I guess the issue is that Terraform doesn't run the "refresh" action for deposed instances, so it doesn't get the opportunity to detect them as gone and remove them quietly from state.

At first blush it seems like it should be reasonable and safe for Terraform to refresh these just like it does for the primary instances. Presumably the same behavior would be desirable for tainted instances, for the same reason.

I didn't dig deep into the code yet to see how easy such a thing would be to implement. It might require some tweaking of Terraform core to allow the "refresh" result to be written to a non-primary instance in the state, but otherwise it seems pretty straightforward since all of the provider mechanisms are in place to do run these operations.

I'm going to retag this as an AWS issue. I agree with @apparentlymart but it will be a lot more straightforward for the AWS resource to be more robust to handle already-destroyed instances in the destroy step. Other resources are expected to do this.

I'm having this issue also (Terraform 7.7). Could it have anything to do with the increased resource ID length?

Experiencing this issue with Terraform v0.11.7 We are currently blocked on missing deposed resources. Is there a way to clean them up manually?

@teu the cleanest/quickest way I have found to fix this is:

terraform state pull > temp.tfstate
vi temp.tfstate
terraform state push temp.tfstate

the editing manipulation in this case seems pretty straightforward, as there are no ids to alter or other data to add, just stale data to remove - easy to identify looking for "deposed"

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rjinski picture rjinski  ยท  3Comments

rnowosielski picture rnowosielski  ยท  3Comments

shanmugakarna picture shanmugakarna  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments

zeninfinity picture zeninfinity  ยท  3Comments