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.86k stars 9.21k forks source link

[Bug]: aws_batch_job_definition node properties with eks/ecs causes nil pointer #38605

Closed danquack closed 1 week ago

danquack commented 4 months ago

Terraform Core Version

1.9.3

AWS Provider Version

5.60.0

Affected Resource(s)

aws_batch_job_definition

Expected Behavior

When specifying other node properties, other than container, on multi-node resources, a panic occurs. It should be possible to define NodeRangeProperties with ecsProperties or eksProperties, not just containerProperties.

Actual Behavior

The provider crashes due to a nil pointer: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/batch/node_properties.go#L27-L32.

[Enhancement] Node range properties doesn't support ecsProperties or eksProperties. https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/batch/node_properties.go#L20-L23

Relevant Error/Panic Output Snippet

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x111ea603c]

goroutine 88 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/batch.(*containerProperties).Reduce(0x0)
        github.com/hashicorp/terraform-provider-aws/internal/service/batch/container_properties.go:22 +0x1c
github.com/hashicorp/terraform-provider-aws/internal/service/batch.(*nodeProperties).Reduce(0x14000145200?)
        github.com/hashicorp/terraform-provider-aws/internal/service/batch/node_properties.go:29 +0x5c
github.com/hashicorp/terraform-provider-aws/internal/service/batch.EquivalentNodePropertiesJSON({0x0, 0x0}, {0x140001450e0, 0x10f})
        github.com/hashicorp/terraform-provider-aws/internal/service/batch/node_properties.go:67 +0x124
github.com/hashicorp/terraform-provider-aws/internal/service/batch.ResourceJobDefinition.func4({0x14001158b70?, 0x140020a5e00?}, {0x0?, 0x14001192140?}, {0x140001450e0?, 0x1195392c0?}, 0x140009df080?)
        github.com/hashicorp/terraform-provider-aws/internal/service/batch/job_definition.go:98 +0x34
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.diff(0x14001158b70, {0x1194f67c8, 0x14002093470}, {0x1141b9114, 0xf}, 0x14001192140, 0x140009df000, {0x1195392c0, 0x140009df080}, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/schema.go:1143 +0x280
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.schemaMap.Diff(0x14001158b70, {0x1194f67c8, 0x14002093470}, 0x14001ddc9c0, 0x14000a22eb0, 0x14000224840, {0x119245ac0, 0x14002fdc5b0}, 0x0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/schema.go:678 +0x298
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).SimpleDiff(0x1194f6bf8?, {0x1194f67c8?, 0x14002093470?}, 0x14001ddc9c0, 0x140020934a0?, {0x119245ac0?, 0x14002fdc5b0?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:990 +0x9c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).PlanResourceChange(0x14001d69110, {0x1194f67c8?, 0x14002093380?}, 0x14000a22780)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:858 +0xa30
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).PlanResourceChange(0x140015505b0, {0x1194f67c8?, 0x140020930b0?}, 0x14000a22780)
        github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5muxserver/mux_server_PlanResourceChange.go:73 +0x250
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).PlanResourceChange(0x1400060c960, {0x1194f67c8?, 0x140020926c0?}, 0x140009de580)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:825 +0x2c8
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_PlanResourceChange_Handler({0x1190330e0, 0x1400060c960}, {0x1194f67c8, 0x140020926c0}, 0x140009de500, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:500 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400119c600, {0x1194f67c8, 0x14002092630}, {0x119558980, 0x1400052ef00}, 0x1400208cd80, 0x14004086870, 0x1229814e0, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x1400119c600, {0x119558980, 0x1400052ef00}, 0x1400208cd80)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0xb20
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 16
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c

Error: The terraform-provider-aws_v5.60.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

An example with eksProperties.

resource "aws_batch_job_definition" "test" {
  name = "tf_test_batch_job_definition_multinode"
  type = "multinode"
  retry_strategy {
    attempts = 1
  }

  node_properties = jsonencode({
    mainNode = 0
    nodeRangeProperties = [
      {
        targetNodes = "0:"
        eksProperties = {
          podProperties = {
            containers = [{
              image = "public.ecr.aws/amazonlinux/amazonlinux:1"
              command = [
                "sleep",
                "60"
              ]
              resources = {
                limits = {
                  cpu    = "1"
                  memory = "1024Mi"
                }
              }
            }]
          }
        }
      },
    ]
    numNodes = 1
  })
}

Steps to Reproduce

Apply a manifest with a node property other than container.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

https://docs.aws.amazon.com/batch/latest/APIReference/API_NodeRangeProperty.html https://aws.amazon.com/about-aws/whats-new/2024/07/aws-batch-gang-scheduling-eks-multi-node-parallel-jobs/

Would you like to implement a fix?

Yes

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 week ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 3 days ago

This functionality has been released in v5.78.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. Thank you!