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_geofence_collection: new data source #25844

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/25844.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_location_geofence_collection
```
9 changes: 5 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,11 @@ func Provider() *schema.Provider {
"aws_lex_intent": lexmodels.DataSourceIntent(),
"aws_lex_slot_type": lexmodels.DataSourceSlotType(),

"aws_location_map": location.DataSourceMap(),
"aws_location_place_index": location.DataSourcePlaceIndex(),
"aws_location_route_calculator": location.DataSourceRouteCalculator(),
"aws_location_tracker": location.DataSourceTracker(),
"aws_location_geofence_collection": location.DataSourceGeofenceCollection(),
"aws_location_map": location.DataSourceMap(),
"aws_location_place_index": location.DataSourcePlaceIndex(),
"aws_location_route_calculator": location.DataSourceRouteCalculator(),
"aws_location_tracker": location.DataSourceTracker(),

"aws_arn": meta.DataSourceARN(),
"aws_billing_service_account": meta.DataSourceBillingServiceAccount(),
Expand Down
80 changes: 80 additions & 0 deletions internal/service/location/geofence_collection_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package location

import (
"context"
"time"

"github.com/aws/aws-sdk-go/aws"
"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"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

func DataSourceGeofenceCollection() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGeofenceCollectionRead,

Schema: map[string]*schema.Schema{
"collection_arn": {
Type: schema.TypeString,
Computed: true,
},
"collection_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
"create_time": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"kms_key_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
},
"tags": tftags.TagsSchemaComputed(),
},
}
}

const (
DSNameGeofenceCollection = "Geofence Collection Data Source"
)

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

name := d.Get("collection_name").(string)

out, err := findGeofenceCollectionByName(ctx, conn, name)
if err != nil {
return names.DiagError(names.Location, names.ErrActionReading, DSNameGeofenceCollection, name, err)
}

d.SetId(aws.StringValue(out.CollectionName))
d.Set("collection_arn", out.CollectionArn)
d.Set("create_time", aws.TimeValue(out.CreateTime).Format(time.RFC3339))
d.Set("description", out.Description)
d.Set("kms_key_id", out.KmsKeyId)
d.Set("update_time", aws.TimeValue(out.UpdateTime).Format(time.RFC3339))

ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

if err := d.Set("tags", KeyValueTags(out.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return names.DiagError(names.Location, names.ErrActionSetting, DSNameGeofenceCollection, d.Id(), err)
}

return nil
}
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 TestAccLocationGeofenceCollectionDataSource_basic(t *testing.T) {
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
dataSourceName := "data.aws_location_geofence_collection.test"
resourceName := "aws_location_geofence_collection.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, locationservice.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckGeofenceCollectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccGeofenceCollectionDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGeofenceCollectionExists(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "collection_arn", resourceName, "collection_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "collection_name", resourceName, "collection_name"),
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, "update_time", resourceName, "update_time"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
),
},
},
})
}

func testAccGeofenceCollectionDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_location_geofence_collection" "test" {
collection_name = %[1]q
}

data "aws_location_geofence_collection" "test" {
collection_name = aws_location_geofence_collection.test.collection_name
}
`, rName)
}
38 changes: 38 additions & 0 deletions website/docs/d/location_geofence_collection.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
subcategory: "Location"
layout: "aws"
page_title: "AWS: aws_location_geofence_collection"
description: |-
Retrieve information about a Location Service Geofence Collection.
---

# Data Source: aws_location_geofence_collection

Retrieve information about a Location Service Geofence Collection.

## Example Usage

### Basic Usage

```terraform
data "aws_location_geofence_collection" "example" {
collection_name = "example"
}
```

## Argument Reference

The following arguments are required:

* `collection_name` - (Required) The name of the geofence collection.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `collection_arn` - The Amazon Resource Name (ARN) for the geofence collection resource. Used when you need to specify a resource across all AWS.
* `create_time` - The timestamp for when the geofence collection resource was created in ISO 8601 format.
* `description` - The optional description of the geofence collection resource.
* `kms_key_id` - A key identifier for an AWS KMS customer managed key assigned to the Amazon Location resource.
* `tags` - Key-value map of resource tags for the geofence collection.
* `update_time` - The timestamp for when the geofence collection resource was last updated in ISO 8601 format.