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_location_tracker_association: new data source #26404

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
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.