-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
helper/schema: Crash while updating set in MapFieldWriter.setSet #14418
Comments
I was also having the |
Here is the stack trace from the panic output, for easier reference:
|
I'm also seeing this, with v0.9.6. |
References: * #14418 * v0.9.5 (original bug report): https://github.com/hashicorp/terraform/blob/a59ee0b30e1350d18e44a3a2a405124302751f93/helper/schema/field_writer_map.go#L311 * v0.11.12 (Terraform AWS Provider discovery): https://github.com/hashicorp/terraform/blob/057286e5228559722bfc9bf6a03679650358c9d2/helper/schema/field_writer_map.go#L343 When creating flatten functions in Terraform Providers that return *schema.Set, its possible to return a typed `nil`, e.g. ```go func flattenHeaders(h *cloudfront.Headers) *schema.Set { if h.Items != nil { return schema.NewSet(schema.HashString, flattenStringList(h.Items)) } return nil } ``` This previously could cause a panic, e.g. ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1881911] goroutine 1325 [running]: github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).setSet(0xc00054bf00, 0xc00073efa0, 0x5, 0x5, 0x5828140, 0x0, 0xc0002cea50, 0xc000e996a8, 0xc001026e40) /Users/bflad/go/pkg/mod/github.com/hashicorp/[email protected]/helper/schema/field_writer_map.go:343 +0x211 ``` Here we catch the typed `nil` and return an empty list flatmap result instead. Unit testing result prior to code update: ``` --- FAIL: TestMapFieldWriter (0.00s) panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1777cdc] goroutine 913 [running]: testing.tRunner.func1(0xc00045b800) /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:830 +0x392 panic(0x192cf20, 0x2267ca0) /usr/local/Cellar/go/1.12.1/libexec/src/runtime/panic.go:522 +0x1b5 github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).setSet(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0xc00045c600, 0x30, 0x19e0080) /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:344 +0x68c github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).set(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0x1, 0x18) /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:107 +0x28b github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).WriteField(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0x0, 0x0) /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:89 +0x504 github.com/hashicorp/terraform/helper/schema.TestMapFieldWriter(0xc00045b800) /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map_test.go:337 +0x2ddd testing.tRunner(0xc00045b800, 0x1a44f90) /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:865 +0xc0 created by testing.(*T).Run /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:916 +0x35a ```
The panic prevention fix for the Terraform Provider SDK has been merged and will release with version 0.12.0-beta2 of Terraform in the coming weeks. Terraform Providers will need to update their Terraform Provider SDK dependency to receive this fix. The new behavior is setting an empty list into the Terraform state when attempting to write a typed |
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. |
Terraform Version
terraform --version
Terraform v0.9.5
Affected Resource(s)
Overall it seems to happen across multiple resources but
aws_launch_configuration
is always included withunexpected EOF
, while other resources will have aconnection is shut down
or theunexpected EOF
error.Terraform Configuration Files
I will need to scrub the configuration files before posting.
Debug Output
I will need to scrub the debug output before posting.
Panic Output
https://gist.github.com/kpettijohn/82eef460a4cdf094efce08100fbba5d0
Expected Behavior
Successful plan
Actual Behavior
Crash
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
terraform plan
orterraform apply
Terraform will crash roughly 50-75% of the time when executing a plan or apply.
The text was updated successfully, but these errors were encountered: