Skip to content

Commit

Permalink
Merge pull request #26404 from kamilturek/f-data-aws-location-tracker…
Browse files Browse the repository at this point in the history
…-association

d/aws_location_tracker_association: new data source
  • Loading branch information
ewbankkit authored Aug 22, 2022
2 parents e77f72a + 148f419 commit 966d3cb
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/26404.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_location_tracker_association
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ func New(_ context.Context) (*schema.Provider, error) {
"aws_location_place_index": location.DataSourcePlaceIndex(),
"aws_location_route_calculator": location.DataSourceRouteCalculator(),
"aws_location_tracker": location.DataSourceTracker(),
"aws_location_tracker_association": location.DataSourceTrackerAssociation(),

// "aws_arn": meta.DataSourceARN(), // Now implemented using Terraform Plugin Framework.
"aws_billing_service_account": meta.DataSourceBillingServiceAccount(),
Expand Down
7 changes: 3 additions & 4 deletions internal/service/location/tracker_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func FindTrackerAssociationByTrackerNameAndConsumerARN(ctx context.Context, conn
}

found := false
fn := func(page *locationservice.ListTrackerConsumersOutput, lastPage bool) bool {

err := conn.ListTrackerConsumersPagesWithContext(ctx, in, func(page *locationservice.ListTrackerConsumersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
Expand All @@ -155,9 +156,7 @@ func FindTrackerAssociationByTrackerNameAndConsumerARN(ctx context.Context, conn
}

return !lastPage
}

err := conn.ListTrackerConsumersPagesWithContext(ctx, in, fn)
})

if err != nil {
return err
Expand Down
56 changes: 56 additions & 0 deletions internal/service/location/tracker_association_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package location

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

func DataSourceTrackerAssociation() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceTrackerAssociationRead,

Schema: map[string]*schema.Schema{
"consumer_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidARN,
},
"tracker_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
},
}
}

const (
DSNameTrackerAssociation = "Tracker Association Data Source"
)

func dataSourceTrackerAssociationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).LocationConn

consumerArn := d.Get("consumer_arn").(string)
trackerName := d.Get("tracker_name").(string)
id := fmt.Sprintf("%s|%s", trackerName, consumerArn)

err := FindTrackerAssociationByTrackerNameAndConsumerARN(ctx, conn, trackerName, consumerArn)
if err != nil {
return create.DiagError(names.Location, create.ErrActionReading, DSNameTrackerAssociation, id, err)
}

d.SetId(id)

return nil
}
56 changes: 56 additions & 0 deletions internal/service/location/tracker_association_data_source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package location_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/locationservice"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccLocationTrackerAssociationDataSource_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_location_tracker_association.test"
resourceName := "aws_location_tracker_association.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, locationservice.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTrackerAssociationDestroy,
Steps: []resource.TestStep{
{
Config: testAccTrackerAssociationDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckTrackerAssociationExists(dataSourceName),
resource.TestCheckResourceAttrPair(resourceName, "consumer_arn", "aws_location_geofence_collection.test", "collection_arn"),
resource.TestCheckResourceAttrPair(resourceName, "tracker_name", "aws_location_tracker.test", "tracker_name"),
),
},
},
})
}

func testAccTrackerAssociationDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_location_geofence_collection" "test" {
collection_name = %[1]q
}
resource "aws_location_tracker" "test" {
tracker_name = %[1]q
}
resource "aws_location_tracker_association" "test" {
consumer_arn = aws_location_geofence_collection.test.collection_arn
tracker_name = aws_location_tracker.test.tracker_name
}
data "aws_location_tracker_association" "test" {
consumer_arn = aws_location_tracker_association.test.consumer_arn
tracker_name = aws_location_tracker_association.test.tracker_name
}
`, rName)
}
33 changes: 33 additions & 0 deletions website/docs/d/location_tracker_association.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
subcategory: "Location"
layout: "aws"
page_title: "AWS: aws_location_tracker_association"
description: |-
Retrieve information about a Location Service Tracker Association.
---

# Data Source: aws_location_tracker_association

Retrieve information about a Location Service Tracker Association.

## Example Usage

### Basic Usage

```terraform
data "aws_location_tracker_association" "example" {
consumer_arn = "arn:aws:geo:region:account-id:geofence-collection/ExampleGeofenceCollectionConsumer"
tracker_name = "example"
}
```

## Argument Reference

The following arguments are required:

* `consumer_arn` - (Required) The Amazon Resource Name (ARN) of the geofence collection associated to tracker resource.
* `tracker_name` - (Required) The name of the tracker resource associated with a geofence collection.

## Attributes Reference

No additional attributes are exported.

0 comments on commit 966d3cb

Please sign in to comment.