hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.71k stars 9.55k forks source link

Terraform crash when refreshing state #21587

Closed auberta2 closed 5 years ago

auberta2 commented 5 years ago

Terraform Version

Terraform v0.12.0
+ provider.aws v2.13.0
+ provider.random v2.1.2

Terraform Configuration Files

Configuration files have nothing special and were used to run in some other accounts.

Debug Output

https://gist.github.com/auberta2/cb00f2ba24fb85fb475885a8978f49de

Crash Output

https://gist.github.com/auberta2/cb00f2ba24fb85fb475885a8978f49de

Expected Behavior

Terraform refresh of the state should succeed

Actual Behavior

terraform crashes after or during refresh of the state of the resources.

Steps to Reproduce

It crashes on commands like terraform plan, apply, refresh or even destroy. Still, taint command is working

Additional Context

Running on MacOS within a workspace named dev having state remotely managed in S3

References

not as far as I know

jbardin commented 5 years ago

Thanks for filing this issue @auberta2!

This appears to be another case of a missing Current state

The relevant stack trace:

github.com/hashicorp/terraform/terraform.(*evaluationStateData).getResourceInstancesAll(0xc000274a20, 0x4d, 0xc00061d620, 0xc, 0xc00061d630, 0xb, 0xc00058a730, 0xb, 0x16c, 0x1c, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/evaluate.go:704 +0x11a3
github.com/hashicorp/terraform/terraform.(*evaluationStateData).GetResourceInstance(0xc000274a20, 0x4d, 0xc00061d620, 0xc, 0xc00061d630, 0xb, 0x0, 0x0, 0xc00058a730, 0xb, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/evaluate.go:593 +0x1360
github.com/hashicorp/terraform/lang.(*Scope).evalContext(0xc000b66460, 0xc000266218, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x43a6140)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:253 +0xfcc
github.com/hashicorp/terraform/lang.(*Scope).EvalContext(...)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:160
github.com/hashicorp/terraform/lang.(*Scope).EvalExpr(0xc000b66460, 0x2be8580, 0xc0006172c0, 0x2be9880, 0xc0000c636f, 0xa, 0x28565b8, 0x1, 0x10cf0e0, 0xc0000e6693, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:87 +0xb3
github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).EvaluateExpr(0xc00050bc70, 0x2be8580, 0xc0006172c0, 0x2be9880, 0xc0000c636f, 0x0, 0x0, 0x10cfec1, 0xc000134100, 0xc00061d610, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:284 +0x1e4
github.com/hashicorp/terraform/terraform.evaluateResourceCountExpressionKnown(0x2be8580, 0xc0006172c0, 0x2c166c0, 0xc00050bc70, 0xc000c7db10, 0x145c3d1, 0x27b9803, 0x5, 0xc000c7daf0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_count.go:55 +0xac
github.com/hashicorp/terraform/terraform.evaluateResourceCountExpression(0x2be8580, 0xc0006172c0, 0x2c166c0, 0xc00050bc70, 0xc000c7db90, 0x80, 0x3b524e0, 0x436e928)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_count.go:28 +0x67
github.com/hashicorp/terraform/terraform.(*NodeRefreshableManagedResource).DynamicExpand(0xc0000b6938, 0x2c166c0, 0xc00050bc70, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/node_resource_refresh.go:36 +0x8a
auberta2 commented 5 years ago

The stack trace looks much similar you're right. Any known workaround waiting for a fix ?

auberta2 commented 5 years ago

Upon investigation of the logs, I could workaround the bug by running : terraform state rm aws_instance.backend-win

where backend-win was a collection of EC2 instances with a variable based count property

jbardin commented 5 years ago

closed by #21979

ghost commented 5 years ago

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.