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

panic when applying a saved plan file created with "terraform plan -destroy -out=tfplan" #19149

Closed
apparentlymart opened this issue Oct 20, 2018 · 2 comments · Fixed by #19726

Comments

@apparentlymart
Copy link
Contributor

Terraform Version

Terraform v0.12.0-alpha1

Crash Output

aws_subnet.all[1]: Destroying... [id=subnet-050215c1492df555c]
aws_subnet.all[2]: Destroying... [id=subnet-0079c70f5e936a9a9]
aws_subnet.all[0]: Destroying... [id=subnet-0fe6fb156f4d13209]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x7248f2]

goroutine 78 [running]:
github.com/zclconf/go-cty/cty.Type.Equals(0x0, 0x0, 0x37855e0, 0xc0002d00d8, 0x200)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type.go:39 +0x22
github.com/zclconf/go-cty/cty.testConformance(0x0, 0x0, 0x37855e0, 0xc0002d00d8, 0xc000868630, 0x0, 0x0, 0xc000868630)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type_conform.go:37 +0xae
github.com/zclconf/go-cty/cty.Type.TestConformance(0x0, 0x0, 0x37855e0, 0xc0002d00d8, 0x37855e0, 0xc0002d00d8, 0xc0008686b8)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type_conform.go:27 +0x7a
github.com/zclconf/go-cty/cty/msgpack.Marshal(0x0, 0x0, 0x0, 0x0, 0x37855e0, 0xc0002d00d8, 0xc0005c2000, 0x144, 0x193, 0x0, ...)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/msgpack/marshal.go:19 +0x67
github.com/hashicorp/terraform/plugin.(*GRPCProvider).ApplyResourceChange(0xc0002dc900, 0xc0002bd9f0, 0xa, 0x37855e0, 0xc0002d00b0, 0x2bfee80, 0xc0005e5d70, 0x0, 0x0, 0x0, ...)
	/opt/gopath/src/github.com/hashicorp/terraform/plugin/grpc_provider.go:410 +0x247
github.com/hashicorp/terraform/terraform.(*EvalApply).Eval(0xc000a04410, 0x3798600, 0xc00001ef70, 0x2, 0x2, 0x43ef89, 0xc0000d40c0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_apply.go:71 +0x61b
github.com/hashicorp/terraform/terraform.EvalRaw(0x376d7e0, 0xc000a04410, 0x3798600, 0xc00001ef70, 0x0, 0x0, 0x0, 0x27)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalIf).Eval(0xc0005e5080, 0x3798600, 0xc00001ef70, 0x2, 0x2, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_if.go:21 +0x9c
github.com/hashicorp/terraform/terraform.EvalRaw(0x376da20, 0xc0005e5080, 0x3798600, 0xc00001ef70, 0x0, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc0002c8b00, 0x3798600, 0xc00001ef70, 0x2, 0x2, 0x42, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_sequence.go:20 +0xfd
github.com/hashicorp/terraform/terraform.EvalRaw(0x376dca0, 0xc0002c8b00, 0x3798600, 0xc00001ef70, 0x2d, 0x0, 0x0, 0x2d)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalOpFilter).Eval(0xc0005e50e0, 0x3798600, 0xc00001ef70, 0x2, 0x2, 0x6, 0x10)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_filter_operation.go:37 +0x4c
github.com/hashicorp/terraform/terraform.EvalRaw(0x376db60, 0xc0005e50e0, 0x3798600, 0xc00001ef70, 0x2bef760, 0x5c23181, 0x28dfb80, 0xc000354510)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.Eval(0x376db60, 0xc0005e50e0, 0x3798600, 0xc00001ef70, 0xc0005e50e0, 0x376db60, 0xc0005e50e0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:35 +0x4d
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x332e3a0, 0xc0002c9300, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/graph.go:90 +0x10d1
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc00013a300, 0x332e3a0, 0xc0002c9300, 0xc00008a180)
	/opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:392 +0x373
created by github.com/hashicorp/terraform/dag.(*Walker).Update
	/opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:314 +0x9d2

Expected Behavior

The AWS provider should have deleted the instances as planned.

Actual Behavior

The provider (most likely: the shared provider SDK) seems to have triggered a panic during the decoding of the provider request to apply the change.

Steps to Reproduce

With resources already existing from a previous apply:

  1. terraform plan -destroy -out=tfplan
  2. terraform apply tfplan
@apparentlymart
Copy link
Contributor Author

I have re-confirmed this with v0.12.0-alpha4. Some more details, this time.

This can be reproduced with any resource type, but I did it this time using the following configuration:

resource "null_resource" "blah" {
}

After running terraform apply to create this, as before I created a saved plan for the destroy operation:

$ terraform plan -destroy -out=tfplan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

null_resource.blah: Refreshing state... [id=7261289251550792988]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # null_resource.blah will be destroyed
  - resource "null_resource" "blah" {
      - id = "7261289251550792988" -> null
    }

Plan: 0 to add, 0 to change, 1 to destroy.

------------------------------------------------------------------------

This plan was saved to: tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "tfplan"

So far so good. But then applying that saved plan causes the same panic as before:

$ terraform apply tfplan
null_resource.blah: Destroying... [id=7261289251550792988]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x7314d2]

