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

provider crash on EFS data search - index out of range [0] with length 0 #21642

Closed
hamBank opened this issue Nov 4, 2021 · 8 comments · Fixed by #24298
Closed

provider crash on EFS data search - index out of range [0] with length 0 #21642

hamBank opened this issue Nov 4, 2021 · 8 comments · Fixed by #24298
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/efs Issues and PRs that pertain to the efs service.

Comments

@hamBank
Copy link

hamBank commented Nov 4, 2021

Hi,

I've got some code that queries for an existing efs filesystem with:
data "aws_efs_file_system" "saas" {
tags = {
Name = "scp-${var.env_name}-efs"
}
}

It previously worked just fine but when I re-ran yesterday I got a provider crash:

Stack trace from the terraform-provider-aws_v3.64.0_x5 plugin:

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

goroutine 113 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/efs.dataSourceFileSystemRead(0xc001072c00, 0x6a88d80, 0xc000eda000, 0xc353b60, 0xc00028a000)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/internal/service/efs/file_system_data_source.go:145 +0xf59
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0001a7b20, 0x860efa8, 0xc000b66900, 0xc001072c00, 0x6a88d80, 0xc000eda000, 0x0, 0x0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:335 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0001a7b20, 0x860efa8, 0xc000b66900, 0xc0020020c0, 0x6a88d80, 0xc000eda000, 0xc000eda000, 0xc0020020c0, 0x0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:558 +0xfd
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc00000ce70, 0x860efa8, 0xc000b66900, 0xc000c3f300, 0xc000b66900, 0x40b965, 0x746f920)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/gdavison/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1105 +0x4d6
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadDataSource(0xc00142d780, 0x860f050, 0xc000b66900, 0xc0011e8b90, 0xc00142d780, 0xc0013f1410, 0xc00149bba0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:247 +0xe5
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler(0x7775b00, 0xc00142d780, 0x860f050, 0xc0013f1410, 0xc0011f22a0, 0x0, 0x860f050, 0xc0013f1410, 0xc00061de60, 0x118)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:416 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0005d5880, 0x8632d98, 0xc001138480, 0xc00140a500, 0xc000b1c510, 0xc311cd0, 0x0, 0x0, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0005d5880, 0x8632d98, 0xc001138480, 0xc00140a500, 0x0)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000bffaa0, 0xc0005d5880, 0x8632d98, 0xc001138480, 0xc00140a500)
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
	/opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x1fd

Error: The terraform-provider-aws_v3.64.0_x5 plugin crashed!

I've tried downgrading the provider version and am seeing the same issue with 3.63 and 3.62.

The data dump from the sdk response (with some attempt at removing sensitive data):

