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

[Bug]: resourceUserPoolUpdate - runtime error: index out of range [0] with length 0 #38164

Closed
hans-d opened this issue Jun 27, 2024 · 11 comments · Fixed by #38184
Closed

[Bug]: resourceUserPoolUpdate - runtime error: index out of range [0] with length 0 #38164

hans-d opened this issue Jun 27, 2024 · 11 comments · Fixed by #38184
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cognitoidp Issues and PRs that pertain to the cognitoidp service.
Milestone

Comments

@hans-d
Copy link

hans-d commented Jun 27, 2024

Terraform Core Version

1.5.7

AWS Provider Version

5.55.0

Affected Resource(s)

aws_cognito_user_pool

Expected Behavior

it works

Actual Behavior

The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.

Relevant Error/Panic Output Snippet

│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-aws_v5.55.0_x5 plugin:

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

goroutine 31 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp.resourceUserPoolUpdate({0x13eb5328, 0x40031650b0}, 0x4000c8bd80, {0x11e8c120, 0x4003924d00})
	github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp/user_pool.go:1035 +0x2260
github.com/hashicorp/terraform-provider-aws/internal/provider.New.(*wrappedResource).Update.interceptedHandler[...].func10(0x4000c8bd80?, {0x11e8c120?, 0x4003924d00})
	github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:113 +0x1d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x13eb5328?, {0x13eb5328?, 0x4002cd00f0?}, 0xd?, {0x11e8c120?, 0x4003924d00?})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:835 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x400101f420, {0x13eb5328, 0x4002cd00f0}, 0x400720da00, 0x4000c8ac00, {0x11e8c120, 0x4003924d00})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x670
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x4002224cd8, {0x13eb5328?, 0x4002cd0030?}, 0x40036d8e60)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xaa4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0x40016bff10, {0x13eb5328?, 0x4003913ce0?}, 0x40036d8e60)
	github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x4000587220, {0x13eb5328?, 0x4003913320?}, 0x4001f0eb60)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x2b4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x11c55b40, 0x4000587220}, {0x13eb5328, 0x4003913320}, 0x40030bb300, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x40017d4000, {0x13eb5328, 0x4003913260}, {0x13f07be0, 0x400051f800}, 0x400163e360, 0x4003f11ad0, 0x1d175038, 0x0)
	google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x40017d4000, {0x13f07be0, 0x400051f800}, 0x400163e360)
	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 51
	google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c

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

unclear yet - strack trace should provide some info.
Occured when adding lambda_config (was not present before)

Steps to Reproduce

Occured when adding lambda_config (was not present before)

Debug Output

No response

Panic Output

No response

Important Factoids

      + lambda_config {
          + post_authentication  = "arn:aws:lambda:eu-west-1:123456789012:layer:blah-post-auth"
          + pre_sign_up          = "arn:aws:lambda:eu-west-1:123456789012:layer:blah-pre-signup"
          + pre_token_generation = "arn:aws:lambda:eu-west-1:123456789012:layer:blah-pre-token"
        }

mentioned line is related to pre_token_generation
https://github.com/hashicorp/terraform-provider-aws/blame/7f011bde8a0843786eb68ac3a4848243c1eca99f/internal/service/cognitoidp/user_pool.go#L1035

wokrs in 5.40, version just before the mentioned line was updated

References

No response

Would you like to implement a fix?

No

@hans-d hans-d added the bug Addresses a defect in current functionality. label Jun 27, 2024
@github-actions github-actions bot added the crash Results from or addresses a Terraform crash or kernel panic. label Jun 27, 2024
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Jun 27, 2024
@justinretzolk
Copy link
Member

Hey @hans-d 👋 Thank you for taking the time to raise this! Are you able to supply a sample configuration in case whoever picks this up needs that information?

@justinretzolk justinretzolk added waiting-response Maintainers are waiting on response from community or contributor. service/cognitoidp Issues and PRs that pertain to the cognitoidp service. labels Jun 27, 2024
@hans-d
Copy link
Author

hans-d commented Jun 27, 2024

saw some recent changes (not yet in a release) to this part of the code, so lets see what that results in.

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 27, 2024
@justinretzolk
Copy link
Member

@hans-d the new release should be out in an hour or so, so hopefully that takes care of it 👍

@justinretzolk justinretzolk added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 27, 2024
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Jun 28, 2024
@hans-d
Copy link
Author

hans-d commented Jun 28, 2024

Still an issue with 5.56

│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵
Releasing state lock. This may take a few moments...

Stack trace from the terraform-provider-aws_v5.56.0_x5 plugin:

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

goroutine 341 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp.resourceUserPoolUpdate({0x1416e428, 0x40046df650}, 0x40049b1200, {0x120ff600, 0x4003c11040})
	github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp/user_pool.go:1000 +0x2144