goroutine 33 [running]:
github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty.Type.Equals(0x0, 0x0, 0x38cc920, 0xc0002c4130, 0xc000310d00)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type.go:39 +0x22
github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty.testConformance(0x0, 0x0, 0x38cc920, 0xc0002c4130, 0xc000588610, 0x0, 0x0, 0xc000588610)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type_conform.go:37 +0xae
github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty.Type.TestConformance(0x0, 0x0, 0x38cc920, 0xc0002c4130, 0x38cc920, 0xc0002c4130, 0xc000588698)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/type_conform.go:27 +0x7a
github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/msgpack.Marshal(0x0, 0x0, 0x0, 0x0, 0x38cc920, 0xc0002c4130, 0xc000137980, 0x22, 0x40, 0x0, ...)
	/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty/msgpack/marshal.go:19 +0x67
github.com/hashicorp/terraform/plugin.(*GRPCProvider).ApplyResourceChange(0xc0002f2000, 0xc0002c7090, 0xd, 0x38cc920, 0xc0002c4108, 0x2cfa3a0, 0xc0002ddb90, 0x0, 0x0, 0x0, ...)
	/opt/gopath/src/github.com/hashicorp/terraform/plugin/grpc_provider.go:418 +0x247
github.com/hashicorp/terraform/terraform.(*EvalApply).Eval(0xc000301790, 0x38e0640, 0xc0000a1ad0, 0x2, 0x2, 0x3c, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_apply.go:71 +0x5fe
github.com/hashicorp/terraform/terraform.EvalRaw(0x38b37a0, 0xc000301790, 0x38e0640, 0xc0000a1ad0, 0x0, 0x0, 0x0, 0x27)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalIf).Eval(0xc0002dd9b0, 0x38e0640, 0xc0000a1ad0, 0x2, 0x2, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_if.go:21 +0x9c
github.com/hashicorp/terraform/terraform.EvalRaw(0x38b39e0, 0xc0002dd9b0, 0x38e0640, 0xc0000a1ad0, 0x0, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc0002eb900, 0x38e0640, 0xc0000a1ad0, 0x2, 0x2, 0x42, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_sequence.go:20 +0xfd
github.com/hashicorp/terraform/terraform.EvalRaw(0x38b3c60, 0xc0002eb900, 0x38e0640, 0xc0000a1ad0, 0x2d, 0x0, 0x0, 0x2d)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.(*EvalOpFilter).Eval(0xc0002dd9e0, 0x38e0640, 0xc0000a1ad0, 0x2, 0x2, 0x6, 0x10)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_filter_operation.go:37 +0x4c
github.com/hashicorp/terraform/terraform.EvalRaw(0x38b3b20, 0xc0002dd9e0, 0x38e0640, 0xc0000a1ad0, 0x2cea200, 0x6272461, 0x29cde80, 0xc00012f040)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x167
github.com/hashicorp/terraform/terraform.Eval(0x38b3b20, 0xc0002dd9e0, 0x38e0640, 0xc0000a1ad0, 0xc0002dd9e0, 0x38b3b20, 0xc0002dd9e0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:35 +0x4d
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x344e4c0, 0xc00027c420, 0x0, 0x0, 0x0)
	/opt/gopath/src/github.com/hashicorp/terraform/terraform/graph.go:90 +0x10d1
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc0002fa080, 0x344e4c0, 0xc00027c420, 0xc0002c0bc0)
	/opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:392 +0x373
created by github.com/hashicorp/terraform/dag.(*Walker).Update
	/opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:314 +0x9d2



!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Running just terraform destroy without the intermediate saved plan seems to work as expected:

$ terraform destroy
null_resource.blah: Refreshing state... [id=7261289251550792988]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # null_resource.blah will be destroyed
  - resource "null_resource" "blah" {
      - id = "7261289251550792988" -> null
    }

Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

null_resource.blah: Destroying... [id=7261289251550792988]
null_resource.blah: Destruction complete after 0s

Destroy complete! Resources: 0 destroyed.

Therefore it seems most likely that this is a bug in the plan file decoder where it's not properly rebuilding the internal plans.ResourceChangeSrc object. In particular, it seems like the "new value" for the object is being left as cty.NilVal (the zero value of cty.Value) rather than being populated as a properly-typed cty.NullVal.

@ghost
Copy link

ghost commented Mar 30, 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 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants