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]: panic in aws_iam_policy_document data source #33060

Closed
dpowley opened this issue Aug 16, 2023 · 4 comments · Fixed by #33093
Closed

[Bug]: panic in aws_iam_policy_document data source #33060

dpowley opened this issue Aug 16, 2023 · 4 comments · Fixed by #33093
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/iam Issues and PRs that pertain to the iam service.
Milestone

Comments

@dpowley
Copy link
Contributor

dpowley commented Aug 16, 2023

Terraform Core Version

1.3.7

AWS Provider Version

5.12.0

Affected Resource(s)

  • aws_iam_policy_document

Expected Behavior

Should not panic and instead handle the error.

Actual Behavior

Panic (output below)

Relevant Error/Panic Output Snippet

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

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

goroutine 364 [running]:
encoding/json.(*encodeState).marshal.func1()
	encoding/json/encode.go:326 +0x6e
panic({0xbe99100, 0xc00255fb00})
	runtime/panic.go:884 +0x213
github.com/hashicorp/terraform-provider-aws/internal/service/iam.IAMPolicyStatementConditionSet.MarshalJSON({0xc0025bc6c0, 0x2, 0xc0002df300?})
	github.com/hashicorp/terraform-provider-aws/internal/service/iam/policy_model.go:186 +0x513
encoding/json.addrMarshalerEncoder(0xc002ab4380, {0xb9c1a20?, 0xc0002df3d0?, 0xaf5f680?}, {0xa0?, 0xca?})
	encoding/json/encode.go:494 +0x102
encoding/json.condAddrEncoder.encode({0xd5b7778?, 0xd5b77c8?}, 0x50dc15?, {0xb9c1a20?, 0xc0002df3d0?, 0x1000000000130?}, {0xc?, 0x0?})
	encoding/json/encode.go:958 +0x4a
encoding/json.structEncoder.encode({{{0xc001af9b00?, 0x0?, 0xc002062560?}, 0xc001d5b110?}}, 0xc002ab4380, {0xd009520?, 0xc0002df340?, 0xc0013dd440?}, {0x0, 0x1})
	encoding/json/encode.go:759 +0x1f4
encoding/json.ptrEncoder.encode({0x18?}, 0xc002ab4380, {0xad7d800?, 0xc00254f8c0?, 0xc002062560?}, {0x6a?, 0xb7?})
	encoding/json/encode.go:943 +0x21c
encoding/json.arrayEncoder.encode({0xae31600?}, 0xc002ab4380, {0xadf7c40?, 0xc00251be60?, 0x0?}, {0x7f?, 0xce?})
	encoding/json/encode.go:914 +0xd5
encoding/json.sliceEncoder.encode({0xc002062758?}, 0xc002ab4380, {0xadf7c40?, 0xc00251be60?, 0xc0020629a8?}, {0xc?, 0x0?})
	encoding/json/encode.go:887 +0x32f
encoding/json.structEncoder.encode({{{0xc001d70240?, 0x18?, 0x18?}, 0xc001d5b170?}}, 0xc002ab4380, {0xc60dca0?, 0xc00251be40?, 0x18?}, {0x0, 0x1})
	encoding/json/encode.go:759 +0x1f4
encoding/json.ptrEncoder.encode({0xc0013dd440?}, 0xc002ab4380, {0xb9936c0?, 0xc00251be40?, 0xb9936c0?}, {0x0?, 0x9?})
	encoding/json/encode.go:943 +0x21c
encoding/json.(*encodeState).reflectValue(0xc002062a10?, {0xb9936c0?, 0xc00251be40?, 0x0?}, {0xe0?, 0xdb?})
	encoding/json/encode.go:358 +0x78
encoding/json.(*encodeState).marshal(0x80000000ad7d800?, {0xb9936c0?, 0xc00251be40?}, {0x38?, 0x21?})
	encoding/json/encode.go:330 +0xfa
encoding/json.Marshal({0xb9936c0, 0xc00251be40})
	encoding/json/encode.go:161 +0xe5
encoding/json.MarshalIndent({0xb9936c0?, 0xc00251be40?}, {0x0, 0x0}, {0xd329e6b, 0x2})
	encoding/json/encode.go:174 +0x4a
github.com/hashicorp/terraform-provider-aws/internal/service/iam.dataSourcePolicyDocumentRead({0x14734848?, 0xc002214600?}, 0xd2c8580?, {0xc001949d40?, 0x0?})
	github.com/hashicorp/terraform-provider-aws/internal/service/iam/policy_document_data_source.go:264 +0x32a
github.com/hashicorp/terraform-provider-aws/internal/provider.interceptedHandler[...].func1(0x0?, {0xd2c8580?, 0xc001949d40?})
	github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:111 +0x34b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xe5bbae0?, {0xe5bbae0?, 0xc002214600?}, 0xd?, {0xd2c8580?, 0xc001949d40?})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:745 +0x87
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0013f17a0, {0xe5bbae0, 0xc002214600}, 0xc002240800, {0xd2c8580, 0xc001949d40})
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:970 +0x150
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc0044ab9b0, {0xe5bbae0?, 0xc0022144e0?}, 0xc0020dcf80)
	github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:1198 +0x38f
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ReadDataSource({0xc00193bef0, 0xc004b93be0, 0xc00193bf20, 0xc00193bf50, {0xc0041bde20, 0x2, 0x2}}, {0xe5bbae0?, 0xc0022141b0?}, 0xc0020dcf80)
	github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf5muxserver/mux_server_ReadDataSource.go:30 +0x139
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadDataSource(0xc00255a000, {0xe5bbae0?, 0xc0020fb9e0?}, 0xc002b2e4b0)
	github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:661 +0x403
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0xd04baa0?, 0xc00255a000}, {0xe5bbae0, 0xc0020fb9e0}, 0xc000edf810, 0x0)
	github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:458 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00019e780, {0xe5c8b80, 0xc001a02820}, 0xc00220c5a0, 0xc001963d70, 0x146e5770, 0x0)
	google.golang.org/grpc@v1.56.1/server.go:1337 +0xdf3
google.golang.org/grpc.(*Server).handleStream(0xc00019e780, {0xe5c8b80, 0xc001a02820}, 0xc00220c5a0, 0x0)
	google.golang.org/grpc@v1.56.1/server.go:1714 +0xa36
google.golang.org/grpc.(*Server).serveStreams.func1.1()
	google.golang.org/grpc@v1.56.1/server.go:959 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/grpc@v1.56.1/server.go:957 +0x18c

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

Operation failed: failed running terraform plan (exit 1)

Terraform Configuration Files

I'm happy to help reproduce, but would like to keep the configuration we are working with private.

Steps to Reproduce

I'm happy to help reproduce, but would like to keep the configuration we are working with private.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

@dpowley dpowley added the bug Addresses a defect in current functionality. label Aug 16, 2023
@github-actions
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.

@github-actions github-actions bot added crash Results from or addresses a Terraform crash or kernel panic. service/iam Issues and PRs that pertain to the iam service. labels Aug 16, 2023
@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Aug 16, 2023
@jar-b jar-b removed the needs-triage Waiting for first response or review from a maintainer. label Aug 16, 2023
@jar-b
Copy link
Member

jar-b commented Aug 17, 2023

Relates #33026

Reproduced with a minimal config:

data "aws_iam_policy_document" "test" {
  statement {
    actions = [
      "s3:ListBucket",
    ]

    resources = [
      "arn:aws:s3:::my-bucket",
    ]

    condition {
      test     = "StringLike"
      variable = "s3:prefix"
      values = ["one/"]
    }
    condition {
      test     = "StringLike"
      variable = "s3:prefix"
      values = ["two/", "three/"]
    }
  }
}
% terraform plan
data.aws_iam_policy_document.test: Reading...

Planning failed. Terraform encountered an error while generating this plan.


│ Error: Plugin did not respond

