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: Add 'arn' attribute #13852

Merged
merged 2 commits into from
Jun 23, 2020
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
14 changes: 14 additions & 0 deletions 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/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
Expand All @@ -16,6 +17,10 @@ func dataSourceAwsVpcEndpoint() *schema.Resource {
Read: dataSourceAwsVpcEndpointRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"cidr_blocks": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -154,6 +159,15 @@ func dataSourceAwsVpcEndpointRead(d *schema.ResourceData, meta interface{}) erro
vpce := respVpce.VpcEndpoints[0]
d.SetId(aws.StringValue(vpce.VpcEndpointId))

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("vpc-endpoint/%s", d.Id()),
}.String()
d.Set("arn", arn)

serviceName := aws.StringValue(vpce.ServiceName)
d.Set("service_name", serviceName)
d.Set("state", vpce.State)
Expand Down
19 changes: 13 additions & 6 deletions aws/data_source_aws_vpc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
Expand All @@ -10,7 +11,7 @@ import (

func TestAccDataSourceAwsVpcEndpoint_gatewayBasic(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -30,6 +31,7 @@ func TestAccDataSourceAwsVpcEndpoint_gatewayBasic(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "requester_managed", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "0"),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand All @@ -38,7 +40,7 @@ func TestAccDataSourceAwsVpcEndpoint_gatewayBasic(t *testing.T) {

func TestAccDataSourceAwsVpcEndpoint_byId(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -58,6 +60,7 @@ func TestAccDataSourceAwsVpcEndpoint_byId(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "requester_managed", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "0"),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand All @@ -66,7 +69,7 @@ func TestAccDataSourceAwsVpcEndpoint_byId(t *testing.T) {

func TestAccDataSourceAwsVpcEndpoint_byFilter(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -86,6 +89,7 @@ func TestAccDataSourceAwsVpcEndpoint_byFilter(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "requester_managed", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "0"),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand All @@ -94,7 +98,7 @@ func TestAccDataSourceAwsVpcEndpoint_byFilter(t *testing.T) {

func TestAccDataSourceAwsVpcEndpoint_byTags(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -114,6 +118,7 @@ func TestAccDataSourceAwsVpcEndpoint_byTags(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "requester_managed", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "3"),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand All @@ -122,7 +127,7 @@ func TestAccDataSourceAwsVpcEndpoint_byTags(t *testing.T) {

func TestAccDataSourceAwsVpcEndpoint_gatewayWithRouteTableAndTags(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -143,6 +148,7 @@ func TestAccDataSourceAwsVpcEndpoint_gatewayWithRouteTableAndTags(t *testing.T)
resource.TestCheckResourceAttr(datasourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(datasourceName, "tags.Name", rName),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand All @@ -151,7 +157,7 @@ func TestAccDataSourceAwsVpcEndpoint_gatewayWithRouteTableAndTags(t *testing.T)

func TestAccDataSourceAwsVpcEndpoint_interface(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint.test"
rName := fmt.Sprintf("tf-testacc-vpce-%s", acctest.RandStringFromCharSet(16, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -172,6 +178,7 @@ func TestAccDataSourceAwsVpcEndpoint_interface(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(datasourceName, "tags.Name", rName),
testAccCheckResourceAttrAccountID(datasourceName, "owner_id"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint/vpce-.+`)),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/vpc_endpoint.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ which take the following arguments:

In addition to all arguments above except `filter`, the following attributes are exported:

* `arn` - The Amazon Resource Name (ARN) of the VPC endpoint.
* `cidr_blocks` - The list of CIDR blocks for the exposed AWS service. Applicable for endpoints of type `Gateway`.
* `dns_entry` - The DNS entries for the VPC Endpoint. Applicable for endpoints of type `Interface`. DNS blocks are documented below.
* `network_interface_ids` - One or more network interfaces for the VPC Endpoint. Applicable for endpoints of type `Interface`.
Expand Down
9 changes: 5 additions & 4 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_elasticache_cluster` resource](/docs/providers/aws/r/elasticache_cluster.html)
- [`aws_elb` data source](/docs/providers/aws/d/elb.html)
- [`aws_elb` resource](/docs/providers/aws/r/elb.html)
- [`aws_flow_log` resource](/docs/providers/aws/r/flow_log.html)
- [`aws_glue_catalog_database` resource](/docs/providers/aws/r/glue_catalog_database.html)
- [`aws_glue_catalog_table` resource](/docs/providers/aws/r/glue_catalog_table.html)
- [`aws_flow_log` resource](/docs/providers/aws/r/flow_log.html)
- [`aws_glue_catalog_database` resource](/docs/providers/aws/r/glue_catalog_database.html)
- [`aws_glue_catalog_table` resource](/docs/providers/aws/r/glue_catalog_table.html)
- [`aws_glue_connection` resource](/docs/providers/aws/r/glue_connection.html)
- [`aws_glue_crawler` resource](/docs/providers/aws/r/glue_crawler.html)
- [`aws_glue_job` resource](/docs/providers/aws/r/glue_job.html)
Expand Down Expand Up @@ -302,7 +302,8 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_vpc` data source](/docs/providers/aws/d/vpc.html)
- [`aws_vpc` resource](/docs/providers/aws/r/vpc.html)
- [`aws_vpc_dhcp_options` data source](/docs/providers/aws/d/vpc_dhcp_options.html)
- [`aws_vpc_dhcp_options` resource](/docs/providers/aws/r/vpc_dhcp_options.html)
- [`aws_vpc_dhcp_options` resource](/docs/providers/aws/r/vpc_dhcp_options.html)
- [`aws_vpc_endpoint` data source](/docs/providers/aws/d/vpc_endpoint.html)
- [`aws_waf_geo_match_set` resource](/docs/providers/aws/r/waf_geo_match_set.html)
- [`aws_waf_ipset` resource](/docs/providers/aws/r/waf_ipset.html)
- [`aws_waf_rate_based_rule` resource](/docs/providers/aws/r/waf_rate_based_rule.html)
Expand Down