From 9b4f4c463279ecbf40e1a731f60c3fe32d2cce13 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 22:44:34 +0200 Subject: [PATCH 1/7] Create new data source --- .../service/location/tracker_data_source.go | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 internal/service/location/tracker_data_source.go diff --git a/internal/service/location/tracker_data_source.go b/internal/service/location/tracker_data_source.go new file mode 100644 index 00000000000..4a525563125 --- /dev/null +++ b/internal/service/location/tracker_data_source.go @@ -0,0 +1,80 @@ +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{ + 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 +} From bc887878f1cfe1f7b8ba919f2e40640e34ac60b4 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 22:45:23 +0200 Subject: [PATCH 2/7] Register new data source --- internal/provider/provider.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 3257b8ad2ff..e4fa86ab1ad 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -745,6 +745,7 @@ func Provider() *schema.Provider { "aws_location_map": location.DataSourceMap(), "aws_location_place_index": location.DataSourcePlaceIndex(), + "aws_location_tracker": location.DataSourceTracker(), "aws_arn": meta.DataSourceARN(), "aws_billing_service_account": meta.DataSourceBillingServiceAccount(), From e9c347dbc3b3b0308930832b03e81426f8935389 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 22:59:45 +0200 Subject: [PATCH 3/7] Add acceptance test --- .../service/location/tracker_data_source.go | 1 + .../location/tracker_data_source_test.go | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 internal/service/location/tracker_data_source_test.go diff --git a/internal/service/location/tracker_data_source.go b/internal/service/location/tracker_data_source.go index 4a525563125..16d9c80b325 100644 --- a/internal/service/location/tracker_data_source.go +++ b/internal/service/location/tracker_data_source.go @@ -14,6 +14,7 @@ import ( func DataSourceTracker() *schema.Resource { return &schema.Resource{ + Read: dataSourceTrackerRead, Schema: map[string]*schema.Schema{ "create_time": { Type: schema.TypeString, diff --git a/internal/service/location/tracker_data_source_test.go b/internal/service/location/tracker_data_source_test.go new file mode 100644 index 00000000000..ea8865c42fe --- /dev/null +++ b/internal/service/location/tracker_data_source_test.go @@ -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) +} From 0c96c6d24f8e5a4e356b91f220959a5e701ca067 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 23:04:04 +0200 Subject: [PATCH 4/7] Create docs page --- website/docs/d/location_tracker.html.markdown | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 website/docs/d/location_tracker.html.markdown diff --git a/website/docs/d/location_tracker.html.markdown b/website/docs/d/location_tracker.html.markdown new file mode 100644 index 00000000000..e0a090498b2 --- /dev/null +++ b/website/docs/d/location_tracker.html.markdown @@ -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. From 49acc93b4b3c2d976435f2f08f9ff5de7b1eb53d Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 23:04:55 +0200 Subject: [PATCH 5/7] Fix other minor docs issues --- website/docs/d/location_map.html.markdown | 2 +- website/docs/d/location_place_index.html.markdown | 2 +- website/docs/r/location_map.html.markdown | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/d/location_map.html.markdown b/website/docs/d/location_map.html.markdown index 9397a4cc71f..10602f33090 100644 --- a/website/docs/d/location_map.html.markdown +++ b/website/docs/d/location_map.html.markdown @@ -30,4 +30,4 @@ data "aws_location_map" "example" { * `description` - The optional description for the map resource. * `map_arn` - The Amazon Resource Name (ARN) for the map resource. * `tags` - Key-value map of resource tags for the map. -* `update_time` - The timestamp for when the map resource was last updated in ISO 8601. +* `update_time` - The timestamp for when the map resource was last updated in ISO 8601 format. diff --git a/website/docs/d/location_place_index.html.markdown b/website/docs/d/location_place_index.html.markdown index f6011ae6f5c..98c1e758961 100644 --- a/website/docs/d/location_place_index.html.markdown +++ b/website/docs/d/location_place_index.html.markdown @@ -30,4 +30,4 @@ data "aws_location_place_index" "example" { * `description` - The optional description for the place index resource. * `index_arn` - The Amazon Resource Name (ARN) for the place index resource. * `tags` - Key-value map of resource tags for the map. -* `update_time` - The timestamp for when the place index resource was last update in ISO 8601. +* `update_time` - The timestamp for when the place index resource was last updated in ISO 8601 format. diff --git a/website/docs/r/location_map.html.markdown b/website/docs/r/location_map.html.markdown index 89f88fe4055..1a549c565a2 100644 --- a/website/docs/r/location_map.html.markdown +++ b/website/docs/r/location_map.html.markdown @@ -47,7 +47,7 @@ In addition to all arguments above, the following attributes are exported: * `create_time` - The timestamp for when the map resource was created in ISO 8601 format. * `map_arn` - The Amazon Resource Name (ARN) for the map resource. Used to specify a resource across all AWS. * `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://www.terraform.io/docs/providers/aws/index.html#default_tags-configuration-block). -* `update_time` - The timestamp for when the map resource was last updated in ISO 8601. +* `update_time` - The timestamp for when the map resource was last updated in ISO 8601 format. ## Import From 1af391f0dc47a4c41312e5e7d4c9d3f22a2b22d0 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Thu, 30 Jun 2022 23:06:25 +0200 Subject: [PATCH 6/7] Add changelog --- .changelog/25639.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/25639.txt diff --git a/.changelog/25639.txt b/.changelog/25639.txt new file mode 100644 index 00000000000..ca4513d39d5 --- /dev/null +++ b/.changelog/25639.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_location_tracker +``` From d0b8e38f2e23841b4cdc4281023938da168f5930 Mon Sep 17 00:00:00 2001 From: Kamil Turek Date: Fri, 1 Jul 2022 09:54:28 +0200 Subject: [PATCH 7/7] Fix one more docs error --- website/docs/d/location_place_index.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/location_place_index.html.markdown b/website/docs/d/location_place_index.html.markdown index 98c1e758961..be20f1f1851 100644 --- a/website/docs/d/location_place_index.html.markdown +++ b/website/docs/d/location_place_index.html.markdown @@ -29,5 +29,5 @@ data "aws_location_place_index" "example" { * `data_source_configuration` - List of configurations that specify data storage option for requesting Places. * `description` - The optional description for the place index resource. * `index_arn` - The Amazon Resource Name (ARN) for the place index resource. -* `tags` - Key-value map of resource tags for the map. +* `tags` - Key-value map of resource tags for the place index. * `update_time` - The timestamp for when the place index resource was last updated in ISO 8601 format.