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]: panic: runtime error: index out of range [0] with length 0 when trying to remove cache_stale_timeout_in_seconds from aws_storagegateway_smb_file_share #28188

Open stevewoodcock opened 1 year ago

stevewoodcock commented 1 year ago

Terraform Core Version

1.3.5

AWS Provider Version

4.45.0

Affected Resource(s)

Expected Behavior

AWS console setting "Automated cache refresh from S3" should be set to None

Actual Behavior

Panic

Relevant Error/Panic Output Snippet

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_storagegateway_smb_file_share.test2 will be updated in-place
  ~ resource "aws_storagegateway_smb_file_share" "test2" {
        id                       = "arn:aws:storagegateway:XXX"
        tags                     = {}
        # (23 unchanged attributes hidden)

      - cache_attributes {
          - cache_stale_timeout_in_seconds = 2592000 -> null
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_storagegateway_smb_file_share.test2: Modifying... [id=arn:aws:storagegateway:XXX]
╷
│ Error: Request cancelled
│
│   with aws_storagegateway_smb_file_share.test2,
│   on storage-gateway.tf line 100, in resource "aws_storagegateway_smb_file_share" "test2":
│  100: resource "aws_storagegateway_smb_file_share" "test2" {
│
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

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

panic: runtime error: index out of range [0] with length 0

goroutine 376 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway.resourceSMBFileShareUpdate(0xc0001f8b80, {0xb813c20?, 0xc001896c00})
    github.com/hashicorp/terraform-provider-aws/internal/service/storagegateway/smb_file_share.go:391 +0x146f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xd7a2060?, {0xd7a2060?, 0xc0001e5080?}, 0xd?, {0xb813c20?, 0xc001896c00?})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:729 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0019ac0e0, {0xd7a2060, 0xc0001e5080}, 0xc0001f09c0, 0xc0001f8a00, {0xb813c20, 0xc001896c00})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/resource.go:847 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0000101c8, {0xd7a2060?, 0xc0001e4f60?}, 0xc004906500)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.24.1/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ApplyResourceChange({0xc00313ec30, 0xc00313ec90, {0xc00477dda0, 0x2, 0x2}, 0xc00313ec60, 0xc0031656a0, 0xc0043a68a0, 0xc00313ecc0}, {0xd7a2060, ...}, ...)
    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(0xc001e988c0, {0xd7a2060?, 0xc0001e4180?}, 0xc0018e8070)
    github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xc384980?, 0xc001e988c0}, {0xd7a2060, 0xc0001e4180}, 0xc0018e8000, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.14.1/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc004240780, {0xd7ac9c0, 0xc0001e0680}, 0xc0043fc000, 0xc00489ee40, 0x13759ee0, 0x0)
    google.golang.org/grpc@v1.50.1/server.go:1340 +0xd23
google.golang.org/grpc.(*Server).handleStream(0xc004240780, {0xd7ac9c0, 0xc0001e0680}, 0xc0043fc000, 0x0)
    google.golang.org/grpc@v1.50.1/server.go:1713 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.50.1/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.50.1/server.go:963 +0x28a

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

Can't easily extract the config sorry, but given a working aws_storagegateway_smb_file_share resource we then added a cache stale timeout setting:

+  cache_attributes {
+    cache_stale_timeout_in_seconds = 43200
+  }

which worked fine, but when we remove the setting (ie. delete the three lines added above) it triggers the error.

Steps to Reproduce

Create working aws_storagegateway_smb_file_share Add cache_stale_timeout_in_seconds terraform apply Remove cache_stale_timeout_in_seconds terraform apply Panic

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

pgr-staranto commented 1 year ago

Still exists w/Terraform 1.5.x and AWS provider 5.15.0.