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

Service details not yet available in GovCloud. #3514

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions aws/data_source_aws_vpc_endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, this line can cause a panic if resp == 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")
}
Expand Down