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

data_source/aws_vpc_endpoint: Exposing prefix_list_id in datasource #1733

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion aws/data_source_aws_vpc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -39,12 +40,16 @@ func dataSourceAwsVpcEndpoint() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"route_table_ids": &schema.Schema{
"route_table_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"prefix_list_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -89,12 +94,36 @@ func dataSourceAwsVpcEndpointRead(d *schema.ResourceData, meta interface{}) erro
return errwrap.Wrapf("policy contains an invalid JSON: {{err}}", err)
}

prefixListServiceName := *vpce.ServiceName
prefixListInput := &ec2.DescribePrefixListsInput{
Filters: []*ec2.Filter{
{Name: aws.String("prefix-list-name"), Values: []*string{aws.String(prefixListServiceName)}},
},
}
log.Printf("[DEBUG] Reading VPC Endpoint prefix list: %s", prefixListServiceName)
prefixListsOutput, err := conn.DescribePrefixLists(prefixListInput)

if err != nil {
_, ok := err.(awserr.Error)
if !ok {
return fmt.Errorf("Error reading VPC Endpoint prefix list: %s", err.Error())
}
}

if len(prefixListsOutput.PrefixLists) != 1 {
return fmt.Errorf("There are multiple prefix lists associated with the service name '%s'. Unexpected", prefixListServiceName)
}

d.SetId(aws.StringValue(vpce.VpcEndpointId))
d.Set("id", vpce.VpcEndpointId)
d.Set("state", vpce.State)
d.Set("vpc_id", vpce.VpcId)
d.Set("service_name", vpce.ServiceName)
d.Set("policy", policy)

pl := prefixListsOutput.PrefixLists[0]
d.Set("prefix_list_id", pl.PrefixListId)

if err := d.Set("route_table_ids", aws.StringValueSlice(vpce.RouteTableIds)); err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions aws/data_source_aws_vpc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ func TestAccDataSourceAwsVpcEndpoint_basic(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDataSourceAwsVpcEndpointConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsVpcEndpointCheckExists("data.aws_vpc_endpoint.s3"),
resource.TestCheckResourceAttrSet("data.aws_vpc_endpoint.s3", "prefix_list_id"),
),
ExpectNonEmptyPlan: true,
},
Expand All @@ -29,7 +30,7 @@ func TestAccDataSourceAwsVpcEndpoint_withRouteTable(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDataSourceAwsVpcEndpointWithRouteTableConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsVpcEndpointCheckExists("data.aws_vpc_endpoint.s3"),
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/vpc_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ The given filters must match exactly one VPC endpoint whose data will be exporte
All of the argument attributes are also exported as result attributes.

* `policy` - The policy document associated with the VPC Endpoint.

* `route_table_ids` - One or more route tables associated with the VPC Endpoint.
* `prefix_list_id` - The prefix list ID of the exposed service.