2021-11-05T10:32:16.872+1100 [INFO]  provider.terraform-provider-aws_v3.62.0_x5: 2021/11/05 10:32:16 [DEBUG] [aws-sdk-go] {"FileSystems":[{"AvailabilityZoneId":null,"AvailabilityZoneName":null,"CreationTime":1.635170523E9,"CreationToken":"terraform-20211025140202919800000002","Encrypted":false,"FileSystemArn":"arn:aws:elasticfilesystem:eu-w
est-1:010930XXXX:file-system/fs-0f75c859bXXXX","FileSystemId":"fs-0f75c859bXXXX","KmsKeyId":null,"LifeCycleState":"available","Name":"XXXX-efs","NumberOfMountTargets":2,"OwnerId":"010930XXXX","PerformanceMode":"generalPurpose","ProvisionedThroughputInMibps":null,"SizeInBytes":{"Timestamp":1.636068345E9,"Value":733184,"Va
lueInIA":0,"ValueInStandard":733184},"Tags":[{"Key":"Application","Value":"XXXX"},{"Key":"BusinessUnit","Value":"XXXX"},{"Key":"CostCenter","Value":""},{"Key":"Customer","Value":"Multi-Tenant"},{"Key":"Environment","Value":"XXXX"},{"Key":"Name","Value":"XXXX-efs"},{"Key":"SsmBootStrap","Value":"true"},{"Key":"environment",
"Value":"XXXX"},{"Key":"region","Value":"eu-west-1"}],"ThroughputMode":"bursting"},{"AvailabilityZoneId":null,"AvailabilityZoneName":null,"CreationTime":1.631200422E9,"CreationToken":"terraform-20210909151341995400000002","Encrypted":false,"FileSystemArn":"arn:aws:elasticfilesystem:eu-west-1:010930XXXX:file-system/fs-XXXXX","FileSy
stemId":"fs-XXXX","KmsKeyId":null,"LifeCycleState":"available","Name":"XXXX-efs","NumberOfMountTargets":2,"OwnerId":"010930XXXX","PerformanceMode":"generalPurpose","ProvisionedThroughputInMibps":null,"SizeInBytes":{"Timestamp":1.636067874E9,"Value":1365891072,"ValueInIA":1164189696,"ValueInStandard":201701376},"Tags":[{"Key":"
Application","Value":"XXXX"},{"Key":"BusinessUnit","Value":"XXXX"},{"Key":"CostCenter","Value":""},{"Key":"Customer","Value":"Multi-Tenant"},{"Key":"Environment","Value":"XXXX"},{"Key":"Name","Value":"XXXXX-efs"},{"Key":"SsmBootStrap","Value":"true"},{"Key":"environment","Value":"XXXX"},{"Key":"region","Value":"eu-west-
1"}],"ThroughputMode":"bursting"},{"AvailabilityZoneId":null,"AvailabilityZoneName":null,"CreationTime":1.620222384E9,"CreationToken":"terraform-20210505134623952400000002","Encrypted":false,"FileSystemArn":"arn:aws:elasticfilesystem:eu-west-1:010930XXXX:file-system/fs-XXXX","FileSystemId":"fs-XXXX","KmsKeyId":null,"LifeCycleState
":"available","Name":"XXXXX-efs","NumberOfMountTargets":2,"OwnerId":"010930XXXXX","PerformanceMode":"generalPurpose","ProvisionedThroughputInMibps":null,"SizeInBytes":{"Timestamp":1.636067757E9,"Value":26593943552,"ValueInIA":25635057664,"ValueInStandard":958885888},"Tags":[{"Key":"Application","Value":"XXXX"},{"Key":"BusinessUnit",
"Value":"XXXX"},{"Key":"CostCenter","Value":""},{"Key":"Customer","Value":"Multi-Tenant"},{"Key":"Environment","Value":"XXXX"},{"Key":"Name","Value":"XXXX-efs"},{"Key":"SsmBootStrap","Value":"true"},{"Key":"environment","Value":"XXXX"},{"Key":"region","Value":"eu-west-1"}],"ThroughputMode":"bursting"}],"Marker":null,"NextMarker":n
ull}: timestamp=2021-11-05T10:32:16.872+1100
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/efs Issues and PRs that pertain to the efs service. labels Nov 4, 2021
@ewbankkit
Copy link
Contributor

var results []*efs.FileSystemDescription
if len(tagsToMatch) > 0 {
var fileSystems []*efs.FileSystemDescription
for _, fileSystem := range describeResp.FileSystems {
tags := KeyValueTags(fileSystem.Tags)
if !tags.ContainsAll(tagsToMatch) {
continue
}
fileSystems = append(fileSystems, fileSystem)
}
results = fileSystems
} else {
results = describeResp.FileSystems
}
if len(results) > 1 {
return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(results))
}
fs := results[0]

Relates: #18097.
Relates: #20399.

@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Nov 5, 2021
@edmundcraske-bjss
Copy link
Contributor

I've just tried to use an aws_efs_file_system data source myself and am hitting the same issue. Is this still an issue for you @hamBank ? I'm not sure what I can do to fix/work around it...

@veromos
Copy link

veromos commented Jan 11, 2022

@edmundcraske-bjss
I encountered the same error, verify that your tag is corresponding to an existing one. Mine was incorrect.

The plugin should display : data source return nothing instead of a "Error: rpc error: code = Unavailable desc = transport is closing"

@edmundcraske-bjss
Copy link
Contributor

Ah yes, I was indeed passing the wrong tag values, so it wasn't finding anything. Thankfully once I fixed my mistake it is working! It really shouldn't crash though if it doesn't find anything?!

@limratechnologies
Copy link

Just encounter the same issue. It doesn't have to crash if data doesn't return anything

@limratechnologies
Copy link

This is weird, data crashes even when the tag keys and values are correct in the case of target file system ID is "short" eg., fs-95138ead. However the same thing is able to pull the file system id is long eg., "fs-0c9826306472877b6". Is someone able to replicate this behaviour?

@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 May 19, 2022
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/efs Issues and PRs that pertain to the efs service.
Projects
None yet
5 participants