From c6ea502e3faaa5940bf58535ad9aead3c369b37f Mon Sep 17 00:00:00 2001 From: Ayumi Tamai Date: Mon, 24 Jun 2024 23:56:35 +0900 Subject: [PATCH 1/9] Add backup_retention_period to docdbelastic resource --- internal/service/docdbelastic/cluster.go | 31 +++++++--- internal/service/docdbelastic/cluster_test.go | 56 ++++++++++++++++++- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/internal/service/docdbelastic/cluster.go b/internal/service/docdbelastic/cluster.go index e4c13754ab0..fc193d921a2 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 0e9d6e5ba15..5848cdd9dfc 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_update1(rName, 4), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &cluster), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), @@ -196,6 +197,24 @@ 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"), + resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), + ), + }, + { + Config: testAccClusterConfig_update2(rName, 2), + Check: resource.ComposeTestCheckFunc( + testAccCheckClusterExists(ctx, resourceName, &cluster), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), + resource.TestCheckResourceAttrSet(resourceName, names.AttrEndpoint), + resource.TestCheckResourceAttr(resourceName, "shard_capacity", acctest.Ct4), + 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 +315,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 +331,7 @@ resource "aws_docdbelastic_cluster" "test" { `, rName)) } -func testAccClusterConfig_update(rName string, shardCapacity int) string { +func testAccClusterConfig_update1(rName string, shardCapacity int) string { return acctest.ConfigCompose( testAccClusterBaseConfig(rName), fmt.Sprintf(` @@ -323,7 +344,7 @@ resource "aws_docdbelastic_cluster" "test" { admin_user_password = "testpassword" auth_type = "PLAIN_TEXT" - preferred_maintenance_window = "tue:04:00-tue:04:30" + preferred_maintenance_window = "Tue:04:00-Tue:04:30" vpc_security_group_ids = [ aws_security_group.test.id @@ -337,6 +358,35 @@ resource "aws_docdbelastic_cluster" "test" { `, rName, shardCapacity)) } +func testAccClusterConfig_update2(rName string, backupRetentionPeriod int) string { + return acctest.ConfigCompose( + testAccClusterBaseConfig(rName), + fmt.Sprintf(` +resource "aws_docdbelastic_cluster" "test" { + name = %[1]q + shard_count = 1 + shard_capacity = 4 + + admin_user_name = "testuser" + admin_user_password = "testpassword" + auth_type = "PLAIN_TEXT" + + backup_retention_period = %[2]d + + preferred_maintenance_window = "tue:04:00-tue:04:30" + + vpc_security_group_ids = [ + aws_security_group.test.id + ] + + subnet_ids = [ + aws_subnet.test[0].id, + aws_subnet.test[1].id + ] +} +`, rName, backupRetentionPeriod)) +} + func testAccClusterConfig_tags1(rName, key1, value1 string) string { return acctest.ConfigCompose( testAccClusterBaseConfig(rName), From 3caf69fb7f3591c31a6bbbf9f1dc91534f83a3c5 Mon Sep 17 00:00:00 2001 From: Ayumi Tamai Date: Sun, 21 Jul 2024 21:09:16 +0900 Subject: [PATCH 2/9] Change day of the week format for preferred_maintenance_window https://docs.aws.amazon.com/documentdb/latest/developerguide/db-cluster-modify.html --- internal/service/docdbelastic/cluster_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/service/docdbelastic/cluster_test.go b/internal/service/docdbelastic/cluster_test.go index 5848cdd9dfc..052e698c070 100644 --- a/internal/service/docdbelastic/cluster_test.go +++ b/internal/service/docdbelastic/cluster_test.go @@ -54,7 +54,7 @@ func TestAccDocDBElasticCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "admin_user_password", "testpassword"), 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"), + resource.TestCheckResourceAttr(resourceName, names.AttrPreferredMaintenanceWindow, "Tue:04:00-Tue:04:30"), resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), ), }, @@ -183,7 +183,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { 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"), + resource.TestCheckResourceAttr(resourceName, names.AttrPreferredMaintenanceWindow, "Tue:04:00-Tue:04:30"), resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), ), }, @@ -217,7 +217,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { 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"), + resource.TestCheckResourceAttr(resourceName, names.AttrPreferredMaintenanceWindow, "Tue:04:00-Tue:04:30"), resource.TestCheckResourceAttrSet(resourceName, names.AttrARN), ), }, @@ -317,7 +317,7 @@ resource "aws_docdbelastic_cluster" "test" { backup_retention_period = 1 - preferred_maintenance_window = "tue:04:00-tue:04:30" + preferred_maintenance_window = "Tue:04:00-Tue:04:30" vpc_security_group_ids = [ aws_security_group.test.id @@ -373,7 +373,7 @@ resource "aws_docdbelastic_cluster" "test" { backup_retention_period = %[2]d - preferred_maintenance_window = "tue:04:00-tue:04:30" + preferred_maintenance_window = "Tue:04:00-Tue:04:30" vpc_security_group_ids = [ aws_security_group.test.id @@ -400,7 +400,7 @@ resource "aws_docdbelastic_cluster" "test" { admin_user_password = "testpassword" auth_type = "PLAIN_TEXT" - preferred_maintenance_window = "tue:04:00-tue:04:30" + preferred_maintenance_window = "Tue:04:00-Tue:04:30" vpc_security_group_ids = [ aws_security_group.test.id @@ -431,7 +431,7 @@ resource "aws_docdbelastic_cluster" "test" { admin_user_password = "testpassword" auth_type = "PLAIN_TEXT" - preferred_maintenance_window = "tue:04:00-tue:04:30" + preferred_maintenance_window = "Tue:04:00-Tue:04:30" vpc_security_group_ids = [ aws_security_group.test.id From 7833e61a0891511c2ea5071502f026f5efa22d1b Mon Sep 17 00:00:00 2001 From: Ayumi Tamai Date: Sun, 4 Aug 2024 13:40:58 +0900 Subject: [PATCH 3/9] Update the document for docdbelastic resource --- website/docs/r/docdbelastic_cluster.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/docdbelastic_cluster.html.markdown b/website/docs/r/docdbelastic_cluster.html.markdown index 8fa7ef2ff26..7cd910b34b6 100644 --- a/website/docs/r/docdbelastic_cluster.html.markdown +++ b/website/docs/r/docdbelastic_cluster.html.markdown @@ -43,6 +43,7 @@ The following arguments are optional: * `kms_key_id` - (Optional) ARN of a KMS key that is used to encrypt the Elastic DocumentDB cluster. If not specified, the default encryption key that KMS creates for your account is used. * `preferred_maintenance_window` - (Optional) Weekly time range during which system maintenance can occur in UTC. Format: `ddd:hh24:mi-ddd:hh24:mi`. If not specified, AWS will choose a random 30-minute window on a random day of the week. +* `backup_retention_period` - (Optional) The number of days for which automatic snapshots are retained. It should be in between 1 and 35. If not specified, the default value of 1 is set. * `subnet_ids` - (Optional) IDs of subnets in which the Elastic DocumentDB Cluster operates. * `tags` - (Optional) A map of tags to assign to the collection. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `vpc_security_group_ids` - (Optional) List of VPC security groups to associate with the Elastic DocumentDB Cluster From f6a3a58ea3f7e95e1179b66e4fb8cf4e8c7f9eb0 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:28:12 -0500 Subject: [PATCH 4/9] aws_docdbelastic_cluster: add preferred_backup_window attribute --- internal/service/docdbelastic/cluster.go | 24 +++++++++++++++---- internal/service/docdbelastic/cluster_test.go | 14 +++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/internal/service/docdbelastic/cluster.go b/internal/service/docdbelastic/cluster.go index 34ea236bf9c..8bb136029ff 100644 --- a/internal/service/docdbelastic/cluster.go +++ b/internal/service/docdbelastic/cluster.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/docdbelastic" awstypes "github.com/aws/aws-sdk-go-v2/service/docdbelastic/types" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/int32validator" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -81,11 +82,11 @@ func (r *resourceCluster) Schema(ctx context.Context, _ resource.SchemaRequest, stringplanmodifier.RequiresReplace(), }, }, - "backup_retention_period": schema.Int64Attribute{ + "backup_retention_period": schema.Int32Attribute{ Optional: true, Computed: true, - Validators: []validator.Int64{ - int64validator.Between(1, 35), + Validators: []validator.Int32{ + int32validator.Between(1, 35), }, }, names.AttrEndpoint: schema.StringAttribute{ @@ -109,6 +110,13 @@ func (r *resourceCluster) Schema(ctx context.Context, _ resource.SchemaRequest, stringplanmodifier.RequiresReplace(), }, }, + "preferred_backup_window": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, names.AttrPreferredMaintenanceWindow: schema.StringAttribute{ CustomType: fwtypes.OnceAWeekWindowType, Optional: true, @@ -287,7 +295,11 @@ func (r *resourceCluster) Update(ctx context.Context, request resource.UpdateReq } if !plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) { - input.BackupRetentionPeriod = fwflex.Int32FromFramework(ctx, plan.BackupRetentionPeriod) + input.BackupRetentionPeriod = plan.BackupRetentionPeriod.ValueInt32Pointer() + } + + if !plan.PreferredBackupWindow.Equal(state.PreferredBackupWindow) { + input.PreferredBackupWindow = plan.PreferredBackupWindow.ValueStringPointer() } if !plan.PreferredMaintenanceWindow.Equal(state.PreferredMaintenanceWindow) { @@ -396,11 +408,12 @@ type resourceClusterData struct { AdminUserPassword types.String `tfsdk:"admin_user_password"` ARN types.String `tfsdk:"arn"` AuthType fwtypes.StringEnum[awstypes.Auth] `tfsdk:"auth_type"` - BackupRetentionPeriod types.Int64 `tfsdk:"backup_retention_period"` + BackupRetentionPeriod types.Int32 `tfsdk:"backup_retention_period"` Endpoint types.String `tfsdk:"endpoint"` ID types.String `tfsdk:"id"` KmsKeyID types.String `tfsdk:"kms_key_id"` Name types.String `tfsdk:"name"` + PreferredBackupWindow types.String `tfsdk:"preferred_backup_window"` PreferredMaintenanceWindow fwtypes.OnceAWeekWindow `tfsdk:"preferred_maintenance_window"` ShardCapacity types.Int64 `tfsdk:"shard_capacity"` ShardCount types.Int64 `tfsdk:"shard_count"` @@ -507,6 +520,7 @@ func clusterHasChanges(_ context.Context, plan, state resourceClusterData) bool !plan.AdminUserPassword.Equal(state.AdminUserPassword) || !plan.AuthType.Equal(state.AuthType) || !plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) || + !plan.PreferredBackupWindow.Equal(state.PreferredBackupWindow) || !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 052e698c070..9cbb2cf0642 100644 --- a/internal/service/docdbelastic/cluster_test.go +++ b/internal/service/docdbelastic/cluster_test.go @@ -180,7 +180,6 @@ 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"), @@ -188,7 +187,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { ), }, { - Config: testAccClusterConfig_update1(rName, 4), + Config: testAccClusterConfig_update(rName, 4, 1), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &cluster), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), @@ -205,7 +204,7 @@ func TestAccDocDBElasticCluster_update(t *testing.T) { ), }, { - Config: testAccClusterConfig_update2(rName, 2), + Config: testAccClusterConfig_update(rName, 4, 3), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &cluster), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), @@ -214,7 +213,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, "backup_retention_period", acctest.Ct3), 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"), @@ -315,8 +314,6 @@ 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 = [ @@ -331,7 +328,7 @@ resource "aws_docdbelastic_cluster" "test" { `, rName)) } -func testAccClusterConfig_update1(rName string, shardCapacity int) string { +func testAccClusterConfig_update(rName string, shardCapacity, backupRetentionPeriod int) string { return acctest.ConfigCompose( testAccClusterBaseConfig(rName), fmt.Sprintf(` @@ -345,6 +342,7 @@ resource "aws_docdbelastic_cluster" "test" { auth_type = "PLAIN_TEXT" preferred_maintenance_window = "Tue:04:00-Tue:04:30" + backup_retention_period = %[3]d vpc_security_group_ids = [ aws_security_group.test.id @@ -355,7 +353,7 @@ resource "aws_docdbelastic_cluster" "test" { aws_subnet.test[1].id ] } -`, rName, shardCapacity)) +`, rName, shardCapacity, backupRetentionPeriod)) } func testAccClusterConfig_update2(rName string, backupRetentionPeriod int) string { From 015bbf8dea023b368d1391cb6c49d4178f9d27d0 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:30:28 -0500 Subject: [PATCH 5/9] aws_docdbelastic_cluster: update documentation --- website/docs/r/docdbelastic_cluster.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/docs/r/docdbelastic_cluster.html.markdown b/website/docs/r/docdbelastic_cluster.html.markdown index 7cd910b34b6..eb7db190bca 100644 --- a/website/docs/r/docdbelastic_cluster.html.markdown +++ b/website/docs/r/docdbelastic_cluster.html.markdown @@ -41,9 +41,10 @@ The following arguments are required: The following arguments are optional: +* `backup_retention_period` - (Optional) The number of days for which automatic snapshots are retained. It should be in between 1 and 35. If not specified, the default value of 1 is set. * `kms_key_id` - (Optional) ARN of a KMS key that is used to encrypt the Elastic DocumentDB cluster. If not specified, the default encryption key that KMS creates for your account is used. +* `preferred_backup_window` - (Optional) The daily time range during which automated backups are created if automated backups are enabled, as determined by the `backup_retention_period`. * `preferred_maintenance_window` - (Optional) Weekly time range during which system maintenance can occur in UTC. Format: `ddd:hh24:mi-ddd:hh24:mi`. If not specified, AWS will choose a random 30-minute window on a random day of the week. -* `backup_retention_period` - (Optional) The number of days for which automatic snapshots are retained. It should be in between 1 and 35. If not specified, the default value of 1 is set. * `subnet_ids` - (Optional) IDs of subnets in which the Elastic DocumentDB Cluster operates. * `tags` - (Optional) A map of tags to assign to the collection. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `vpc_security_group_ids` - (Optional) List of VPC security groups to associate with the Elastic DocumentDB Cluster From 1f93c52b4b5f61a5a69301043269447b5a4abd8d Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:32:06 -0500 Subject: [PATCH 6/9] aws_docdbelastic_cluster: add plan modifier for backup_retention_period --- internal/service/docdbelastic/cluster.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/service/docdbelastic/cluster.go b/internal/service/docdbelastic/cluster.go index 8bb136029ff..f9658f12a69 100644 --- a/internal/service/docdbelastic/cluster.go +++ b/internal/service/docdbelastic/cluster.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" @@ -88,6 +89,9 @@ func (r *resourceCluster) Schema(ctx context.Context, _ resource.SchemaRequest, Validators: []validator.Int32{ int32validator.Between(1, 35), }, + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), + }, }, names.AttrEndpoint: schema.StringAttribute{ Computed: true, From cf73e9abdae52f23b68017345112df1a475a4ed8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:33:57 -0500 Subject: [PATCH 7/9] add CHANGELOG entry --- .changelog/38452.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/38452.txt diff --git a/.changelog/38452.txt b/.changelog/38452.txt new file mode 100644 index 00000000000..7dbcf73e825 --- /dev/null +++ b/.changelog/38452.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_docdbelastic_cluster: Add `backup_retention_period` and `preferred_backup_window` attributes +``` \ No newline at end of file From 31cc737624bca4c240cfb732fd334b64f68dbae0 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:35:49 -0500 Subject: [PATCH 8/9] chore: cleanup tests --- internal/service/docdbelastic/cluster_test.go | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/internal/service/docdbelastic/cluster_test.go b/internal/service/docdbelastic/cluster_test.go index 9cbb2cf0642..02478017b2d 100644 --- a/internal/service/docdbelastic/cluster_test.go +++ b/internal/service/docdbelastic/cluster_test.go @@ -356,35 +356,6 @@ resource "aws_docdbelastic_cluster" "test" { `, rName, shardCapacity, backupRetentionPeriod)) } -func testAccClusterConfig_update2(rName string, backupRetentionPeriod int) string { - return acctest.ConfigCompose( - testAccClusterBaseConfig(rName), - fmt.Sprintf(` -resource "aws_docdbelastic_cluster" "test" { - name = %[1]q - shard_count = 1 - shard_capacity = 4 - - admin_user_name = "testuser" - admin_user_password = "testpassword" - auth_type = "PLAIN_TEXT" - - backup_retention_period = %[2]d - - preferred_maintenance_window = "Tue:04:00-Tue:04:30" - - vpc_security_group_ids = [ - aws_security_group.test.id - ] - - subnet_ids = [ - aws_subnet.test[0].id, - aws_subnet.test[1].id - ] -} -`, rName, backupRetentionPeriod)) -} - func testAccClusterConfig_tags1(rName, key1, value1 string) string { return acctest.ConfigCompose( testAccClusterBaseConfig(rName), From 9352f729f264643962d8452ed51db863d483431a Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 5 Sep 2024 13:48:36 -0500 Subject: [PATCH 9/9] chore: ignore int32validator golangci-lint --- .ci/.golangci2.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.ci/.golangci2.yml b/.ci/.golangci2.yml index cea62cd3383..b392f719ee1 100644 --- a/.ci/.golangci2.yml +++ b/.ci/.golangci2.yml @@ -79,6 +79,7 @@ linters-settings: - schema.DefaultTimeout - validation.* # Terraform Plugin Framework + - int32validator.* - int64validator.* - listvalidator.* - setvalidator.*