Skip to content

Commit

Permalink
data-source/aws_api_gateway_vpc_link: Add attributes (#10822)
Browse files Browse the repository at this point in the history
Output from acceptance testing:

```
--- PASS: TestAccDataSourceAwsApiGatewayVpcLink (726.29s)
```
  • Loading branch information
DrFaust92 authored Jan 29, 2020
1 parent 5c61372 commit f650f11
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
27 changes: 27 additions & 0 deletions aws/data_source_aws_api_gateway_vpc_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsApiGatewayVpcLink() *schema.Resource {
Expand All @@ -23,6 +24,24 @@ func dataSourceAwsApiGatewayVpcLink() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"status_message": {
Type: schema.TypeString,
Computed: true,
},
"target_arns": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tagsSchemaComputed(),
},
}
}
Expand Down Expand Up @@ -57,6 +76,14 @@ func dataSourceAwsApiGatewayVpcLinkRead(d *schema.ResourceData, meta interface{}

d.SetId(*match.Id)
d.Set("name", match.Name)
d.Set("status", match.Status)
d.Set("status_message", match.StatusMessage)
d.Set("description", match.Description)
d.Set("target_arns", flattenStringList(match.TargetArns))

if err := d.Set("tags", keyvaluetags.ApigatewayKeyValueTags(match.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
}
11 changes: 9 additions & 2 deletions aws/data_source_aws_api_gateway_vpc_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ import (

func TestAccDataSourceAwsApiGatewayVpcLink(t *testing.T) {
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(8))
resourceName := "aws_api_gateway_vpc_link.vpc_link"
dataSourceName := "data.aws_api_gateway_vpc_link.vpc_link"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsApiGatewayVpcLinkConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.aws_api_gateway_vpc_link.vpc_link", "name", "aws_api_gateway_vpc_link.vpc_link", "name"),
resource.TestCheckResourceAttrPair("data.aws_api_gateway_vpc_link.vpc_link", "id", "aws_api_gateway_vpc_link.vpc_link", "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "id", resourceName, "id"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrSet(dataSourceName, "status_message"),
resource.TestCheckResourceAttrSet(dataSourceName, "status"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(dataSourceName, "target_arns.#", "1"),
),
},
},
Expand Down
5 changes: 5 additions & 0 deletions website/docs/d/api_gateway_vpc_link.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ data "aws_api_gateway_vpc_link" "my_api_gateway_vpc_link" {
## Attributes Reference

* `id` - Set to the ID of the found API Gateway VPC Link.
* `description` - The description of the VPC link.
* `status` - The status of the VPC link.
* `status_message` - The status message of the VPC link.
* `target_arns` - The list of network load balancer arns in the VPC targeted by the VPC link. Currently AWS only supports 1 target.
* `tags` - Key-value mapping of resource tags

0 comments on commit f650f11

Please sign in to comment.