github.com/hashicorp/terraform-provider-aws/internal/provider.New.(*wrappedResource).Update.interceptedHandler[...].func10(0x40049b1200?, {0x120ff600?, 0x4003c11040})
	github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:113 +0x1d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x1416e428?, {0x1416e428?, 0x40042d7440?}, 0xd?, {0x120ff600?, 0x4003c11040?})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:835 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x400120b420, {0x1416e428, 0x40042d7440}, 0x40042e6ea0, 0x40049b0b80, {0x120ff600, 0x4003c11040})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x670
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x4003bfe300, {0x1416e428?, 0x40042d7380?}, 0x4001e379f0)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xaa4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0x4001aee5b0, {0x1416e428?, 0x40042d70b0?}, 0x4001e379f0)
	github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x400102e320, {0x1416e428?, 0x40042d66f0?}, 0x4000ca0a80)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x2b4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x11ec6d80, 0x400102e320}, {0x1416e428, 0x40042d66f0}, 0x4000c38d80, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x40012d0200, {0x1416e428, 0x40042d6660}, {0x141c4b20, 0x400051e180}, 0x40042d17a0, 0x4002087ce0, 0x1d5c0998, 0x0)
	google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x40012d0200, {0x141c4b20, 0x400051e180}, 0x40042d17a0)
	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 59
	google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c

Occurs when having no lambda config before, and adding one with a subsequent apply run

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 28, 2024
@hans-d
Copy link
Author

hans-d commented Jun 28, 2024

if v, ok := d.GetOk("lambda_config"); ok {
if v, ok := v.([]interface{})[0].(map[string]interface{}); ok && v != nil {
if d.HasChange("lambda_config.0.pre_token_generation") {
v["pre_token_generation_config"].([]interface{})[0].(map[string]interface{})["lambda_arn"] = d.Get("lambda_config.0.pre_token_generation")
}
if d.HasChange("lambda_config.0.pre_token_generation_config.0.lambda_arn") {
v["pre_token_generation"] = d.Get("lambda_config.0.pre_token_generation_config.0.lambda_arn")
}
input.LambdaConfig = expandLambdaConfigType(v)
}
}

So very specific re change in pre-generation

lambda_config {
          pre_token_generation = "arn:aws:lambda:eu-west-1:123456789012:layer:blah-pre-token"
        }

@ewbankkit
Copy link
Contributor

@hans-d Thanks for following up with this -- we'll fix for a likely patch release today addressing a couple of regressions.

@ewbankkit
Copy link
Contributor

I can reproduce with a new acceptance test case:

% make testacc TESTARGS='-run=TestAccCognitoIDPUserPool_addLambda' PKG=cognitoidp ACCTEST_PARALLELISM=3
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.4 test ./internal/service/cognitoidp/... -v -count 1 -parallel 3  -run=TestAccCognitoIDPUserPool_addLambda -timeout 360m
=== RUN   TestAccCognitoIDPUserPool_addLambda
=== PAUSE TestAccCognitoIDPUserPool_addLambda
=== CONT  TestAccCognitoIDPUserPool_addLambda
panic: runtime error: index out of range [0] with length 0

goroutine 3642 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp.resourceUserPoolUpdate({0x1186146b0, 0x14009865140}, 0x14009797b80, {0x118385700, 0x14009f880d0})
	/Users/kewbank/src/github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp/user_pool.go:1000 +0x2144
github.com/hashicorp/terraform-provider-aws/internal/provider.New.(*wrappedResource).Update.interceptedHandler[...].func10(0x14009797b80?, {0x118385700?, 0x14009f880d0})
	/Users/kewbank/src/github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:113 +0x1d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x1186146b0?, {0x1186146b0?, 0x140098a4660?}, 0xd?, {0x118385700?, 0x14009f880d0?})
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:835 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140024242a0, {0x1186146b0, 0x140098a4660}, 0x14009617930, 0x1400973d980, {0x118385700, 0x14009f880d0})
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x670
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x14005e138a8, {0x1186146b0?, 0x140098a45d0?}, 0x14003f99db0)
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xaa4
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0x14000322a10, {0x1186146b0?, 0x140098a4330?}, 0x14003f99db0)
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x184
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x14006d9e8c0, {0x1186146b0?, 0x1400977faa0?}, 0x14009759110)
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x2b4
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x118165aa0, 0x14006d9e8c0}, {0x1186146b0, 0x1400977faa0}, 0x1400973d280, 0x0)
	/Users/kewbank/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x14004e9f000, {0x1186146b0, 0x1400977fa10}, {0x11866a8e0, 0x1400822c180}, 0x140098917a0, 0x14009f6fc20, 0x121b0b8d8, 0x0)
	/Users/kewbank/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1369 +0xb58
google.golang.org/grpc.(*Server).handleStream(0x14004e9f000, {0x11866a8e0, 0x1400822c180}, 0x140098917a0)
	/Users/kewbank/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1780 +0xb20
google.golang.org/grpc.(*Server).serveStreams.func2.1()
	/Users/kewbank/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1019 +0x8c
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 1351
	/Users/kewbank/go/pkg/mod/google.golang.org/grpc@v1.63.2/server.go:1030 +0x13c
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp	30.141s
FAIL
make: *** [testacc] Error 1

Copy link

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.

@ewbankkit ewbankkit added this to the v5.56.1 milestone Jun 28, 2024
Copy link

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

Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2024
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/cognitoidp Issues and PRs that pertain to the cognitoidp service.
Projects
None yet
3 participants