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

Cannot remove modules from state. Error: leftover module #23859

Closed
deobieta opened this issue Jan 14, 2020 · 6 comments
Closed

Cannot remove modules from state. Error: leftover module #23859

deobieta opened this issue Jan 14, 2020 · 6 comments

Comments

@deobieta
Copy link

deobieta commented Jan 14, 2020

Terraform Version

Terraform v0.12.19

Terraform Configuration Files

provider "aws" {
  region = "us-east-1"
}

data "aws_vpc" "default" {
  default = true
}

module "security_group_example_http" {
  source = "terraform-aws-modules/security-group/aws//modules/http-80"
  name        = "web-server"
  version = "3.3.0"
  vpc_id      = data.aws_vpc.default.id
  ingress_cidr_blocks = ["0.0.0.0/0"]
}

Debug Output

Crash Output

Expected Behavior

Terraform should delete module resources and remove them from state.

Actual Behavior

Terraform deletes the resources but leaves the state file with information about the deleted modules. This causes CI systems to break.

Error: leftover module module.security_group_example_http.module.sg in state that should have been removed; this is a bug in Terraform and should be reported

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Remove module security_group_example_http
  4. terraform apply

Additional Context

I did the same steps using version v0.12.18 and it works as expected.

References

The issue #22579 states that "-target" should be used in the "apply" to reproduce but it seems that it's a bigger problem now.

@deobieta
Copy link
Author

If you run into this problem you can fix manually the state file following this steps:

  1. terraform state pull > pulled-tfstate.json
  2. Edit pulled-tfstate.json, delete all references to the deleted modules and increment serial number
  3. terraform state push pulled-tfstate.json

@dghubble
Copy link

I've started seeing this in any workspace that upgrades to Terraform v0.12.19 :S

@dghubble
Copy link

#23822 appears to fix this issue (haven't verified myself) and was merged after v0.12.19, so I imagine it will appear in v0.12.20.

@hashibot
Copy link
Contributor

Hello! 🤖

Duplicate of #23821

@deobieta
Copy link
Author

#23822 appears to fix this issue (haven't verified myself) and was merged after v0.12.19, so I imagine it will appear in v0.12.20.

Thanks @dghubble

@ghost
Copy link

ghost commented Mar 6, 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 Mar 6, 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

3 participants