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

Crash with bad service_type in aws_vpc_endpoint_service #17419

Closed
gotrevor opened this issue Feb 3, 2021 · 3 comments · Fixed by #17641
Closed

Crash with bad service_type in aws_vpc_endpoint_service #17419

gotrevor opened this issue Feb 3, 2021 · 3 comments · Fixed by #17641
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@gotrevor
Copy link

gotrevor commented Feb 3, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • 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
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.14.5
+ provider registry.terraform.io/hashicorp/aws v3.26.0

Affected Resource(s)

  • data aws_vpc_endpoint_service

Terraform Configuration Files

provider "aws" {
  region = "us-west-2"
}

data "aws_vpc_endpoint_service" "s3-g" {
  count        = 1
  service      = "s3"
  service_type = "gateway" // The 'g' in 'gateway' should be capitalized
}

Debug Output

Skipping. Trivial to reproduce.

Panic Output

Relevant lines:

2021-02-02T16:49:11.048-0500 [DEBUG] plugin.terraform-provider-aws_v3.26.0_x5: panic: runtime error: index out of range [0] with length 0
2021-02-02T16:49:11.048-0500 [DEBUG] plugin.terraform-provider-aws_v3.26.0_x5: 
2021-02-02T16:49:11.048-0500 [DEBUG] plugin.terraform-provider-aws_v3.26.0_x5: goroutine 119 [running]:
2021-02-02T16:49:11.048-0500 [DEBUG] plugin.terraform-provider-aws_v3.26.0_x5: github.com/terraform-providers/terraform-provider-aws/aws.dataSourceAwsVpcEndpointServiceRead(0xc0016d0400, 0x66ec4c0, 0xc0017bc000, 0xb28c9b0, 0x7513270)

Expected Behavior

A non-crash error indicating that no vpc endpoints were found. Possibly an error that service_type is invalid. Per the documentation, Gateway and Interface are valid values. The crash results from an invalid value.

Actual Behavior

Crash

Steps to Reproduce

  1. terraform init
  2. terraform plan
@ghost ghost added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service. labels Feb 3, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 3, 2021
@bflad bflad removed the needs-triage Waiting for first response or review from a maintainer. label Feb 3, 2021
@ewbankkit
Copy link
Contributor

ewbankkit commented Feb 3, 2021

Fuller stack trace:

2021-02-03T08:14:45.984-0500 [DEBUG] plugin: plugin exited
panic: runtime error: index out of range [0] with length 0
2021-02-03T08:14:45.967-0500 [DEBUG] plugin.terraform-provider-aws: 
2021-02-03T08:14:45.967-0500 [DEBUG] plugin.terraform-provider-aws: goroutine 68 [running]:
2021-02-03T08:14:45.968-0500 [DEBUG] plugin.terraform-provider-aws: github.com/terraform-providers/terraform-provider-aws/aws.dataSourceAwsVpcEndpointServiceRead(0xc001953f80, 0x5af8d60, 0xc001b54680, 0xa68cea0, 0x6920d48)
2021-02-03T08:14:45.969-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/src/github.com/terraform-providers/terraform-provider-aws/aws/data_source_aws_vpc_endpoint_service.go:159 +0x15b1
2021-02-03T08:14:45.970-0500 [DEBUG] plugin.terraform-provider-aws: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0001af8c0, 0x7242b00, 0xc0006dc7c0, 0xc001953f80, 0x5af8d60, 0xc001b54680, 0x0, 0x0, 0x0)
2021-02-03T08:14:45.970-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:290 +0x88
2021-02-03T08:14:45.970-0500 [DEBUG] plugin.terraform-provider-aws: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc0001af8c0, 0x7242b00, 0xc0006dc7c0, 0xc0006f9d80, 0x5af8d60, 0xc001b54680, 0xc001b54680, 0xc0006f9d80, 0x0, 0x0)
2021-02-03T08:14:45.971-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:498 +0xfd
2021-02-03T08:14:45.971-0500 [DEBUG] plugin.terraform-provider-aws: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc000ecddc0, 0x7242b00, 0xc0006dc7c0, 0xc0006f9a40, 0xc0006dc7c0, 0x634be40, 0x65ea300)
2021-02-03T08:14:45.971-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1105 +0x4d4
2021-02-03T08:14:45.972-0500 [DEBUG] plugin.terraform-provider-aws: github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadDataSource(0xc00151a9c0, 0x7242b00, 0xc0006dc7c0, 0xc001d0bd10, 0xc00151a9c0, 0xc0013a7ce0, 0xc00008eba0)
2021-02-03T08:14:45.972-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:247 +0xe5
2021-02-03T08:14:45.974-0500 [DEBUG] plugin.terraform-provider-aws: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler(0x65ea300, 0xc00151a9c0, 0x7242bc0, 0xc0013a7ce0, 0xc000e54480, 0x0, 0x7242bc0, 0xc0013a7ce0, 0xc0003cb560, 0x103)
2021-02-03T08:14:45.975-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:416 +0x214
2021-02-03T08:14:45.975-0500 [DEBUG] plugin.terraform-provider-aws: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00059ae00, 0x7265aa0, 0xc001340600, 0xc000132600, 0xc0006b4300, 0xa64b7d0, 0x0, 0x0, 0x0)
2021-02-03T08:14:45.975-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0x522
2021-02-03T08:14:45.976-0500 [DEBUG] plugin.terraform-provider-aws: google.golang.org/grpc.(*Server).handleStream(0xc00059ae00, 0x7265aa0, 0xc001340600, 0xc000132600, 0x0)
2021-02-03T08:14:45.976-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0xd05
2021-02-03T08:14:45.976-0500 [DEBUG] plugin.terraform-provider-aws: google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000f56160, 0xc00059ae00, 0x7265aa0, 0xc001340600, 0xc000132600)
2021-02-03T08:14:45.977-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/google.golang.org/[email protected]/server.go:859 +0xa5
2021-02-03T08:14:45.977-0500 [DEBUG] plugin.terraform-provider-aws: created by google.golang.org/grpc.(*Server).serveStreams.func1
2021-02-03T08:14:45.977-0500 [DEBUG] plugin.terraform-provider-aws: 	/home/kit/wrk/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x1fd

