Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_docdbelastic_cluster: Add backup_retention_period and pr… #38952

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/38952.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_docdbelastic_cluster: Add backup_retention_period and preferred_backup_window arguments.
```
31 changes: 31 additions & 0 deletions internal/service/docdbelastic/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ func (r *resourceCluster) Schema(ctx context.Context, _ resource.SchemaRequest,
stringplanmodifier.UseStateForUnknown(),
},
},
"backup_retention_period": schema.Int64Attribute{
Optional: true,
},
"preferred_backup_window": schema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"shard_capacity": schema.Int64Attribute{
Required: true,
},
Expand Down Expand Up @@ -180,6 +189,14 @@ func (r *resourceCluster) Create(ctx context.Context, request resource.CreateReq
input.PreferredMaintenanceWindow = flex.StringFromFramework(ctx, plan.PreferredMaintenanceWindow)
}

if !plan.PreferredBackupWindow.IsNull() || !plan.PreferredBackupWindow.IsUnknown() {
input.PreferredBackupWindow = flex.StringFromFramework(ctx, plan.PreferredBackupWindow)
}

if !plan.BackupRetentionPeriod.IsNull() || !plan.BackupRetentionPeriod.IsUnknown() {
input.BackupRetentionPeriod = flex.Int32FromFramework(ctx, plan.BackupRetentionPeriod)
}

if !plan.SubnetIds.IsNull() || !plan.SubnetIds.IsUnknown() {
input.SubnetIds = flex.ExpandFrameworkStringValueSet(ctx, plan.SubnetIds)
}
Expand Down Expand Up @@ -280,6 +297,14 @@ func (r *resourceCluster) Update(ctx context.Context, request resource.UpdateReq
input.PreferredMaintenanceWindow = flex.StringFromFramework(ctx, plan.PreferredMaintenanceWindow)
}

if !plan.PreferredBackupWindow.Equal(state.PreferredBackupWindow) {
input.PreferredBackupWindow = flex.StringFromFramework(ctx, plan.PreferredBackupWindow)
}

if !plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) {
input.BackupRetentionPeriod = flex.Int32FromFramework(ctx, plan.BackupRetentionPeriod)
}

if !plan.ShardCapacity.Equal(state.ShardCapacity) {
input.ShardCapacity = flex.Int32FromFramework(ctx, plan.ShardCapacity)
}
Expand Down Expand Up @@ -385,6 +410,8 @@ type resourceClusterData struct {
ID types.String `tfsdk:"id"`
KmsKeyID types.String `tfsdk:"kms_key_id"`
Name types.String `tfsdk:"name"`
BackupRetentionPeriod types.Int64 `tfsdk:"backup_retention_period"`
PreferredBackupWindow types.String `tfsdk:"preferred_backup_window"`
PreferredMaintenanceWindow types.String `tfsdk:"preferred_maintenance_window"`
ShardCapacity types.Int64 `tfsdk:"shard_capacity"`
ShardCount types.Int64 `tfsdk:"shard_count"`
Expand Down Expand Up @@ -494,6 +521,8 @@ func (r *resourceClusterData) refreshFromOutput(ctx context.Context, output *aws
r.KmsKeyID = flex.StringToFramework(ctx, output.KmsKeyId)
r.Name = flex.StringToFramework(ctx, output.ClusterName)
r.PreferredMaintenanceWindow = flex.StringToFramework(ctx, output.PreferredMaintenanceWindow)
r.PreferredBackupWindow = flex.StringToFramework(ctx, output.PreferredBackupWindow)
r.BackupRetentionPeriod = flex.Int32ToFramework(ctx, output.BackupRetentionPeriod)
r.ShardCapacity = flex.Int32ToFramework(ctx, output.ShardCapacity)
r.ShardCount = flex.Int32ToFramework(ctx, output.ShardCount)
r.SubnetIds = flex.FlattenFrameworkStringValueSet(ctx, output.SubnetIds)
Expand All @@ -505,6 +534,8 @@ func clusterHasChanges(_ context.Context, plan, state resourceClusterData) bool
!plan.AdminUserPassword.Equal(state.AdminUserPassword) ||
!plan.AuthType.Equal(state.AuthType) ||
!plan.PreferredMaintenanceWindow.Equal(state.PreferredMaintenanceWindow) ||
!plan.PreferredBackupWindow.Equal(state.PreferredBackupWindow) ||
!plan.BackupRetentionPeriod.Equal(state.BackupRetentionPeriod) ||
!plan.ShardCapacity.Equal(state.ShardCapacity) ||
!plan.ShardCount.Equal(state.ShardCount) ||
!plan.SubnetIds.Equal(state.SubnetIds) ||
Expand Down
32 changes: 25 additions & 7 deletions internal/service/docdbelastic/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ 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.TestCheckResourceAttr(resourceName, "backup_retention_period", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "preferred_backup_window", "03:00-04:00"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
),
},
Expand Down Expand Up @@ -182,7 +184,9 @@ func TestAccDocDBElasticCluster_update(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.TestCheckResourceAttr(resourceName, "backup_retention_period", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "preferred_backup_window", "03:00-04:00"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
),
},
Expand All @@ -198,7 +202,9 @@ func TestAccDocDBElasticCluster_update(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.TestCheckResourceAttr(resourceName, "backup_retention_period", acctest.Ct2),
resource.TestCheckResourceAttr(resourceName, "preferred_backup_window", "03:00-04:00"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrARN),
),
},
Expand Down Expand Up @@ -296,7 +302,10 @@ 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"

backup_retention_period = 2
preferred_backup_window = "03:00-04:00"

vpc_security_group_ids = [
aws_security_group.test.id
Expand All @@ -323,7 +332,10 @@ 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"

backup_retention_period = 2
preferred_backup_window = "03:00-04:00"

vpc_security_group_ids = [
aws_security_group.test.id
Expand All @@ -350,7 +362,10 @@ 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"

backup_retention_period = 2
preferred_backup_window = "03:00-04:00"

vpc_security_group_ids = [
aws_security_group.test.id
Expand Down Expand Up @@ -381,7 +396,10 @@ 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"

backup_retention_period = 2
preferred_backup_window = "03:00-04:00"

vpc_security_group_ids = [
aws_security_group.test.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ The following arguments are required:

The following arguments are optional:

* `backup_retention_period` - (Optional) Number of days for which automated backups are retained. You must specify a minimum value of 1 and maximum value of 35. If not specified, 1 day will be used.
* `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.
* `preferred_backup_window` - (Optional) Daily time range during which automated backups are created if automated backups are enabled using the `backup_retention_period` parameter in UTC. Format: `hh24:mi-hh24:mi`. If not specified, a 30-minute window is selected at random from an 8-hour block of time for each AWS Region. Must be at least 30 minutes.
* `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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ The following arguments are required:

The following arguments are optional:

* `backupRetentionPeriod` - (Optional) Number of days for which automated backups are retained. You must specify a minimum value of 1 and maximum value of 35. If not specified, 1 day will be used.
* `kmsKeyId` - (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.
* `preferredMaintenanceWindow` - (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.
* `preferredBackupWindow` - (Optional) Daily time range during which automated backups are created if automated backups are enabled using the `backup_retention_period` parameter in UTC. Format: `hh24:mi-hh24:mi`. If not specified, a 30-minute window is selected at random from an 8-hour block of time for each AWS Region. Must be at least 30 minutes.
* `subnetIds` - (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 [`defaultTags` 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.
* `vpcSecurityGroupIds` - (Optional) List of VPC security groups to associate with the Elastic DocumentDB Cluster
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/docdbelastic_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ The following arguments are required:

The following arguments are optional:

* `backup_retention_period` - (Optional) Number of days for which automated backups are retained. You must specify a minimum value of 1 and maximum value of 35. If not specified, 1 day will be used.
* `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.
* `preferred_backup_window` - (Optional) Daily time range during which automated backups are created if automated backups are enabled using the `backup_retention_period` parameter in UTC. Format: `hh24:mi-hh24:mi`. If not specified, a 30-minute window is selected at random from an 8-hour block of time for each AWS Region. Must be at least 30 minutes.
* `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
Expand Down
Loading