Skip to content

Commit b60724a

Browse files
authored
fix: Changes on_demand_policy_item attribute from required to optional for mongodbatlas_backup_compliance_policy (#3119)
* test: Reproduces failure in GH issue (`on_demand_policy_item` is required) * fix: Uses `optional` instead of `required` for `on_demand_policy_item` in `mongodbatlas_backup_compliance_policy` * doc: Adds a reference for `on_demand_policy_item` * chore: Add changelog entry * test: Add check for retention_value in on_demand_policy_item in backup compliance policy tests and remove commented code from config * doc: Add scheduled policy frequency types to backup compliance policy documentation
1 parent 572e42b commit b60724a

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

.changelog/3119.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_backup_compliance_policy: Changes `on_demand_policy_item` attribute from `required` to `optional`
3+
```

docs/data-sources/backup_compliance_policy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ In addition to all arguments above, the following attributes are exported:
144144
* `state` - Label that indicates the state of the Backup Compliance Policy settings. MongoDB Cloud ignores this setting when you enable or update the Backup Compliance Policy settings.
145145
* `updated_date` - ISO 8601 timestamp format in UTC that indicates when the user updated the Data Protection Policy settings. MongoDB Cloud ignores this setting when you enable or update the Backup Compliance Policy settings.
146146
* `updated_user` - Email address that identifies the user who updated the Backup Compliance Policy settings. MongoDB Cloud ignores this email setting when you enable or update the Backup Compliance Policy settings.
147+
* `on_demand_policy_item` - Specifications for [on-demand policy](#on-demand-policy-item).
148+
* `policy_item_hourly` - Scheduled policy using an hourly frequency type, see [block fields](#policy-item-hourly).
149+
* `policy_item_daily` - Scheduled policy using a daily frequency type, see [block fields](#policy-item-daily).
150+
* `policy_item_weekly` - Scheduled policy using a weekly frequency type, see [block fields](#policy-item-weekly).
151+
* `policy_item_monthly` - Scheduled policy using a monthly frequency type, see [block fields](#policy-item-monthly).
152+
* `policy_item_yearly` - Scheduled policy using a yearly frequency type, see [block fields](#policy-item-yearly).
147153

148154
### On Demand Policy Item
149155
* `id` - Unique identifier of the backup policy item.

docs/resources/backup_compliance_policy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ resource "mongodbatlas_backup_compliance_policy" "backup_policy" {
163163
* `pit_enabled` - Flag that indicates whether the cluster uses Continuous Cloud Backups with a Backup Compliance Policy. If unspecified, this value defaults to false.
164164
* `encryption_at_rest_enabled` - Flag that indicates whether Encryption at Rest using Customer Key Management is required for all clusters with a Backup Compliance Policy. If unspecified, this value defaults to false.
165165
* `restore_window_days` - Number of previous days that you can restore back to with Continuous Cloud Backup with a Backup Compliance Policy. You must specify a positive, non-zero integer, and the maximum retention window can't exceed the hourly retention time. This parameter applies only to Continuous Cloud Backups with a Backup Compliance Policy.
166+
* `on_demand_policy_item` - Specifications for [on-demand policy](#on-demand-policy-item).
167+
* `policy_item_hourly` - Scheduled policy using an hourly frequency type, see [block fields](#policy-item-hourly).
168+
* `policy_item_daily` - Scheduled policy using a daily frequency type, see [block fields](#policy-item-daily).
169+
* `policy_item_weekly` - Scheduled policy using a weekly frequency type, see [block fields](#policy-item-weekly).
170+
* `policy_item_monthly` - Scheduled policy using a monthly frequency type, see [block fields](#policy-item-monthly).
171+
* `policy_item_yearly` - Scheduled policy using a yearly frequency type, see [block fields](#policy-item-yearly).
166172

167173
## Attributes Reference
168174

internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
285285
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "updated_user", projectID, err))
286286
}
287287

288-
if err := d.Set("on_demand_policy_item", flattenOnDemandBackupPolicyItem(policy.GetOnDemandPolicyItem())); err != nil {
289-
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "policies", projectID, err))
288+
if err := d.Set("on_demand_policy_item", flattenOnDemandBackupPolicyItem(policy.OnDemandPolicyItem)); err != nil {
289+
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "on_demand_policy_item", projectID, err))
290290
}
291291

292292
if err := d.Set("policy_item_hourly", flattenBackupPolicyItems(policy.GetScheduledPolicyItems(), cloudbackupschedule.Hourly)); err != nil {

internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func Resource() *schema.Resource {
7070
"on_demand_policy_item": {
7171
Type: schema.TypeList,
7272
MaxItems: 1,
73-
Required: true,
73+
Optional: true,
7474
Elem: &schema.Resource{
7575
Schema: map[string]*schema.Schema{
7676
"id": {
@@ -330,8 +330,8 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
330330
return diag.FromErr(fmt.Errorf(errorBackupPolicySetting, "pit_enabled", projectID, err))
331331
}
332332

333-
if err := d.Set("on_demand_policy_item", flattenOnDemandBackupPolicyItem(policy.GetOnDemandPolicyItem())); err != nil {
334-
return diag.FromErr(fmt.Errorf(errorBackupPolicySetting, "scheduled_policy_items", projectID, err))
333+
if err := d.Set("on_demand_policy_item", flattenOnDemandBackupPolicyItem(policy.OnDemandPolicyItem)); err != nil {
334+
return diag.FromErr(fmt.Errorf(errorBackupPolicySetting, "on_demand_policy_item", projectID, err))
335335
}
336336

337337
if err := d.Set("policy_item_hourly", flattenBackupPolicyItems(policy.GetScheduledPolicyItems(), cloudbackupschedule.Hourly)); err != nil {
@@ -411,7 +411,10 @@ func resourceImport(ctx context.Context, d *schema.ResourceData, meta any) ([]*s
411411
return []*schema.ResourceData{d}, nil
412412
}
413413

414-
func flattenOnDemandBackupPolicyItem(item admin.BackupComplianceOnDemandPolicyItem) []map[string]any {
414+
func flattenOnDemandBackupPolicyItem(item *admin.BackupComplianceOnDemandPolicyItem) []map[string]any {
415+
if item == nil {
416+
return nil
417+
}
415418
return []map[string]any{
416419
{
417420
"id": item.GetId(),

internal/service/backupcompliancepolicy/resource_backup_compliance_policy_test.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestAccBackupCompliancePolicy_overwriteBackupPolicies(t *testing.T) {
9393
})
9494
}
9595

96-
func TestAccBackupCompliancePolicy_withoutRestoreWindowDays(t *testing.T) {
96+
func TestAccBackupCompliancePolicy_withoutRestoreWindowDaysAndOnDemand(t *testing.T) {
9797
var (
9898
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
9999
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid conflicts with backup compliance policy
@@ -105,11 +105,12 @@ func TestAccBackupCompliancePolicy_withoutRestoreWindowDays(t *testing.T) {
105105
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
106106
Steps: []resource.TestStep{
107107
{
108-
Config: configWithoutRestoreDays(projectName, orgID, projectOwnerID),
108+
Config: configWithoutRestoreDaysAndOnDemand(projectName, orgID, projectOwnerID),
109109
Check: resource.ComposeAggregateTestCheckFunc(
110110
checkExists(resourceName),
111111
resource.TestCheckResourceAttr(resourceName, "copy_protection_enabled", "false"),
112112
resource.TestCheckResourceAttr(resourceName, "encryption_at_rest_enabled", "false"),
113+
resource.TestCheckResourceAttr(resourceName, "on_demand_policy_item.#", "0"),
113114
),
114115
},
115116
},
@@ -136,6 +137,7 @@ func TestAccBackupCompliancePolicy_UpdateSetsAllAttributes(t *testing.T) {
136137
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "false"),
137138
resource.TestCheckResourceAttr(resourceName, "encryption_at_rest_enabled", "false"),
138139
resource.TestCheckResourceAttr(resourceName, "copy_protection_enabled", "true"),
140+
resource.TestCheckResourceAttr(resourceName, "on_demand_policy_item.0.retention_value", "3"),
139141
),
140142
},
141143
{
@@ -324,7 +326,7 @@ func configWithoutOptionals(projectName, orgID, projectOwnerID string) string {
324326
`
325327
}
326328

327-
func configWithoutRestoreDays(projectName, orgID, projectOwnerID string) string {
329+
func configWithoutRestoreDaysAndOnDemand(projectName, orgID, projectOwnerID string) string {
328330
return acc.ConfigProjectWithSettings(projectName, orgID, projectOwnerID, false) + `
329331
resource "mongodbatlas_backup_compliance_policy" "backup_policy_res" {
330332
project_id = mongodbatlas_project.test.id
@@ -335,14 +337,6 @@ func configWithoutRestoreDays(projectName, orgID, projectOwnerID string) string
335337
pit_enabled = false
336338
encryption_at_rest_enabled = false
337339
338-
//restore_window_days = 7
339-
340-
on_demand_policy_item {
341-
frequency_interval = 0
342-
retention_unit = "days"
343-
retention_value = 3
344-
}
345-
346340
policy_item_hourly {
347341
frequency_interval = 6
348342
retention_unit = "days"

0 commit comments

Comments
 (0)