-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 #25844 from kamilturek/f-data-aws-location-geofenc…
…e-collection d/aws_location_geofence_collection: new data source
- Loading branch information
Showing
5 changed files
with
177 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_geofence_collection | ||
``` |
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
80 changes: 80 additions & 0 deletions
80
internal/service/location/geofence_collection_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,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 | ||
} |
51 changes: 51 additions & 0 deletions
51
internal/service/location/geofence_collection_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,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) | ||
} |
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,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. |