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 doesn't cleanup resources from state file #24130

Closed
estahn opened this issue Feb 17, 2020 · 2 comments
Closed

terraform doesn't cleanup resources from state file #24130

estahn opened this issue Feb 17, 2020 · 2 comments

Comments

@estahn
Copy link

estahn commented Feb 17, 2020

Terraform Version

Terraform v0.12.18
+ provider.aws v2.36.0
+ provider.kubernetes v1.10.0
+ provider.mysql v1.9.0
+ provider.random v2.2.1

Expected Behavior

Terraform should clean up removed modules from the state file.

Actual Behavior

After removing the module from the .tf file, terraform is leaving the following entry in the state file:

    {
      "module": "module.app-db-user-notmidship-unified-api",
      "mode": "managed",
      "type": "mysql_grant",
      "name": "default",
      "each": "list",
      "provider": "provider.mysql.notmidship",
      "instances": []
    },

This will cause the following error message on every run:

Error: Missing required argument

The argument "endpoint" is required, but was not set.


Error: Missing required argument

The argument "username" is required, but was not set.

Workaround

  • terraform state pull > terraform.tfstate
  • jq '.resources[] | select(.instances | length == 0)' terraform.tfstate
  • Manually remove resources from terraform.tfstate
  • terraform state push -force terraform.tfstate
@hashibot
Copy link
Contributor

Hello! 🤖

This issue seems to be covering the same problem or request as #23821, so we're going to close it just to consolidate the discussion over there. Thanks!

@ghost
Copy link

ghost commented Apr 1, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants