-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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 #25639 from kamilturek/f-data-source-aws-location-…
…tracker d/aws_location_tracker - new data source
- Loading branch information
Showing
8 changed files
with
173 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 | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package location | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/locationservice" | ||
"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" | ||
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
) | ||
|
||
func DataSourceTracker() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTrackerRead, | ||
Schema: map[string]*schema.Schema{ | ||
"create_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"kms_key_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"position_filtering": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tftags.TagsSchemaComputed(), | ||
"tracker_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tracker_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(1, 100), | ||
}, | ||
"update_time": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTrackerRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).LocationConn | ||
|
||
input := &locationservice.DescribeTrackerInput{ | ||
TrackerName: aws.String(d.Get("tracker_name").(string)), | ||
} | ||
|
||
output, err := conn.DescribeTracker(input) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error getting Location Service Tracker: %w", err) | ||
} | ||
|
||
if output == nil { | ||
return fmt.Errorf("error getting Location Service Tracker: empty response") | ||
} | ||
|
||
d.SetId(aws.StringValue(output.TrackerName)) | ||
d.Set("create_time", aws.TimeValue(output.CreateTime).Format(time.RFC3339)) | ||
d.Set("description", output.Description) | ||
d.Set("kms_key_id", output.KmsKeyId) | ||
d.Set("position_filtering", output.PositionFiltering) | ||
d.Set("tags", KeyValueTags(output.Tags).IgnoreAWS().IgnoreConfig(meta.(*conns.AWSClient).IgnoreTagsConfig).Map()) | ||
d.Set("tracker_arn", output.TrackerArn) | ||
d.Set("tracker_name", output.TrackerName) | ||
d.Set("update_time", aws.TimeValue(output.UpdateTime).Format(time.RFC3339)) | ||
|
||
return nil | ||
} |
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,51 @@ | ||
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 TestAccLocationTrackerDataSource_indexName(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) | ||
dataSourceName := "data.aws_location_tracker.test" | ||
resourceName := "aws_location_tracker.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, locationservice.EndpointsID), | ||
ProviderFactories: acctest.ProviderFactories, | ||
CheckDestroy: testAccCheckTrackerDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTrackerDataSourceConfig_indexName(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "create_time", resourceName, "create_time"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_id", resourceName, "kms_key_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "position_filtering", resourceName, "position_filtering"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tracker_arn", resourceName, "tracker_arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tracker_name", resourceName, "tracker_name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "update_time", resourceName, "update_time"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccTrackerDataSourceConfig_indexName(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_location_tracker" "test" { | ||
tracker_name = %[1]q | ||
} | ||
data "aws_location_tracker" "test" { | ||
tracker_name = aws_location_tracker.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
subcategory: "Location" | ||
layout: "aws" | ||
page_title: "AWS: aws_location_tracker" | ||
description: |- | ||
Retrieve information about a Location Service Tracker. | ||
--- | ||
|
||
# Data Source: aws_location_tracker | ||
|
||
Retrieve information about a Location Service Tracker. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_location_tracker" "example" { | ||
tracker_name = "example" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `tracker_name` - (Required) The name of the tracker resource. | ||
|
||
## Attribute Reference | ||
|
||
* `create_time` - The timestamp for when the tracker resource was created in ISO 8601 format. | ||
* `description` - The optional description for the tracker resource. | ||
* `kms_key_id` - A key identifier for an AWS KMS customer managed key assigned to the Amazon Location resource. | ||
* `position_filtering` - The position filtering method of the tracker resource. | ||
* `tags` - Key-value map of resource tags for the map. | ||
* `tracker_arn` - The Amazon Resource Name (ARN) for the tracker resource. Used when you need to specify a resource across all AWS. | ||
* `update_time` - The timestamp for when the tracker resource was last updated in ISO 8601 format. |
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