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

Add data_source for aws_elasticache_serverless_cache #39590

Merged
merged 4 commits into from
Oct 10, 2024
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/39590.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_elasticache_serverless_cache
```
4 changes: 2 additions & 2 deletions internal/service/appstream/image_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (d *dataSourceImage) Read(ctx context.Context, req datasource.ReadRequest,
}

if image.PublicBaseImageReleasedDate != nil {
data.PubilcBaseImageReleasedDate = timetypes.NewRFC3339TimeValue(*image.PublicBaseImageReleasedDate)
data.PublicBaseImageReleasedDate = timetypes.NewRFC3339TimeValue(*image.PublicBaseImageReleasedDate)
}

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down Expand Up @@ -269,7 +269,7 @@ type dsImage struct {
Name types.String `tfsdk:"name"`
NameRegex fwtypes.Regexp `tfsdk:"name_regex"`
Platform types.String `tfsdk:"platform"`
PubilcBaseImageReleasedDate timetypes.RFC3339 `tfsdk:"public_base_image_released_date"`
PublicBaseImageReleasedDate timetypes.RFC3339 `tfsdk:"public_base_image_released_date"`
State types.String `tfsdk:"state"`
StateChangeReason fwtypes.ListNestedObjectValueOf[dsStateChange] `tfsdk:"state_change_reason"`
Type fwtypes.StringEnum[awstypes.VisibilityType] `tfsdk:"type"`
Expand Down
165 changes: 165 additions & 0 deletions internal/service/elasticache/serverless_cache_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package elasticache

import (
"context"

awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types"
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource(name="Serverless Cache")
func newDataSourceServerlessCache(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceServerlessCache{}, nil
}

type dataSourceServerlessCache struct {
framework.DataSourceWithConfigure
}

func (d *dataSourceServerlessCache) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) {
response.TypeName = "aws_elasticache_serverless_cache"
}

func (d *dataSourceServerlessCache) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrARN: schema.StringAttribute{
CustomType: fwtypes.ARNType,
Computed: true,
},
"cache_usage_limits": schema.ObjectAttribute{
CustomType: fwtypes.NewObjectTypeOf[dsCacheUsageLimits](ctx),
Computed: true,
},
names.AttrCreateTime: schema.StringAttribute{
CustomType: timetypes.RFC3339Type{},
Computed: true,
},
"daily_snapshot_time": schema.StringAttribute{
Computed: true,
},
names.AttrDescription: schema.StringAttribute{
Computed: true,
},
names.AttrEndpoint: schema.ObjectAttribute{
CustomType: fwtypes.NewObjectTypeOf[dsEndpoint](ctx),
Computed: true,
},
names.AttrEngine: schema.StringAttribute{
Computed: true,
},
"full_engine_version": schema.StringAttribute{
Computed: true,
},
names.AttrKMSKeyID: schema.StringAttribute{
Computed: true,
},
"major_engine_version": schema.StringAttribute{
Computed: true,
},
names.AttrName: schema.StringAttribute{
Required: true,
},
"reader_endpoint": schema.ObjectAttribute{
CustomType: fwtypes.NewObjectTypeOf[dsEndpoint](ctx),
Computed: true,
},
names.AttrSecurityGroupIDs: schema.ListAttribute{
CustomType: fwtypes.ListOfStringType,
Computed: true,
},
"snapshot_retention_limit": schema.Int64Attribute{
Computed: true,
},
names.AttrStatus: schema.StringAttribute{
Computed: true,
},
names.AttrSubnetIDs: schema.ListAttribute{
CustomType: fwtypes.ListOfStringType,
Computed: true,
},
"user_group_id": schema.StringAttribute{
Computed: true,
},
},
}
}

func (d *dataSourceServerlessCache) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data dsServerlessCache
conn := d.Meta().ElastiCacheClient(ctx)

response.Diagnostics.Append(request.Config.Get(ctx, &data)...)
if response.Diagnostics.HasError() {
return
}

output, err := findServerlessCacheByID(ctx, conn, data.Name.ValueString())

if err != nil {
response.Diagnostics.AddError(
create.ProblemStandardMessage(names.ElastiCache, create.ErrActionReading, "Serverless Cache", data.Name.ValueString(), err),
err.Error(),
)
return
}

response.Diagnostics.Append(flex.Flatten(ctx, output, &data)...)
if response.Diagnostics.HasError() {
return
}

response.Diagnostics.Append(response.State.Set(ctx, &data)...)
}

type dsServerlessCache struct {
ARN fwtypes.ARN `tfsdk:"arn"`
CacheUsageLimits fwtypes.ObjectValueOf[dsCacheUsageLimits] `tfsdk:"cache_usage_limits"`
CreateTime timetypes.RFC3339 `tfsdk:"create_time"`
DailySnapshotTime types.String `tfsdk:"daily_snapshot_time"`
Description types.String `tfsdk:"description"`
Endpoint fwtypes.ObjectValueOf[dsEndpoint] `tfsdk:"endpoint"`
Engine types.String `tfsdk:"engine"`
FullEngineVersion types.String `tfsdk:"full_engine_version"`
KmsKeyID types.String `tfsdk:"kms_key_id"`
MajorEngineVersion types.String `tfsdk:"major_engine_version"`
Name types.String `tfsdk:"name"`
ReaderEndpoint fwtypes.ObjectValueOf[dsEndpoint] `tfsdk:"reader_endpoint"`
SecurityGroupIDs fwtypes.ListValueOf[types.String] `tfsdk:"security_group_ids"`
SnapshotRetentionLimit types.Int64 `tfsdk:"snapshot_retention_limit"`
Status types.String `tfsdk:"status"`
SubnetIDs fwtypes.ListValueOf[types.String] `tfsdk:"subnet_ids"`
UserGroupID types.String `tfsdk:"user_group_id"`
}

type dsCacheUsageLimits struct {
DataStorage fwtypes.ObjectValueOf[dsDataStorage] `tfsdk:"data_storage"`
ECPUPerSecond fwtypes.ObjectValueOf[dsECPUPerSecond] `tfsdk:"ecpu_per_second"`
}

type dsDataStorage struct {
Maximum types.Int64 `tfsdk:"maximum"`
Minimum types.Int64 `tfsdk:"minimum"`
Unit fwtypes.StringEnum[awstypes.DataStorageUnit] `tfsdk:"unit"`
}

type dsECPUPerSecond struct {
Maximum types.Int64 `tfsdk:"maximum"`
Minimum types.Int64 `tfsdk:"minimum"`
}

type dsEndpoint struct {
Address types.String `tfsdk:"address"`
Port types.Int64 `tfsdk:"port"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package elasticache_test

