diff --git a/aws/data_source_aws_vpc_endpoint_service.go b/aws/data_source_aws_vpc_endpoint_service.go index 62a5d342b52..b4eaa5e7dd9 100644 --- a/aws/data_source_aws_vpc_endpoint_service.go +++ b/aws/data_source_aws_vpc_endpoint_service.go @@ -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]