│   with data.aws_iam_policy_document.test,
│   on main.tf line 13, in data "aws_iam_policy_document" "test":
│   13: data "aws_iam_policy_document" "test" {

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


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

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

goroutine 295 [running]:
encoding/json.(*encodeState).marshal.func1()
        encoding/json/encode.go:326 +0x80
panic({0x10cb19e80, 0x14001657740})
        runtime/panic.go:884 +0x204
github.com/hashicorp/terraform-provider-aws/internal/service/iam.IAMPolicyStatementConditionSet.MarshalJSON({0x1400068d860, 0x2, 0x100?})
        github.com/hashicorp/terraform-provider-aws/internal/service/iam/policy_model.go:186 +0x4bc
encoding/json.addrMarshalerEncoder(0x1400411b500, {0x10c642760?, 0x1400517b690?, 0x1400411b500?}, {0x20?, 0xfd?})
        encoding/json/encode.go:494 +0xe8
encoding/json.condAddrEncoder.encode({0x10dfacd48?, 0x10dfacd98?}, 0x140032242b8?, {0x10c642760?, 0x1400517b690?, 0x101244fcc?}, {0x1?, 0x0?})
        encoding/json/encode.go:958 +0x50
encoding/json.structEncoder.encode({{{0x14001698900?, 0x101246900?, 0x0?}, 0x14001657620?}}, 0x1400411b500, {0x10dc8c0e0?, 0x1400517b600?, 0x14003f530c0?}, {0x0?, 0x0?})
        encoding/json/encode.go:759 +0x178
encoding/json.ptrEncoder.encode({0x140032244d8?}, 0x1400411b500, {0x10b9fdb20?, 0x14003f530c0?, 0x0?}, {0x0?, 0x0?})
        encoding/json/encode.go:943 +0x1c4
encoding/json.arrayEncoder.encode({0x14003224618?}, 0x1400411b500, {0x10ba78020?, 0x140017d7a60?, 0x14003224598?}, {0xd0?, 0x5?})
        encoding/json/encode.go:914 +0xc0
encoding/json.sliceEncoder.encode({0x140032246e8?}, 0x1400411b500, {0x10ba78020?, 0x140017d7a60?, 0x14003224718?}, {0xc?, 0x0?})
        encoding/json/encode.go:887 +0x260
encoding/json.structEncoder.encode({{{0x1400168e480?, 0x101246900?, 0x13f1b5c98?}, 0x14001657680?}}, 0x1400411b500, {0x10d28ffe0?, 0x140017d7a40?, 0x140017d7a40?}, {0x18?, 0x48?})
        encoding/json/encode.go:759 +0x178
encoding/json.ptrEncoder.encode({0x14003224908?}, 0x1400411b500, {0x10c6141c0?, 0x140017d7a40?, 0x1400134b540?}, {0xa0?, 0x34?})
        encoding/json/encode.go:943 +0x1c4
encoding/json.(*encodeState).reflectValue(0x140032249b8?, {0x10c6141c0?, 0x140017d7a40?, 0x140036d08b8?}, {0x0?, 0x0?})
        encoding/json/encode.go:358 +0x70
encoding/json.(*encodeState).marshal(0x800014003224a01?, {0x10c6141c0?, 0x140017d7a40?}, {0xb8?, 0x8?})
        encoding/json/encode.go:330 +0x120
encoding/json.Marshal({0x10c6141c0, 0x140017d7a40})
        encoding/json/encode.go:161 +0x94
encoding/json.MarshalIndent({0x10c6141c0?, 0x140017d7a40?}, {0x0, 0x0}, {0x10a149302, 0x2})
        encoding/json/encode.go:174 +0x34
github.com/hashicorp/terraform-provider-aws/internal/service/iam.dataSourcePolicyDocumentRead({0x114192380?, 0x1400160d0b0?}, 0x10df4af40?, {0x140031491e0?, 0x0?})
        github.com/hashicorp/terraform-provider-aws/internal/service/iam/policy_document_data_source.go:264 +0x260
github.com/hashicorp/terraform-provider-aws/internal/provider.interceptedHandler[...].func1(0x0?, {0x10df4af40?, 0x140031491e0?})
        github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:111 +0x28c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x10e0e4560?, {0x10e0e4560?, 0x1400160d0b0?}, 0xd?, {0x10df4af40?, 0x140031491e0?})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:745 +0x64
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0x140013437a0, {0x10e0e4560, 0x1400160d0b0}, 0x14003121180, {0x10df4af40, 0x140031491e0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:970 +0x130
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0x140022e35f0, {0x10e0e4560?, 0x1400160cf90?}, 0x140014a95a0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:1198 +0x304
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ReadDataSource({0x14003133aa0, 0x14004eef500, 0x14003133ad0, 0x14003133b00, {0x1400315a460, 0x2, 0x2}}, {0x10e0e4560?, 0x1400160cc60?}, 0x140014a95a0)
        github.com/hashicorp/terraform-plugin-mux@v0.11.2/tf5muxserver/mux_server_ReadDataSource.go:30 +0x100
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadDataSource(0x140031425a0, {0x10e0e4560?, 0x1400160c2d0?}, 0x14004125220)
        github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:661 +0x368
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0x10dcce7a0?, 0x140031425a0}, {0x10e0e4560, 0x1400160c2d0}, 0x140013b8000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:458 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x140004e0960, {0x10e0f1500, 0x140032089c0}, 0x1400157d440, 0x140032038f0, 0x11413d650, 0x0)
        google.golang.org/grpc@v1.56.1/server.go:1337 +0xc90
google.golang.org/grpc.(*Server).handleStream(0x140004e0960, {0x10e0f1500, 0x140032089c0}, 0x1400157d440, 0x0)
        google.golang.org/grpc@v1.56.1/server.go:1714 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.56.1/server.go:959 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.56.1/server.go:957 +0x16c

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

@github-actions
Copy link

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

@github-actions
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 Sep 24, 2023
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/iam Issues and PRs that pertain to the iam service.
Projects
None yet
2 participants