Skip to content

Commit

Permalink
Merge pull request #38269 from nikhil-goenka/b/aws_elasticache_server…
Browse files Browse the repository at this point in the history
…less_cache

aws_elasticache_serverless_cache
  • Loading branch information
ewbankkit authored Jul 8, 2024
2 parents 54d88fc + 33bf10f commit fe926cd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .changelog/38269.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_elasticache_serverless_cache: Allow `cache_usage_limits.data_storage.maximum`, `cache_usage_limits.data_storage.minimum`, `cache_usage_limits.ecpu_per_second.maximum` and `cache_usage_limits.ecpu_per_second.minimum` to be updated in-place
```
12 changes: 0 additions & 12 deletions internal/service/elasticache/serverless_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,9 @@ func (r *serverlessCacheResource) Schema(ctx context.Context, request resource.S
Attributes: map[string]schema.Attribute{
"maximum": schema.Int64Attribute{
Optional: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
},
"minimum": schema.Int64Attribute{
Optional: true,
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
},
names.AttrUnit: schema.StringAttribute{
CustomType: fwtypes.StringEnumType[awstypes.DataStorageUnit](),
Expand All @@ -224,18 +218,12 @@ func (r *serverlessCacheResource) Schema(ctx context.Context, request resource.S
Validators: []validator.Int64{
int64validator.Between(1000, 15000000),
},
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
},
"minimum": schema.Int64Attribute{
Optional: true,
Validators: []validator.Int64{
int64validator.Between(1000, 15000000),
},
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplace(),
},
},
},
},
Expand Down
67 changes: 60 additions & 7 deletions internal/service/elasticache/serverless_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package elasticache_test

import (
"context"
"errors"
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
awstypes "github.com/aws/aws-sdk-go-v2/service/elasticache/types"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -270,7 +272,7 @@ func TestAccElastiCacheServerlessCache_updatesc(t *testing.T) {
descriptionOld := "Memcached Serverless Cluster"
descriptionNew := "Memcached Serverless Cluster updated"
resourceName := "aws_elasticache_serverless_cache.test"
var serverlessElasticCache awstypes.ServerlessCache
var v1, v2, v3, v4 awstypes.ServerlessCache

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
Expand All @@ -283,7 +285,7 @@ func TestAccElastiCacheServerlessCache_updatesc(t *testing.T) {
{
Config: testAccServerlessCacheConfig_updatesc(rName, descriptionOld, 1, 1000),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckServerlessCacheExists(ctx, resourceName, &serverlessElasticCache),
testAccCheckServerlessCacheExists(ctx, resourceName, &v1),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
resource.TestCheckResourceAttrSet(resourceName, "cache_usage_limits.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCreateTime),
Expand All @@ -302,10 +304,47 @@ func TestAccElastiCacheServerlessCache_updatesc(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccServerlessCacheConfig_updatesc(rName, descriptionOld, 2, 1000),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckServerlessCacheExists(ctx, resourceName, &v2),
testAccCheckServerlessCacheNotRecreated(&v1, &v2),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
resource.TestCheckResourceAttrSet(resourceName, "cache_usage_limits.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCreateTime),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, descriptionOld),
resource.TestCheckResourceAttrSet(resourceName, "endpoint.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngine),
resource.TestCheckResourceAttrSet(resourceName, "full_engine_version"),
resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint.#"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus),
resource.TestCheckResourceAttrSet(resourceName, "subnet_ids.#"),
),
},
{
Config: testAccServerlessCacheConfig_updatesc(rName, descriptionNew, 2, 1000),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckServerlessCacheExists(ctx, resourceName, &v3),
testAccCheckServerlessCacheNotRecreated(&v2, &v3),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
resource.TestCheckResourceAttrSet(resourceName, "cache_usage_limits.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCreateTime),
resource.TestCheckResourceAttr(resourceName, names.AttrDescription, descriptionNew),
resource.TestCheckResourceAttrSet(resourceName, "endpoint.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrEngine),
resource.TestCheckResourceAttrSet(resourceName, "full_engine_version"),
resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint.#"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrSet(resourceName, names.AttrStatus),
resource.TestCheckResourceAttrSet(resourceName, "subnet_ids.#"),
),
},
{
Config: testAccServerlessCacheConfig_updatesc(rName, descriptionNew, 2, 1010),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckServerlessCacheExists(ctx, resourceName, &serverlessElasticCache),
testAccCheckServerlessCacheExists(ctx, resourceName, &v4),
testAccCheckServerlessCacheNotRecreated(&v3, &v4),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
resource.TestCheckResourceAttrSet(resourceName, "cache_usage_limits.#"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCreateTime),
Expand Down Expand Up @@ -461,6 +500,16 @@ func testAccCheckServerlessCacheDestroy(ctx context.Context) resource.TestCheckF
}
}

func testAccCheckServerlessCacheNotRecreated(i, j *awstypes.ServerlessCache) resource.TestCheckFunc {
return func(s *terraform.State) error {
if !aws.ToTime(i.CreateTime).Equal(aws.ToTime(j.CreateTime)) {
return errors.New("ElastiCache Serverless Cache was recreated")
}

return nil
}
}

func testAccServerlessCacheConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_elasticache_serverless_cache" "test" {
Expand Down Expand Up @@ -549,26 +598,30 @@ resource "aws_elasticache_serverless_cache" "test" {
snapshot_retention_limit = 1
security_group_ids = [aws_security_group.test.id]
subnet_ids = aws_subnet.test[*].id
tags = {
Name = %[1]q
}
}
resource "aws_kms_key" "test" {
description = "tf-test-cmk-kms-key-id"
description = %[1]q
}
resource "aws_security_group" "test" {
name = %[1]q
description = %[1]q
vpc_id = aws_vpc.test.id
name = %[1]q
vpc_id = aws_vpc.test.id
ingress {
from_port = -1
to_port = -1
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = %[1]q
}
}
`, rName))
}
Expand Down

0 comments on commit fe926cd

Please sign in to comment.