From 019d097c3dff0df2c4facfcc5f4b9a8eabe154b8 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Sat, 24 Feb 2018 15:28:05 -0500 Subject: [PATCH 1/2] Service details not yet available in GovCloud. Revert to logic from 1.8 for GovCloud until service details are supported. --- aws/data_source_aws_vpc_endpoint_service.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/aws/data_source_aws_vpc_endpoint_service.go b/aws/data_source_aws_vpc_endpoint_service.go index 428747cca61..abab39f1209 100644 --- a/aws/data_source_aws_vpc_endpoint_service.go +++ b/aws/data_source_aws_vpc_endpoint_service.go @@ -65,6 +65,7 @@ func dataSourceAwsVpcEndpointService() *schema.Resource { func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn + isGovCloud := meta.(*AWSClient).IsGovCloud() var serviceName string if v, ok := d.GetOk("service_name"); ok { @@ -85,6 +86,21 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{ if err != nil { return fmt.Errorf("Error fetching VPC Endpoint Services: %s", err) } + + // Note: AWS Commercial now returns a response with `ServiceNames` and + // `ServiceDetails`, but GovCloud responses only include `ServiceNames` + if isGovCloud && resp.ServiceDetails == nil { + if resp == nil || len(resp.ServiceNames) == 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") + } + d.SetId(strconv.Itoa(hashcode.String(*resp.ServiceNames[0]))) + d.Set("service_name", resp.ServiceNames[0]) + return nil + } + if resp == nil || len(resp.ServiceDetails) == 0 { return fmt.Errorf("no matching VPC Endpoint Service found") } From e683b84db9755366cdefc18cff84c6f23861b984 Mon Sep 17 00:00:00 2001 From: Joshua Carp Date: Sat, 3 Mar 2018 13:51:06 -0500 Subject: [PATCH 2/2] Simplify backwards compatibility for vpc endpoint service. h/t @bflad --- aws/data_source_aws_vpc_endpoint_service.go | 24 ++++++++------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/aws/data_source_aws_vpc_endpoint_service.go b/aws/data_source_aws_vpc_endpoint_service.go index abab39f1209..62a5d342b52 100644 --- a/aws/data_source_aws_vpc_endpoint_service.go +++ b/aws/data_source_aws_vpc_endpoint_service.go @@ -65,7 +65,6 @@ func dataSourceAwsVpcEndpointService() *schema.Resource { func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - isGovCloud := meta.(*AWSClient).IsGovCloud() var serviceName string if v, ok := d.GetOk("service_name"); ok { @@ -87,27 +86,22 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error fetching VPC Endpoint Services: %s", err) } + if resp == nil || len(resp.ServiceNames) == 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 isGovCloud && resp.ServiceDetails == nil { - if resp == nil || len(resp.ServiceNames) == 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") - } + if len(resp.ServiceDetails) == 0 { d.SetId(strconv.Itoa(hashcode.String(*resp.ServiceNames[0]))) d.Set("service_name", resp.ServiceNames[0]) return nil } - if resp == nil || len(resp.ServiceDetails) == 0 { - 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] serviceName = aws.StringValue(sd.ServiceName) d.SetId(strconv.Itoa(hashcode.String(serviceName)))