From 766b93c37990997f3c71741737fdbdfc87221276 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Sat, 20 Jun 2020 16:54:33 -0400 Subject: [PATCH] d/aws_vpc_endpoint: Add 'arn' attribute. --- aws/data_source_aws_vpc_endpoint.go | 14 ++++++++++++++ aws/data_source_aws_vpc_endpoint_test.go | 19 +++++++++++++------ website/docs/d/vpc_endpoint.html.markdown | 1 + website/docs/index.html.markdown | 7 ++++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/aws/data_source_aws_vpc_endpoint.go b/aws/data_source_aws_vpc_endpoint.go index 2def730f951..8995a464553 100644 --- a/aws/data_source_aws_vpc_endpoint.go +++ b/aws/data_source_aws_vpc_endpoint.go @@ -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" @@ -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, @@ -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) diff --git a/aws/data_source_aws_vpc_endpoint_test.go b/aws/data_source_aws_vpc_endpoint_test.go index f89d9249c32..b9891c96ac5 100644 --- a/aws/data_source_aws_vpc_endpoint_test.go +++ b/aws/data_source_aws_vpc_endpoint_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -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) }, @@ -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-.+`)), ), }, }, @@ -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) }, @@ -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-.+`)), ), }, }, @@ -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) }, @@ -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-.+`)), ), }, }, @@ -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) }, @@ -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-.+`)), ), }, }, @@ -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) }, @@ -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-.+`)), ), }, }, @@ -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) }, @@ -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-.+`)), ), }, }, diff --git a/website/docs/d/vpc_endpoint.html.markdown b/website/docs/d/vpc_endpoint.html.markdown index a05536402d5..6c1701c288b 100644 --- a/website/docs/d/vpc_endpoint.html.markdown +++ b/website/docs/d/vpc_endpoint.html.markdown @@ -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`. diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 891f7884b87..2c0fb85e6e9 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -263,8 +263,8 @@ 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_table` resource](/docs/providers/aws/r/glue_catalog_table.html) + - [`aws_flow_log` resource](/docs/providers/aws/r/flow_log.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) @@ -296,7 +296,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)