-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26404 from kamilturek/f-data-aws-location-tracker…
…-association d/aws_location_tracker_association: new data source
- Loading branch information
Showing
6 changed files
with
152 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-data-source | ||
aws_location_tracker_association | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
internal/service/location/tracker_association_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
internal/service/location/tracker_association_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |