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

d/aws_vpc_endpoint_service: GovCloud doesn't respect the VPC Endpoint Service service names filter #4592

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions aws/data_source_aws_vpc_endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,28 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error fetching VPC Endpoint Services: %s", err)
}

if resp == nil || len(resp.ServiceNames) == 0 {
if resp == nil || (len(resp.ServiceNames) == 0 && len(resp.ServiceDetails) == 0) {
return fmt.Errorf("no matching VPC Endpoint Service found")
}

if len(resp.ServiceNames) > 1 {
return fmt.Errorf("multiple VPC Endpoint Services matched; use additional constraints to reduce matches to a single VPC Endpoint Service")
}

// Note: AWS Commercial now returns a response with `ServiceNames` and
// `ServiceDetails`, but GovCloud responses only include `ServiceNames`
if len(resp.ServiceDetails) == 0 {
d.SetId(strconv.Itoa(hashcode.String(*resp.ServiceNames[0])))
d.Set("service_name", resp.ServiceNames[0])
return nil
// GovCloud doesn't respect the filter.
names := aws.StringValueSlice(resp.ServiceNames)
for _, name := range names {
if name == serviceName {
d.SetId(strconv.Itoa(hashcode.String(name)))
d.Set("service_name", name)
return nil
}
}

return fmt.Errorf("no matching VPC Endpoint Service found")
}

if len(resp.ServiceDetails) > 1 {
return fmt.Errorf("multiple VPC Endpoint Services matched; use additional constraints to reduce matches to a single VPC Endpoint Service")
}

sd := resp.ServiceDetails[0]
Expand Down