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

invalid memory address or nil pointer dereference #30760

Closed
kerryhatcher opened this issue Mar 29, 2022 · 10 comments · Fixed by #30773
Closed

invalid memory address or nil pointer dereference #30760

kerryhatcher opened this issue Mar 29, 2022 · 10 comments · Fixed by #30773
Labels

Comments

@kerryhatcher
Copy link

kerryhatcher commented Mar 29, 2022

I was applying some ACM/CloudFront changes (AWS) when I got this error. Had just completed a successful plan with -out. After copying down the info from the error I ran another successful plan and applied further without any problems. Unable to reproduce since then but thought I'd still send this in since the error output specifically asked for that.

Also going to take some time to upgrade terraform and providers after this.

Here is the plan: https://gist.github.com/kerryhatcher/3a5e1e86d3145478132df8f2ce7d996e

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

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.

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

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

runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /home/circleci/project/project/internal/logging/panic.go:55 +0x154
panic({0x22202c0, 0x3edab70})
        /usr/local/go/src/runtime/panic.go:1047 +0x266
github.com/hashicorp/terraform/internal/backend/remote.(*Remote).Operation(0xc0004bb600, {0x2a7adf0, 0xc000140008}, 0xc000512a20)
        /home/circleci/project/project/internal/backend/remote/backend.go:688 +0x135
github.com/hashicorp/terraform/internal/command.(*Meta).RunOperation(0xc000802340, {0x7fe335177770, 0xc0004bb600}, 0xc000512a20)
        /home/circleci/project/project/internal/command/meta.go:401 +0xde
github.com/hashicorp/terraform/internal/command.(*ApplyCommand).Run(0xc000802340, {0xc000120170, 0x0, 0x0})
        /home/circleci/project/project/internal/command/apply.go:121 +0x59b
github.com/mitchellh/cli.(*CLI).Run(0xc000c0e140)
        /home/circleci/go/pkg/mod/github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x5f8
main.realMain()
        /home/circleci/project/project/main.go:309 +0x1509
main.main()
        /home/circleci/project/project/main.go:58 +0x19

Terraform Version

Terraform v1.1.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/archive v2.2.0
+ provider registry.terraform.io/hashicorp/aws v4.1.0
+ provider registry.terraform.io/hashicorp/random v3.1.0
+ provider registry.terraform.io/newrelic/newrelic v2.37.0
+ provider registry.terraform.io/pagerduty/pagerduty v1.9.6

Terraform Configuration Files

Private info. Here some data that could be relevant:

Resources involved in planned changes:

resource "aws_acm_certificate"
resource "aws_cloudfront_distribution"
Each of the above is created with a for_each

Debug Output

not available, unable to reproduce.

Expected Behavior

Apply changes from plan

Actual Behavior

Terraform crashed

Steps to Reproduce

Unable to reproduce

Additional Context

Running directly in VS Code terminal

References

Non known

@kerryhatcher kerryhatcher added bug new new issue not yet triaged labels Mar 29, 2022
@ron-basumallik
Copy link

Seeing the same issue running AWS resource updates, lots of resources so can't print out exactly. Can't get crash log file because it's on Terraform Cloud. Having tried multiple Terraform 1.0 and 1.1 versions. In the run before I got this error

Failed to request discovery document: Get "https://app.terraform.io/.well-known/terraform.json": net/http: request canceled (Client.Timeout exceeded while awaiting headers)

@alisdair
Copy link
Member

Thanks for the report! This seems likely to be the same root cause as #30646. We still don't have a reproduction case for this.

@kerryhatcher, can you share anything more about your environment? Some specific questions:

  • Are you using Terraform Cloud?
  • If so, is the workspace in remote or local execution mode?
  • How are you authenticating with Terraform Cloud (or the other remote system)? That is, where is your token stored?

@ron-basumallik
Copy link

@alisdair I am using Terraform Cloud, workspace is in remote execution mode. We auth with a token stored locally.

[signal SIGSEGV: segmentation violation code=0x1 addr=0x288 pc=0xe204b2]

goroutine 1 [running]:
github.com/hashicorp/terraform/internal/backend/remote.(*Remote).Operation(0xc000c7e0b0, 0x2bb3cf0, 0xc000124018, 0xc000723560, 0x1, 0x0, 0x0)
	/home/circleci/project/project/internal/backend/remote/backend.go:674 +0x92
github.com/hashicorp/terraform/internal/command.(*Meta).RunOperation(0xc0003aa000, 0x2bc8c18, 0xc000c7e0b0, 0xc000723560, 0x1, 0x1, 0x0)
	/home/circleci/project/project/internal/command/meta.go:396 +0x8e
github.com/hashicorp/terraform/internal/command.(*ApplyCommand).Run(0xc0003aa000, 0xc000100070, 0x3, 0x3, 0xc00049e030)
	/home/circleci/project/project/internal/command/apply.go:122 +0x730
github.com/mitchellh/cli.(*CLI).Run(0xc0005f52c0, 0xc0001ba000, 0x27282a4, 0x5)
	/home/circleci/go/pkg/mod/github.com/mitchellh/cli@v1.1.2/cli.go:262 +0x41a
main.wrappedMain(0x0)
	/home/circleci/project/project/main.go:384 +0x1112
