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

nil checks to prevent crashes on empty config blocks #10713

Merged
merged 1 commit into from
Nov 6, 2019
Merged

Conversation

ryndaniels
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Closes #10702

Release note for CHANGELOG:

BUG FIXES:
* resource/aws_ssm_maintenance_window_task: Add nil checks to prevent crashes when empty config blocks are provided

Output from acceptance testing:

  • First, reproducing the crash with a new test:
$ make testacc TESTARGS="-run=TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run=TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== CONT  TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 301 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.expandAwsSsmTaskInvocationRunCommandParametersNotificationConfig(0xc0014c3ce0, 0x1, 0x1, 0x13)
        /Users/ryndaniels/terraform-providers/terraform-provider-aws/aws/resource_aws_ssm_maintenance_window_task.go:581 +0x306
github.com/terraform-providers/terraform-provider-aws/aws.expandAwsSsmTaskInvocationRunCommandParameters(0xc0014c3bc0, 0x1, 0x1, 0x16)
        /Users/ryndaniels/terraform-providers/terraform-provider-aws/aws/resource_aws_ssm_maintenance_window_task.go:494 +0x62b
github.com/terraform-providers/terraform-provider-aws/aws.expandAwsSsmTaskInvocationParameters(0xc0014c3b60, 0x1, 0x1, 0x53834a0)
        /Users/ryndaniels/terraform-providers/terraform-provider-aws/aws/resource_aws_ssm_maintenance_window_task.go:395 +0x485
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsSsmMaintenanceWindowTaskCreate(0xc00049ae70, 0x5324280, 0xc0004c8000, 0x2, 0xa1c93e0)
        /Users/ryndaniels/terraform-providers/terraform-provider-aws/aws/resource_aws_ssm_maintenance_window_task.go:683 +0x856
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0006beb80, 0xc000960500, 0xc0006d8760, 0x5324280, 0xc0004c8000, 0xc000c35201, 0xc000ca5b00, 0xc000c352f0)
        /Users/ryndaniels/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.2.0/helper/schema/resource.go:305 +0x365
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc00076d980, 0xc000a53918, 0xc000960500, 0xc0006d8760, 0xc000ca3ca8, 0xc0000d7a38, 0x588e180)
        /Users/ryndaniels/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.2.0/helper/schema/provider.go:294 +0x99
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000487190, 0x70ddb20, 0xc000c73da0, 0xc0000d91a0, 0xc000487190, 0xc000c73da0, 0xc000076a80)
        /Users/ryndaniels/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.2.0/internal/helper/plugin/grpc_provider.go:885 +0x882
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x624ae60, 0xc000487190, 0x70ddb20, 0xc000c73da0, 0xc0000d9140, 0x0, 0x70ddb20, 0xc000c73da0, 0xc000c8cc00, 0x5c0)
        /Users/ryndaniels/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.2.0/internal/tfplugin5/tfplugin5.pb.go:3189 +0x217
google.golang.org/grpc.(*Server).processUnaryRPC(0xc001844f20, 0x7113b20, 0xc0004f3b00, 0xc000b13200, 0xc001394690, 0xa1863e0, 0x0, 0x0, 0x0)
        /Users/ryndaniels/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:995 +0x460
google.golang.org/grpc.(*Server).handleStream(0xc001844f20, 0x7113b20, 0xc0004f3b00, 0xc000b13200, 0x0)
        /Users/ryndaniels/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:1275 +0xd97
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc0006e6d00, 0xc001844f20, 0x7113b20, 0xc0004f3b00, 0xc000b13200)
        /Users/ryndaniels/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:710 +0xbb
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /Users/ryndaniels/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:708 +0xa1
FAIL    github.com/terraform-providers/terraform-provider-aws/aws       13.805s
testing: warning: no tests to run
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws/internal/flatmap      0.032s [no tests to run]
testing: warning: no tests to run
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags 0.071s [no tests to run]
FAIL
make: *** [testacc] Error 1
  • Next, fixing the crash:
make testacc TESTARGS="-run=TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig"
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run=TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== CONT  TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
--- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (22.15s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       22.936s
  • Finally, all the tests:
make testacc TESTARGS="-run=TestAccAWSSSMMaintenanceWindowTask_"        
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -count 1 -parallel 20 -run=TestAccAWSSSMMaintenanceWindowTask_ -timeout 120m
?       github.com/terraform-providers/terraform-provider-aws   [no test files]
=== RUN   TestAccAWSSSMMaintenanceWindowTask_basic
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_basic
=== RUN   TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource
=== RUN   TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters
=== RUN   TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters
=== RUN   TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters
=== RUN   TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters
=== RUN   TestAccAWSSSMMaintenanceWindowTask_TaskParameters
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_TaskParameters
=== RUN   TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== PAUSE TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== CONT  TestAccAWSSSMMaintenanceWindowTask_basic
=== CONT  TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters
=== CONT  TestAccAWSSSMMaintenanceWindowTask_TaskParameters
=== CONT  TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig
=== CONT  TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters
=== CONT  TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters
=== CONT  TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters
=== CONT  TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource
--- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (35.36s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (38.63s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskParameters (38.81s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (60.41s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (61.43s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (63.02s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (84.44s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (88.47s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       89.293s

@ryndaniels ryndaniels requested review from bflad and a team November 1, 2019 16:05
@ghost ghost added size/M Managed by automation to categorize the size of a PR. service/ssm Issues and PRs that pertain to the ssm service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Nov 1, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Nov 1, 2019
@bflad bflad added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 6, 2019
@bflad bflad added this to the v2.35.0 milestone Nov 6, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ryndaniels 🚀 I added the bug and crash labels to highlight the pull request's purpose better.

Output from acceptance testing:

--- PASS: TestAccAWSSSMMaintenanceWindowTask_emptyNotificationConfig (12.47s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationStepFunctionParameters (13.21s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskParameters (14.11s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_updateForcesNewResource (19.92s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationRunCommandParameters (21.25s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationAutomationParameters (21.32s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_basic (22.05s)
--- PASS: TestAccAWSSSMMaintenanceWindowTask_TaskInvocationLambdaParameters (28.96s)

@bflad bflad merged commit 883c0be into master Nov 6, 2019
@bflad bflad deleted the rfd-10702 branch November 6, 2019 21:27
bflad added a commit that referenced this pull request Nov 6, 2019
@ghost
Copy link

ghost commented Nov 7, 2019

This has been released in version 2.35.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 29, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ssm Issues and PRs that pertain to the ssm service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tf crash while while 'apply' with notification_config { } blanked out
2 participants