Terraform-provider-aws: Terraform should clean up state when deposed instances already terminated

Created on 13 Jun 2017  ยท  14Comments  ยท  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @kojiromike as hashicorp/terraform#10905. It was migrated here as part of the provider split. The original body of the issue is below._


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 servicec2

Most helpful comment

I struggled over what the work-around is for this. A state refresh doesn't help. I finally did a state list to get the exact name of the instance in the state and then did a state rm (remove) for that instance and could finally move on.

All 14 comments

I am experiencing this same thing with aws_nat_gateway resources which no longer exists. After failing to delete the non-existent NAT resource it times out.

* aws_nat_gateway.nat.1 (deposed #0): Error waiting for NAT Gateway (nat-0a6dd2ef5cdc789f8) to delete: %!s(<nil>)
* module.network.module.private_subnet.aws_route_table.private[1]: 1 error(s) occurred:

And same with aws_ami and aws_ami_from_instance resources.

I struggled over what the work-around is for this. A state refresh doesn't help. I finally did a state list to get the exact name of the instance in the state and then did a state rm (remove) for that instance and could finally move on.

+1

This state happens when tf fails on a missing ssh keypair

Error: Error applying plan:

1 error(s) occurred:

* aws_instance.ecs: 1 error(s) occurred:

* aws_instance.ecs: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'invalid-keypair-name' does not exist
    status code: 400, request id: 2516997c-6384-4d95-8262-7c5333e3b3fb

causes a


Error: Error applying plan:

1 error(s) occurred:

* aws_instance.ecs: 1 error(s) occurred:

* aws_instance.ecs: InvalidInstanceID.NotFound: The instance ID 'i-061782cf8f1e068d9' does not exist
    status code: 400, request id: a16464ff-d296-4b88-ab19-d53388dc703f

on the next terraform apply

+1
getting same issue while terraform apply. gettimg error that instance does not exist.

+1

thanks @practicalint that worked for me:

$ terraform state ls
...
$ terraform state rm google_compute_image.ubuntu

+1 this issue is still present in 0.11

@practicalint @matti Removing the state may cause other problems if you already created the new resource.
I have changed the state file:

terraform state pull > temp.state

Cleared deposed section,
do a vi temp.state
so changed this

                    "deposed": [
                        {
                            "id": "YOUR_ID_*************************",
                            "attributes": {
                            .........................................................
                            .........................................................
                            .........................................................
                        }
                    ],

to this:
"deposed": [],

finally pushed the state

terraform state push temp.state

It fixed the deposed problem with no side effect

The fix for the original issue of the aws_instance resource returning the Error terminating instance: InvalidInstanceID.NotFound error has been merged and will release with version 1.55.0 of the Terraform AWS provider, likely in the next two days.

For issues with other resources or error messages, please open new issues filling out the issue template so we can properly triage. Thanks!

The fix for the original issue has been released in version 1.55.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

next

I also have the same issue InvalidInstanceID.NotFound: The instance ID 'i-XXXXXX' does not exist

Terraform v0.11.10

  • provider.aws: version = "~> 1.59"

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. Thanks!

Was this page helpful?
0 / 5 - 0 ratings