hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.78k stars 9.13k forks source link

[Bug]: nil pointer dereference error in dms.checkDefaultValues #36588

Open jquag opened 6 months ago

jquag commented 6 months ago

Terraform Core Version

1.5.1

AWS Provider Version

5.42.0

Affected Resource(s)

aws_dms_replication_task

Expected Behavior

I expect the aws_dms_replication_task resource to be created successfully the first time as well as being updated successfully on subsequent changes.

Actual Behavior

The resource is created successfully but fails on any updates.

Relevant Error/Panic Output Snippet

Stack trace from the terraform-provider-aws_v5.42.0_x5 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0xc7abdd9]
goroutine 1029 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/dms.checkdefaultvalues(0xc00287d000?, 0xe9b?)
                github.com/hashicorp/terraform-provider-aws/internal/service/dms/task_settings_json.go:233 +0x119
github.com/hashicorp/terraform-provider-aws/internal/service/dms.normalizeTaskSettings({0xc002843000, 0xe9b})
                github.com/hashicorp/terraform-provider-aws/internal/service/dms/task_settings_json.go:210 +0x2ae5
github.com/hashicorp/terraform-provider-aws/internal/service/dms.suppressEquivalentTaskSettings({0x4185c8?, 0x115f136e?}, {0xc002843000, 0xe9b}, {0xc002850160, 0x157}, 0xc004d5bf80?)
                github.com/hashicorp/terraform-provider-aws/internal/service/dms/task_settings_json.go:225 +0xba
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.diff(0x6?, {0x12f7d928, 0xc002838690}, {0x115f136e, 0x19}, 0xc000e75040, 0xc004d5bf00, {0x12fa44e0?, 0xc004d5bf80}, 0x0)
                github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/schema.go:1143 +0x392
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0xc00100db00, {0x12f7d928, 0xc002838690}, 0xc002008d00, 0xc002582e10, 0xc0000113c8, {0x114b87a0, 0xc002563180}, 0x0)
                github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/schema.go:678 +0x332
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0x12f7dd20?, {0x12f7d928?, 0xc002838690?}, 0xc002008d00, 0xf776ca0?, {0x114b87a0?, 0xc002563180?})
                github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/resource.go:962 +0xd5
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0xc001e173e0, {0x12f7d928?, 0xc002838570?}, 0xc002582960)
                github.com/hashicorp/terraform-plugin-sdk/v2@v2.33.0/helper/schema/grpc_provider.go:798 +0x9b6
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).PlanResourceChange(0xc00116b9d0, {0x12f7d928?, 0xc002838270?}, 0xc002582960)
                github.com/hashicorp/terraform-plugin-mux@v0.15.0/tf5muxserver/mux_server_PlanResourceChange.go:73 +0x2ad
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0xc000a9a0a0, {0x12f7d928?, 0xc0025b9a40?}, 0xc00248f490)
                github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/tf5server/server.go:811 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0x11261960?, 0xc000a9a0a0}, {0x12f7d928, 0xc0025b9a40}, 0xc00461fe00, 0x0)
                github.com/hashicorp/terraform-plugin-go@v0.22.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:500 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc001642200, {0x12f7d928, 0xc0028de6f0}, {0x12fb6938, 0xc002686680}, 0xc002751c20, 0xc0026143c0, 0x1b175a60, 0x0)
                google.golang.org/grpc@v1.62.0/server.go:1383 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc001642200, {0x12fb6938, 0xc002686680}, 0xc002751c20)
                google.golang.org/grpc@v1.62.0/server.go:1794 +0x100c
google.golang.org/grpc.(*Server).serveStreams.func2.1()
                google.golang.org/grpc@v1.62.0/server.go:1027 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 45
                google.golang.org/grpc@v1.62.0/server.go:1038 +0x135
Error: The terraform-provider-aws_v5.42.0_x5 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Terraform Configuration Files

Sorry, I can't provide a full set of configuration files for this issue but I believe the key is having BeforeImageSettings defined in the aws_dms_replication_task resource as below...

resource "aws_dms_replication_task" "postgres_replication_task" {
  migration_type           = "cdc"
  table_mappings           = file("${path.module}/dms_table_mappings.json")
  replication_task_id      = "my-replication-task"
  replication_instance_arn = aws_dms_replication_instance.postgres_replication_instance.replication_instance_arn
  source_endpoint_arn      = aws_dms_endpoint.source_endpoint.endpoint_arn
  target_endpoint_arn      = aws_dms_endpoint.target_endpoint.endpoint_arn
  start_replication_task   = true

  replication_task_settings = jsonencode({
    "BeforeImageSettings": {
      "EnableBeforeImage": true,
      "ColumnFilter": "all",
      "FieldName": "previous-value"
    },
    "FullLoadSettings": {
      "TargetTablePrepMode": "DO_NOTHING",
      "CreatePkAfterFullLoad": false,
      "StopTaskCachedChangesApplied": false,
      "StopTaskCachedChangesNotApplied": false,
      "MaxFullLoadSubTasks": 30,
      "TransactionConsistencyTimeout": 600,
      "CommitRate": 10000
    },
  })
}

Steps to Reproduce

Apply the terraform including an aws_dms_replication_task similar to the provided. The first apply should succeed. Apply the terraform a second time and you should see the error.

Debug Output

No response

Panic Output

No response

Important Factoids

Based on what I see in the source code where the panic is happening (github.com/hashicorp/terraform-provider-aws/internal/service/dms/task_settings_json.go:233), it looks like it is not expected that a value from defaultMap would be nil. However, as can be seen on line 48, the defaultSettings map is created with a value of nil for the key "BeforeImageSettings".

I suspect this causes the panic if ever the aws_dms_replication_task includes "BeforeImageSettings".

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 6 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

shmathes commented 6 months ago

I ran into a similar issue today. In my task setting, I had null values for items we didn't need. After hitting the nil pointer panic, did like jquag and looked at task_settings_json.go and any key that was assigned with nil, I removed from my settings and after that it worked like a charm.

ponkio-o commented 6 months ago

I'm facing the same issue now. It happened when I updated the terraform-provider-aws v5.42.0.

nijave commented 6 months ago

Seeing this as well. I assume related to recent changes here https://github.com/hashicorp/terraform-provider-aws/pull/36035 cc @nam054

ponkio-o commented 5 months ago

Was this issue solved by https://github.com/hashicorp/terraform-provider-aws/pull/36967 ? Actually, terraform plan executed successfully in my environment using v5.48.0.