main.realMain(0x0)
	/home/circleci/project/project/main.go:115 +0x554
main.main()
	/home/circleci/project/project/main.go:58 +0x25


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

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.581538997.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.

SECURITY WARNING: the "crash.581538997.log" file that was created may contain 
sensitive information that must be redacted before it is safe to share 
on the issue tracker.

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

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!```

@tomaswalander
Copy link

tomaswalander commented Mar 30, 2022

Just started getting a similar error when planning our infrastructure for Azure.
(Not sure if exactly the same though - but didn't want to open a new issue just yet...)

Observed behaviour
The plan for our test environment failed (see details below) but the plan for our UAT environment, using the same config but different tfvars (file + command-line args) worked.

My own guessing
I'm fairly certain that (in my case) it has to do with a module that was previously only "targeting" the test environment - while I was working on it. And then when I deemed it ready I wanted to get it to our UAT environment so I simply removed:

count = var.environment == "test" ? 1 : 0

Haven't verified thought but while writing I thought of this and thought I'd add it...


Setup

Terraform v1.1.7
on darwin_amd64
+ provider registry.terraform.io/hashicorp/azuread v2.15.0
+ provider registry.terraform.io/hashicorp/azurerm v2.89.0
+ provider registry.terraform.io/hashicorp/random v3.1.2

using remote backend (azure container blob) run in an azure devops pipeline using a service principal.

Error

runtime error: invalid memory address or nil pointer dereferencegoroutine 3126 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
	/home/circleci/project/project/internal/logging/panic.go:44 +0xb5
panic({0x221d240, 0x3ed5b10})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/hashicorp/terraform/internal/instances.(*expanderModule).resourceInstances(0x0, {0xc000931120, 0x1, 0x1}, {{}, 0x4d, {0xc000906ec0, 0x10}, {0xc000906ed0, 0x4}}, ...)
	/home/circleci/project/project/internal/instances/expander.go:376 +0xc3
github.com/hashicorp/terraform/internal/instances.(*expanderModule).resourceInstances(0xc001e26b70, {0xc000931100, 0x2, 0x2}, {{}, 0x4d, {0xc000906ec0, 0x10}, {0xc000906ed0, 0x4}}, ...)
	/home/circleci/project/project/internal/instances/expander.go:385 +0x293
github.com/hashicorp/terraform/internal/instances.(*Expander).ExpandResource(0xc0000989e0, {{}, {0xc000931100, 0x2, 0x2}, {{}, 0x4d, {0xc000906ec0, 0x10}, {0xc000906ed0, ...}}})
	/home/circleci/project/project/internal/instances/expander.go:157 +0x16f
github.com/hashicorp/terraform/internal/terraform.(*NodePlannableResourceInstanceOrphan).deleteActionReason(0xc002261dd0, {0x2aecc00, 0xc0022c49a0})
	/home/circleci/project/project/internal/terraform/node_resource_plan_orphan.go:204 +0x23b
github.com/hashicorp/terraform/internal/terraform.(*NodePlannableResourceInstanceOrphan).managedResourceExecute(0xc002261dd0, {0x2aecc00, 0xc0022c49a0})
	/home/circleci/project/project/internal/terraform/node_resource_plan_orphan.go:140 +0x58c
github.com/hashicorp/terraform/internal/terraform.(*NodePlannableResourceInstanceOrphan).Execute(0x0, {0x2aecc00, 0xc0022c49a0}, 0x20)
	/home/circleci/project/project/internal/terraform/node_resource_plan_orphan.go:49 +0x90
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc000ab37a0, {0x2aecc00, 0xc0022c49a0}, {0x7f321d21e370, 0xc002261dd0})
	/home/circleci/project/project/internal/terraform/graph_walk_context.go:133 +0xc2
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x2553ec0, 0xc002261dd0})
	/home/circleci/project/project/internal/terraform/graph.go:74 +0x2f0
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc00136d500, {0x2553ec0, 0xc002261dd0}, 0xc0015ef400)
	/home/circleci/project/project/internal/dag/walk.go:381 +0x2f1
created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update
	/home/circleci/project/project/internal/dag/walk.go:304 +0xf85
##[error]Error: Terraform Plan failed with exit code: 11

@alisdair
Copy link
Member

@tomaswalander Thanks for reporting that crash. It's a different panic; would you mind opening a new issue, please?

@tomaswalander
Copy link

tomaswalander commented Mar 30, 2022

@alisdair I just confirmed that it was indeed due to removing the count... From my side, I could just work around it with removing/re-importing states to fix the references. But I guess it would still be nice if terraform didn't just crash..

Do you still want me to open a new issue? :)

@alisdair
Copy link
Member

Yes, please! Any crash is a bug that we'd like to fix if we can.

@kerryhatcher
Copy link
Author

@alisdair Sorry I forgot all about this since it never popped back up again.

Are you using Terraform Cloud? **Yes**
If so, is the workspace in remote or local execution mode? **local**
How are you authenticating with Terraform Cloud (or the other remote system)? That is, where is your token stored? **I just used the login command. Nothing fancy. https://www.terraform.io/cli/commands/login**

@alisdair
Copy link
Member

Thanks! As noted above, we believe this has been fixed and released in Terraform 1.1.8, so hopefully you don't see it again.

@crw crw removed the new new issue not yet triaged label Apr 12, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants