diff --git a/internal/service/docdbelastic/cluster.go b/internal/service/docdbelastic/cluster.go index e4c13754ab0a..fc193d921a24 100644 --- a/internal/service/docdbelastic/cluster.go +++ b/internal/service/docdbelastic/cluster.go @@ -81,6 +81,13 @@ func (r *resourceCluster) Schema(ctx context.Context, _ resource.SchemaRequest, enum.FrameworkValidate[awstypes.Auth](), }, }, + "backup_retention_period": schema.Int64Attribute{ + Optional: true, + Computed: true, + Validators: []validator.Int64{ + int64validator.Between(1, 35), + }, + }, names.AttrEndpoint: schema.StringAttribute{ Computed: true, PlanModifiers: []planmodifier.String{ @@ -162,14 +169,15 @@ func (r *resourceCluster) Create(ctx context.Context, request resource.CreateReq } input := &docdbelastic.CreateClusterInput{ - ClientToken: aws.String(id.UniqueId()), - AdminUserName: flex.StringFromFramework(ctx, plan.AdminUserName), - AdminUserPassword: flex.StringFromFramework(ctx, plan.AdminUserPassword), - AuthType: awstypes.Auth(plan.AuthType.ValueString()), - ClusterName: flex.StringFromFramework(ctx, plan.Name), - ShardCapacity: flex.Int32FromFramework(ctx, plan.ShardCapacity), - ShardCount: flex.Int32FromFramework(ctx, plan.ShardCount), - Tags: getTagsIn(ctx), + ClientToken: aws.String(id.UniqueId()), + AdminUserName: flex.StringFromFramework(ctx, plan.AdminUserName), + AdminUserPassword: flex.StringFromFramework(ctx, plan.AdminUserPassword), + AuthType: awstypes.Auth(plan.AuthType.ValueString()), + BackupRetentionPeriod: flex.Int32FromFramework(ctx, plan.BackupRetentionPeriod), + ClusterName: flex.StringFromFramework(ctx, plan.Name), + ShardCapacity: flex.Int32FromFramework(ctx, plan.ShardCapacity), + ShardCount: flex.Int32FromFramework(ctx, plan.ShardCount), + Tags: getTagsIn(ctx), } if !plan.KmsKeyID.IsNull() || !plan.KmsKeyID.IsUnknown() { @@ -276,6 +284,10 @@ func (r *resourceCluster) Update(ctx context.Context, request resource.UpdateReq input.AuthType = awstypes.Auth(plan.AuthType.ValueString()) } + if !plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) { + input.BackupRetentionPeriod = flex.Int32FromFramework(ctx, plan.BackupRetentionPeriod) + } + if !plan.PreferredMaintenanceWindow.Equal(state.PreferredMaintenanceWindow) { input.PreferredMaintenanceWindow = flex.StringFromFramework(ctx, plan.PreferredMaintenanceWindow) } @@ -381,6 +393,7 @@ type resourceClusterData struct { AdminUserPassword types.String `tfsdk:"admin_user_password"` ARN types.String `tfsdk:"arn"` AuthType types.String `tfsdk:"auth_type"` + BackupRetentionPeriod types.Int64 `tfsdk:"backup_retention_period"` Endpoint types.String `tfsdk:"endpoint"` ID types.String `tfsdk:"id"` KmsKeyID types.String `tfsdk:"kms_key_id"` @@ -489,6 +502,7 @@ func findClusterByID(ctx context.Context, conn *docdbelastic.Client, id string) func (r *resourceClusterData) refreshFromOutput(ctx context.Context, output *awstypes.Cluster) { r.AdminUserName = flex.StringToFrameworkLegacy(ctx, output.AdminUserName) r.AuthType = flex.StringValueToFramework(ctx, string(output.AuthType)) + r.BackupRetentionPeriod = flex.Int32ToFramework(ctx, output.BackupRetentionPeriod) r.ARN = flex.StringToFramework(ctx, output.ClusterArn) r.Endpoint = flex.StringToFramework(ctx, output.ClusterEndpoint) r.KmsKeyID = flex.StringToFramework(ctx, output.KmsKeyId) @@ -504,6 +518,7 @@ func clusterHasChanges(_ context.Context, plan, state resourceClusterData) bool return !plan.Name.Equal(state.Name) || !plan.AdminUserPassword.Equal(state.AdminUserPassword) || !plan.AuthType.Equal(state.AuthType) || + !plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) || !plan.PreferredMaintenanceWindow.Equal(state.PreferredMaintenanceWindow) || !plan.ShardCapacity.Equal(state.ShardCapacity) || !plan.ShardCount.Equal(state.ShardCount) || diff --git a/internal/service/docdbelastic/cluster_test.go b/internal/service/docdbelastic/cluster_test.go index 0e9d6e5ba154..859aa753641f 100644 --- a/internal/service/docdbelastic/cluster_test.go +++ b/internal/service/docdbelastic/cluster_test.go @@ -180,6 +180,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "shard_count", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "admin_user_name", "testuser"), resource.TestCheckResourceAttr(resourceName, "admin_user_password", "testpassword"), + resource.TestCheckResourceAttr(resourceName, "backup_retention_period", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", acctest.Ct2), resource.TestCheckResourceAttr(resourceName, "vpc_security_group_ids.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, names.AttrPreferredMaintenanceWindow, "tue:04:00-tue:04:30"), @@ -187,7 +188,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { ), }, { - Config: testAccClusterConfig_update(rName, 4), + Config: testAccClusterConfig_update(rName, 4, 2), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &cluster), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), @@ -196,6 +197,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "shard_count", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, "admin_user_name", "testuser"), resource.TestCheckResourceAttr(resourceName, "admin_user_password", "testpassword"), + resource.TestCheckResourceAttr(resourceName, "backup_retention_period", acctest.Ct2), resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", acctest.Ct2), resource.TestCheckResourceAttr(resourceName, "vpc_security_group_ids.#", acctest.Ct1), resource.TestCheckResourceAttr(resourceName, names.AttrPreferredMaintenanceWindow, "tue:04:00-tue:04:30"), @@ -296,6 +298,8 @@ resource "aws_docdbelastic_cluster" "test" { admin_user_password = "testpassword" auth_type = "PLAIN_TEXT" + backup_retention_period = 1 + preferred_maintenance_window = "tue:04:00-tue:04:30" vpc_security_group_ids = [ @@ -310,7 +314,7 @@ resource "aws_docdbelastic_cluster" "test" { `, rName)) } -func testAccClusterConfig_update(rName string, shardCapacity int) string { +func testAccClusterConfig_update(rName string, shardCapacity int, backupRetentionPeriod int) string { return acctest.ConfigCompose( testAccClusterBaseConfig(rName), fmt.Sprintf(` @@ -323,6 +327,8 @@ resource "aws_docdbelastic_cluster" "test" { admin_user_password = "testpassword" auth_type = "PLAIN_TEXT" + backup_retention_period = %[3]d + preferred_maintenance_window = "tue:04:00-tue:04:30" vpc_security_group_ids = [ @@ -334,7 +340,7 @@ resource "aws_docdbelastic_cluster" "test" { aws_subnet.test[1].id ] } -`, rName, shardCapacity)) +`, rName, shardCapacity, backupRetentionPeriod)) } func testAccClusterConfig_tags1(rName, key1, value1 string) string {