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

Terraform should clean up state when deposed instances already terminated #445

Closed
hashibot opened this issue Jun 13, 2017 · 14 comments · Fixed by #6978
Closed

Terraform should clean up state when deposed instances already terminated #445

hashibot opened this issue Jun 13, 2017 · 14 comments · Fixed by #6978
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@hashibot
Copy link

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


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.

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@Jared-Stensland
Copy link

Jared-Stensland commented Jul 12, 2017

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:

@jmehnle
Copy link
Contributor

jmehnle commented Aug 10, 2017

And same with aws_ami and aws_ami_from_instance resources.

@practicalint
Copy link

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.

@zzzuzik
Copy link

zzzuzik commented Oct 9, 2017

+1

@jlsjonas
Copy link

jlsjonas commented Nov 8, 2017

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

@kailashverma2402
Copy link

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

@hagurganus
Copy link
Contributor

+1

@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2018
@matti
Copy link

matti commented Feb 4, 2018

thanks @practicalint that worked for me:

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

@seanjfellows
Copy link

+1 this issue is still present in 0.11

@tolgaingenc
Copy link

tolgaingenc commented Jan 2, 2019

@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

@bflad bflad added this to the v1.55.0 milestone Jan 8, 2019
@bflad
Copy link
Contributor

bflad commented Jan 8, 2019

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!

@bflad
Copy link
Contributor

bflad commented Jan 10, 2019

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.

@sriraja53
Copy link

sriraja53 commented Feb 21, 2019

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"

@ghost
Copy link

ghost commented Mar 31, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.