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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_vpc_endpoint_service: Add 'arn' attribute #13856

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions aws/data_source_aws_vpc_endpoint_service.go
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"

"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/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -21,6 +22,10 @@ func dataSourceAwsVpcEndpointService() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"availability_zones": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -133,9 +138,20 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{
}

sd := resp.ServiceDetails[0]
serviceId := aws.StringValue(sd.ServiceId)
serviceName = aws.StringValue(sd.ServiceName)

d.SetId(strconv.Itoa(hashcode.String(serviceName)))
d.Set("service_name", serviceName)

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

d.Set("acceptance_required", sd.AcceptanceRequired)
err = d.Set("availability_zones", flattenStringSet(sd.AvailabilityZones))
if err != nil {
Expand All @@ -148,7 +164,8 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{
d.Set("manages_vpc_endpoints", sd.ManagesVpcEndpoints)
d.Set("owner", sd.Owner)
d.Set("private_dns_name", sd.PrivateDnsName)
d.Set("service_id", sd.ServiceId)
d.Set("service_id", serviceId)
d.Set("service_name", serviceName)
d.Set("service_type", sd.ServiceType[0].ServiceType)
err = d.Set("tags", keyvaluetags.Ec2KeyValueTags(sd.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map())
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions aws/data_source_aws_vpc_endpoint_service_test.go
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
Expand Down Expand Up @@ -29,6 +30,7 @@ func TestAccDataSourceAwsVpcEndpointService_gateway(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "service_type", "Gateway"),
resource.TestCheckResourceAttr(datasourceName, "vpc_endpoint_policy_supported", "true"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "0"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)),
),
},
},
Expand All @@ -55,6 +57,7 @@ func TestAccDataSourceAwsVpcEndpointService_interface(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "service_type", "Interface"),
resource.TestCheckResourceAttr(datasourceName, "vpc_endpoint_policy_supported", "true"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "0"),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)),
),
},
},
Expand All @@ -63,7 +66,7 @@ func TestAccDataSourceAwsVpcEndpointService_interface(t *testing.T) {

func TestAccDataSourceAwsVpcEndpointService_custom(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint_service.test"
rName := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -80,6 +83,7 @@ func TestAccDataSourceAwsVpcEndpointService_custom(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "vpc_endpoint_policy_supported", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(datasourceName, "tags.Name", rName),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)),
),
},
},
Expand All @@ -88,7 +92,7 @@ func TestAccDataSourceAwsVpcEndpointService_custom(t *testing.T) {

func TestAccDataSourceAwsVpcEndpointService_custom_filter(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint_service.test"
rName := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -105,6 +109,7 @@ func TestAccDataSourceAwsVpcEndpointService_custom_filter(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "vpc_endpoint_policy_supported", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(datasourceName, "tags.Name", rName),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)),
),
},
},
Expand All @@ -113,7 +118,7 @@ func TestAccDataSourceAwsVpcEndpointService_custom_filter(t *testing.T) {

func TestAccDataSourceAwsVpcEndpointService_custom_filter_tags(t *testing.T) {
datasourceName := "data.aws_vpc_endpoint_service.test"
rName := fmt.Sprintf("tf-testacc-vpcesvc-%s", acctest.RandStringFromCharSet(13, acctest.CharSetAlphaNum))
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -130,6 +135,7 @@ func TestAccDataSourceAwsVpcEndpointService_custom_filter_tags(t *testing.T) {
resource.TestCheckResourceAttr(datasourceName, "vpc_endpoint_policy_supported", "false"),
resource.TestCheckResourceAttr(datasourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(datasourceName, "tags.Name", rName),
testAccMatchResourceAttrRegionalARN(datasourceName, "arn", "ec2", regexp.MustCompile(`vpc-endpoint-service/vpce-svc-.+`)),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/vpc_endpoint_service.html.markdown
Expand Up @@ -76,6 +76,7 @@ The following arguments are supported by the `filter` configuration block:
In addition to all arguments above, the following attributes are exported:

* `acceptance_required` - Whether or not VPC endpoint connection requests to the service must be accepted by the service owner - `true` or `false`.
* `arn` - The Amazon Resource Name (ARN) of the VPC endpoint service.
* `availability_zones` - The Availability Zones in which the service is available.
* `base_endpoint_dns_names` - The DNS names for the service.
* `manages_vpc_endpoints` - Whether or not the service manages its VPC endpoints - `true` or `false`.
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Expand Up @@ -307,6 +307,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`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_vpc_endpoint` resource](/docs/providers/aws/r/vpc_endpoint.html)
- [`aws_vpc_endpoint_service` data source](/docs/providers/aws/d/vpc_endpoint_service.html)
- [`aws_vpn_gateway` data source](/docs/providers/aws/d/vpn_gateway.html)
- [`aws_vpn_gateway` resource](/docs/providers/aws/r/vpn_gateway.html)
- [`aws_waf_geo_match_set` resource](/docs/providers/aws/r/waf_geo_match_set.html)
Expand Down