import (
"fmt"
"testing"

sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccElastiCacheServerlessCacheDataSource_basic(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_elasticache_serverless_cache.test"
dataSourceName := "data.aws_elasticache_serverless_cache.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.ElastiCacheEndpointID)
},
ErrorCheck: acctest.ErrorCheck(t, names.ElastiCacheServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccServerlessCacheDataSourceConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrCreateTime, resourceName, names.AttrCreateTime),
resource.TestCheckResourceAttrPair(dataSourceName, "daily_snapshot_time", resourceName, "daily_snapshot_time"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrDescription, resourceName, names.AttrDescription),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrEngine, resourceName, names.AttrEngine),
resource.TestCheckResourceAttrPair(dataSourceName, "full_engine_version", resourceName, "full_engine_version"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrKMSKeyID, resourceName, names.AttrKMSKeyID),
resource.TestCheckResourceAttrPair(dataSourceName, "major_engine_version", resourceName, "major_engine_version"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(dataSourceName, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "snapshot_retention_limit", resourceName, "snapshot_retention_limit"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrStatus, resourceName, names.AttrStatus),
resource.TestCheckResourceAttrPair(dataSourceName, "subnet_ids.#", resourceName, "subnet_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "user_group_id", resourceName, "user_group_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "cache_usage_limits.#", resourceName, "cache_usage_limits.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.address", resourceName, "endpoint.0.address"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint.port", resourceName, "endpoint.0.port"),
resource.TestCheckResourceAttrPair(dataSourceName, "reader_endpoint.address", resourceName, "reader_endpoint.0.address"),
resource.TestCheckResourceAttrPair(dataSourceName, "reader_endpoint.port", resourceName, "reader_endpoint.0.port"),
),
},
},
})
}

func testAccServerlessCacheDataSourceConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_elasticache_serverless_cache" "test" {
engine = "redis"
name = %[1]q
}

data "aws_elasticache_serverless_cache" "test" {
name = aws_elasticache_serverless_cache.test.name
}
`, rName)
}
4 changes: 4 additions & 0 deletions internal/service/elasticache/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions website/docs/d/elasticache_serverless_cache.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
subcategory: "ElastiCache"
layout: "aws"
page_title: "AWS: aws_elasticache_serverless_cache"
description: |-
Get information on an ElastiCache Serverless Cache resource.
---

# Data Source: aws_elasticache_serverless_cache

Use this data source to get information about an ElastiCache Serverless Cache.

## Example Usage

```terraform
data "aws_elasticache_serverless_cache" "example" {
name = "example"
}
```

## Argument Reference

This data source supports the following arguments:

* `name` – (Required) Identifier for the serverless cache.

## Attribute Reference

This data source exports the following attributes in addition to the arguments above:

* `arn` - The Amazon Resource Name (ARN) of the serverless cache.
* `cache_usage_limits` - The cache usage limits for storage and ElastiCache Processing Units for the cache. See [`cache_usage_limits` Block](#cache_usage_limits-block) for details.
* `create_time` - Timestamp of when the serverless cache was created.
* `daily_snapshot_time` - The daily time that snapshots will be created from the new serverless cache. Only available for engine type `"redis"`.
* `description` - Description of the serverless cache.
* `endpoint` - Represents the information required for client programs to connect to the cache. See [`endpoint` Block](#endpoint-block) for details.
* `engine` – Name of the cache engine.
* `full_engine_version` - The name and version number of the engine the serverless cache is compatible with.
* `kms_key_id` - ARN of the customer managed key for encrypting the data at rest.
* `major_engine_version` - The version number of the engine the serverless cache is compatible with.
* `reader_endpoint` - Represents the information required for client programs to connect to a cache node. See [`reader_endpoint` Block](#reader_endpoint-block) for details.
* `security_group_ids` - A list of the one or more VPC security groups associated with the serverless cache.
* `snapshot_retention_limit` - The number of snapshots that will be retained for the serverless cache. Available for Redis only.
* `status` - The current status of the serverless cache.
* `subnet_ids` – A list of the identifiers of the subnets where the VPC endpoint for the serverless cache are deployed.
* `user_group_id` - The identifier of the UserGroup associated with the serverless cache. Available for Redis only.

### `cache_usage_limits` Block

The `cache_usage_limits` block supports the following attributes:

* `data_storage` - The maximum data storage limit in the cache, expressed in Gigabytes. See [`data_storage` Block](#data_storage-block) for details.
* `ecpu_per_second` - The configured number of ElastiCache Processing Units (ECPU) the cache can consume per second. See [`ecpu_per_second` Block](#ecpu_per_second-block) for details.

### `data_storage` Block

The `data_storage` block supports the following attributes:

* `minimum` - The lower limit for data storage the cache is set to use.
* `maximum` - The upper limit for data storage the cache is set to use.
* `unit` - The unit that the storage is measured in.

### `ecpu_per_second` Block

The `ecpu_per_second` block supports the following attributes:

* `minimum` - The minimum number of ECPUs the cache can consume per second.
* `maximum` - The maximum number of ECPUs the cache can consume per second.

### `endpoint` Block

The `endpoint` block exports the following attributes:

* `address` - The DNS hostname of the cache node.
* `port` - The port number that the cache engine is listening on. Set as integer.

### `reader_endpoint` Block

The `reader_endpoint` block exports the following attributes:

* `address` - The DNS hostname of the cache node.
* `port` - The port number that the cache engine is listening on. Set as integer.
Loading