Skip to content

Commit

Permalink
Merge pull request #28022 from roberth-k/f-aws_memorydb_cluster-enhan…
Browse files Browse the repository at this point in the history
…cements

aws_memorydb_cluster: add data_tiering attribute and allow more than one snapshot ARN
  • Loading branch information
ewbankkit authored Nov 28, 2022
2 parents 076c989 + 9022553 commit 0fe96a1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .changelog/28022.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_memorydb_cluster: Add `data_tiering` attribute
```

```release-note:enhancement
data-source/aws_memorydb_cluster: Add `data_tiering` attribute
```

```release-note:bug
resource/aws_memorydb_cluster: Allow more than one element in `snapshot_arns`
```
21 changes: 20 additions & 1 deletion internal/service/memorydb/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -56,6 +57,12 @@ func ResourceCluster() *schema.Resource {
ForceNew: true,
},
"cluster_endpoint": endpointSchema(),
"data_tiering": {
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
Default: false,
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -188,7 +195,6 @@ func ResourceCluster() *schema.Resource {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
ConflictsWith: []string{"snapshot_name"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -275,6 +281,10 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, meta int
TLSEnabled: aws.Bool(d.Get("tls_enabled").(bool)),
}

if v, ok := d.GetOk("data_tiering"); ok {
input.DataTiering = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
Expand Down Expand Up @@ -490,6 +500,15 @@ func resourceClusterRead(ctx context.Context, d *schema.ResourceData, meta inter
d.Set("port", v.Port)
}

if v := aws.StringValue(cluster.DataTiering); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
return diag.Errorf("error reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err)
}

d.Set("data_tiering", b)
}

d.Set("description", cluster.Description)
d.Set("engine_patch_version", cluster.EnginePatchVersion)
d.Set("engine_version", cluster.EngineVersion)
Expand Down
14 changes: 14 additions & 0 deletions internal/service/memorydb/cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package memorydb

import (
"context"
"strconv"

"github.com/aws/aws-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -30,6 +31,10 @@ func DataSourceCluster() *schema.Resource {
Computed: true,
},
"cluster_endpoint": endpointSchema(),
"data_tiering": {
Type: schema.TypeBool,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -176,6 +181,15 @@ func dataSourceClusterRead(ctx context.Context, d *schema.ResourceData, meta int
d.Set("port", v.Port)
}

if v := aws.StringValue(cluster.DataTiering); v != "" {
b, err := strconv.ParseBool(v)
if err != nil {
return diag.Errorf("error reading data_tiering for MemoryDB Cluster (%s): %s", d.Id(), err)
}

d.Set("data_tiering", b)
}

d.Set("description", cluster.Description)
d.Set("engine_patch_version", cluster.EnginePatchVersion)
d.Set("engine_version", cluster.EngineVersion)
Expand Down
1 change: 1 addition & 0 deletions internal/service/memorydb/cluster_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccMemoryDBClusterDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, "auto_minor_version_upgrade", resourceName, "auto_minor_version_upgrade"),
resource.TestCheckResourceAttrPair(dataSourceName, "cluster_endpoint.0.address", resourceName, "cluster_endpoint.0.address"),
resource.TestCheckResourceAttrPair(dataSourceName, "cluster_endpoint.0.port", resourceName, "cluster_endpoint.0.port"),
resource.TestCheckResourceAttrPair(dataSourceName, "data_tiering", resourceName, "data_tiering"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "engine_patch_version", resourceName, "engine_patch_version"),
resource.TestCheckResourceAttrPair(dataSourceName, "engine_version", resourceName, "engine_version"),
Expand Down
43 changes: 43 additions & 0 deletions internal/service/memorydb/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestAccMemoryDBCluster_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"),
resource.TestMatchResourceAttr(resourceName, "cluster_endpoint.0.address", regexp.MustCompile(`^clustercfg\..*?\.amazonaws\.com$`)),
resource.TestCheckResourceAttr(resourceName, "cluster_endpoint.0.port", "6379"),
resource.TestCheckResourceAttr(resourceName, "data_tiering", "false"),
resource.TestCheckResourceAttr(resourceName, "description", "Managed by Terraform"),
resource.TestCheckResourceAttrSet(resourceName, "engine_patch_version"),
resource.TestCheckResourceAttrSet(resourceName, "engine_version"),
Expand Down Expand Up @@ -95,6 +96,7 @@ func TestAccMemoryDBCluster_defaults(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "true"),
resource.TestCheckResourceAttrSet(resourceName, "cluster_endpoint.0.address"),
resource.TestCheckResourceAttr(resourceName, "cluster_endpoint.0.port", "6379"),
resource.TestCheckResourceAttr(resourceName, "data_tiering", "false"),
resource.TestCheckResourceAttr(resourceName, "description", "Managed by Terraform"),
resource.TestCheckResourceAttrSet(resourceName, "engine_patch_version"),
resource.TestCheckResourceAttrSet(resourceName, "engine_version"),
Expand Down Expand Up @@ -218,6 +220,32 @@ func TestAccMemoryDBCluster_create_noTLS(t *testing.T) {
})
}

func TestAccMemoryDBCluster_create_withDataTiering(t *testing.T) {
rName := "tf-test-" + sdkacctest.RandString(8)
resourceName := "aws_memorydb_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, memorydb.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccClusterConfig_dataTiering(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "data_tiering", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccMemoryDBCluster_create_withKMS(t *testing.T) {
rName := "tf-test-" + sdkacctest.RandString(8)
resourceName := "aws_memorydb_cluster.test"
Expand Down Expand Up @@ -1197,6 +1225,21 @@ resource "aws_memorydb_cluster" "test" {
)
}

func testAccClusterConfig_dataTiering(rName string) string {
return acctest.ConfigCompose(
testAccClusterConfig_baseNetwork(rName),
fmt.Sprintf(`
resource "aws_memorydb_cluster" "test" {
acl_name = "open-access"
data_tiering = true
name = %[1]q
node_type = "db.r6gd.xlarge"
subnet_group_name = aws_memorydb_subnet_group.test.id
}
`, rName),
)
}

func testAccClusterConfig_description(rName, description string) string {
return acctest.ConfigCompose(
testAccClusterConfig_baseNetwork(rName),
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/memorydb_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ In addition, the following attributes are exported:
* `cluster_endpoint`
* `address` - DNS hostname of the cluster configuration endpoint.
* `port` - Port number that the cluster configuration endpoint is listening on.
* `data_tiering` - True when data tiering is enabled.
* `description` - Description for the cluster.
* `engine_patch_version` - Patch version number of the Redis engine used by the cluster.
* `engine_version` - Version number of the Redis engine used by the cluster.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/memorydb_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following arguments are required:
The following arguments are optional:

* `auto_minor_version_upgrade` - (Optional, Forces new resource) When set to `true`, the cluster will automatically receive minor engine version upgrades after launch. Defaults to `true`.
* `data_tiering` - (Optional, Forces new resource) Enables data tiering. This option is not supported by all instance types. For more information, see [Data tiering](https://docs.aws.amazon.com/memorydb/latest/devguide/data-tiering.html).
* `description` - (Optional) Description for the cluster. Defaults to `"Managed by Terraform"`.
* `engine_version` - (Optional) Version number of the Redis engine to be used for the cluster. Downgrades are not supported.
* `final_snapshot_name` - (Optional) Name of the final cluster snapshot to be created when this resource is deleted. If omitted, no final snapshot will be made.
Expand Down

0 comments on commit 0fe96a1

Please sign in to comment.