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]: aws_instance panic/crash with null capacity_reservation_specification #27330

Open ryan-cpi opened 1 year ago

ryan-cpi commented 1 year ago

Terraform Core Version

1.2.4

AWS Provider Version

4.33.0

Affected Resource(s)

In aws_instance setting this

capacity_reservation_specification {
    capacity_reservation_preference = null
}

Causes terraform to panic

(I know i can avoid this with dynamic blocks)

Expected Behavior

To be handled with the normal error handing not crashing and burning with an unhelpful traceback

Actual Behavior

Plug in fails to respond causing a panic

Relevant Error/Panic Output Snippet

Error: Plugin did not respond

  with module.test_instance1.aws_instance.instance,
  on .terraform/modules/test_instance1/ec2/ec2.tf line 1, in resource "aws_instance" "instance":
   1: resource "aws_instance" "instance" {

The plugin encountered an error, and failed to respond to the
plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
more details.

Stack trace from the terraform-provider-aws_v4.33.0_x5 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 355 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.expandCapacityReservationSpecification(0xc0026e4c60)
    github.com/hashicorp/terraform-provider-aws/internal/service/ec2/ec2_instance.go:2995 +0x2fa
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.resourceInstanceUpdate(0xc0032f9400, {0x8eafb40?, 0xc00114f500})
    github.com/hashicorp/terraform-provider-aws/internal/service/ec2/ec2_instance.go:1797 +0x5945
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xafdc420?, {0xafdc420?, 0xc0026a3650?}, 0xd?, {0x8eafb40?, 0xc00114f500?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:729 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000d9fb20, {0xafdc420, 0xc0026a3650}, 0xc0019fbba0, 0xc0032f8e80, {0x8eafb40, 0xc00114f500})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/resource.go:847 +0x82c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000d368, {0xafdc420?, 0xc0026a3530?}, 0xc0029e9d10)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.23.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ApplyResourceChange({0xc0019ab0e0, 0xc0019ab6b0, {0xc001afce60, 0x2, 0x2}, 0xc0019ab500, 0xc00107d130, 0xc002eb04f0, 0xc0019ab770}, {0xafdc420, ...}, ...)
    github.com/hashicorp/terraform-plugin-mux@v0.7.0/tf5muxserver/mux_server_ApplyResourceChange.go:27 +0x142
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc001510140, {0xafdc420?, 0xc0026a20c0?}, 0xc0019312d0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x9f4cc80?, 0xc001510140}, {0xafdc420, 0xc0026a20c0}, 0xc001931260, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000001e0, {0xafe1cc0, 0xc002ead860}, 0xc0030770e0, 0xc001ac12f0, 0x107451c0, 0x0)
    google.golang.org/grpc@v1.48.0/server.go:1295 +0xb0b
google.golang.org/grpc.(*Server).handleStream(0xc0000001e0, {0xafe1cc0, 0xc002ead860}, 0xc0030770e0, 0x0)
    google.golang.org/grpc@v1.48.0/server.go:1636 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.48.0/server.go:930 +0x28a

Error: The terraform-provider-aws_v4.33.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

n/a

Steps to Reproduce

Set null values in capacity_reservation_specification

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No response

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ewbankkit commented 1 year ago
v4.33.0

https://github.com/hashicorp/terraform-provider-aws/blob/61768353b052fba586e90a04c08c79b0073607bc/internal/service/ec2/ec2_instance.go#L2983-L2999

main

https://github.com/hashicorp/terraform-provider-aws/blob/5b85a5788722607826f2cf8ccc3a84b7cc0c9ffd/internal/service/ec2/ec2_instance.go#L2983-L2999

github-actions[bot] commented 5 days ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!