diff --git a/.changelog/28022.txt b/.changelog/28022.txt new file mode 100644 index 00000000000..e07588f6118 --- /dev/null +++ b/.changelog/28022.txt @@ -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` +``` diff --git a/internal/service/memorydb/cluster.go b/internal/service/memorydb/cluster.go index 9204c95fdea..d0b3cec8c60 100644 --- a/internal/service/memorydb/cluster.go +++ b/internal/service/memorydb/cluster.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "log" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -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, @@ -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, @@ -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)) } @@ -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) diff --git a/internal/service/memorydb/cluster_data_source.go b/internal/service/memorydb/cluster_data_source.go index 39d4c872fca..2f338b4377d 100644 --- a/internal/service/memorydb/cluster_data_source.go +++ b/internal/service/memorydb/cluster_data_source.go @@ -2,6 +2,7 @@ package memorydb import ( "context" + "strconv" "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -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, @@ -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) diff --git a/internal/service/memorydb/cluster_data_source_test.go b/internal/service/memorydb/cluster_data_source_test.go index 0b0e744d613..38c69b36e51 100644 --- a/internal/service/memorydb/cluster_data_source_test.go +++ b/internal/service/memorydb/cluster_data_source_test.go @@ -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"), diff --git a/internal/service/memorydb/cluster_test.go b/internal/service/memorydb/cluster_test.go index 9d68a31462f..a620c4ea3c7 100644 --- a/internal/service/memorydb/cluster_test.go +++ b/internal/service/memorydb/cluster_test.go @@ -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"), @@ -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"), @@ -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" @@ -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), diff --git a/website/docs/d/memorydb_cluster.html.markdown b/website/docs/d/memorydb_cluster.html.markdown index 6823f6e81ee..bd24d05604d 100644 --- a/website/docs/d/memorydb_cluster.html.markdown +++ b/website/docs/d/memorydb_cluster.html.markdown @@ -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. diff --git a/website/docs/r/memorydb_cluster.html.markdown b/website/docs/r/memorydb_cluster.html.markdown index 3fd49ff9136..55c7d217949 100644 --- a/website/docs/r/memorydb_cluster.html.markdown +++ b/website/docs/r/memorydb_cluster.html.markdown @@ -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.