var serviceDetails []*ec2.ServiceDetail
// Client-side filtering. When the EC2 API supports this functionality
// server-side it should be moved.
for _, serviceDetail := range resp.ServiceDetails {
if serviceDetail == nil {
continue
}
if v, ok := d.GetOk("service_type"); ok {
if len(serviceDetail.ServiceType) > 0 && serviceDetail.ServiceType[0] != nil && v.(string) != aws.StringValue(serviceDetail.ServiceType[0].ServiceType) {
continue
}
}
serviceDetails = append(serviceDetails, serviceDetail)
}
if len(serviceDetails) > 1 {
return fmt.Errorf("multiple VPC Endpoint Services matched; use additional constraints to reduce matches to a single VPC Endpoint Service")
}
sd := serviceDetails[0]

<?xml version="1.0" encoding="UTF-8"?>
<DescribeVpcEndpointServicesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
    <requestId>c2678f56-fe75-4374-b47e-870c376a4754</requestId>
    <serviceDetailSet>
        <item>
            <acceptanceRequired>false</acceptanceRequired>
            <availabilityZoneSet>
                <item>us-west-2a</item>
                <item>us-west-2b</item>
                <item>us-west-2c</item>
                <item>us-west-2d</item>
            </availabilityZoneSet>
            <baseEndpointDnsNameSet>
                <item>s3.us-west-2.vpce.amazonaws.com</item>
            </baseEndpointDnsNameSet>
            <managesVpcEndpoints>false</managesVpcEndpoints>
            <owner>amazon</owner>
            <serviceId>vpce-svc-0b5d83f29260cde0d</serviceId>
            <serviceName>com.amazonaws.us-west-2.s3</serviceName>
            <serviceType>
                <item>
                    <serviceType>Interface</serviceType>
                </item>
            </serviceType>
            <tagSet/>
            <vpcEndpointPolicySupported>true</vpcEndpointPolicySupported>
        </item>
        <item>
            <acceptanceRequired>false</acceptanceRequired>
            <availabilityZoneSet>
                <item>us-west-2-lax-1a</item>
                <item>us-west-2-lax-1b</item>
                <item>us-west-2-wl1-den-wlz-1</item>
                <item>us-west-2-wl1-las-wlz-1</item>
                <item>us-west-2-wl1-sea-wlz-1</item>
                <item>us-west-2-wl1-sfo-wlz-1</item>
                <item>us-west-2a</item>
                <item>us-west-2b</item>
                <item>us-west-2c</item>
                <item>us-west-2d</item>
            </availabilityZoneSet>
            <baseEndpointDnsNameSet>
                <item>s3.us-west-2.amazonaws.com</item>
            </baseEndpointDnsNameSet>
            <owner>amazon</owner>
            <serviceId>vpce-svc-0001be97e1865c74e</serviceId>
            <serviceName>com.amazonaws.us-west-2.s3</serviceName>
            <serviceType>
                <item>
                    <serviceType>Gateway</serviceType>
                </item>
            </serviceType>
            <tagSet/>
            <vpcEndpointPolicySupported>true</vpcEndpointPolicySupported>
        </item>
    </serviceDetailSet>
    <serviceNameSet>
        <item>com.amazonaws.us-west-2.s3</item>
        <item>com.amazonaws.us-west-2.s3</item>
    </serviceNameSet>
</DescribeVpcEndpointServicesResponse>

bflad added a commit that referenced this issue Feb 16, 2021
… update CHANGELOG for #17641

Reference: #17419

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (21.03s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (22.39s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (22.48s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (23.76s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (230.43s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (235.33s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (238.79s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (30.12s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (30.15s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (30.16s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (30.16s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (249.96s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (259.01s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (261.24s)
```
bflad added a commit that referenced this issue Mar 18, 2021
…rom client-side to API (#17641)

* data-soruce/aws_vpc_endpoint_service: Switch service_type filtering from client-side to API

Reference: #17417

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (12.25s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (12.65s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (12.65s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (12.65s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (217.41s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (219.87s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (228.91s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (16.05s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (16.25s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (16.26s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (16.26s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (229.07s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (229.30s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (229.52s)
```

* Update CHANGELOG for #17641

* data-source/aws_vpc_endpoint_service: Validate service_type argument, update CHANGELOG for #17641

Reference: #17419

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (21.03s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (22.39s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (22.48s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (23.76s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (230.43s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (235.33s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (238.79s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (30.12s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Interface (30.15s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (30.16s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_ServiceType_Gateway (30.16s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter_tags (249.96s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (259.01s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom_filter (261.24s)
```
@github-actions github-actions bot added this to the v3.33.0 milestone Mar 18, 2021
@ghost
Copy link

ghost commented Mar 18, 2021

This has been released in version 3.33.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 for triage. Thanks!

@ghost
Copy link

ghost commented Apr 18, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 18, 2021
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/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
3 participants