-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Handles update of
mongodbatlas_backup_compliance_policy
as a c…
…reate operation (#2480) * handle update as a create * add test to make sure no plan changes appear when reapplying config with non default values * add changelog * fix projectId * fix name of resource in test * Update .changelog/2480.txt Co-authored-by: kyuan-mongodb <[email protected]> --------- Co-authored-by: kyuan-mongodb <[email protected]>
- Loading branch information
1 parent
94371a9
commit 99e9212
Showing
3 changed files
with
169 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
resource/mongodbatlas_backup_compliance_policy: Fixes an issue where the update operation modified attributes that were not supposed to be modified" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/plancheck" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" | ||
|
@@ -116,6 +117,41 @@ func TestAccBackupCompliancePolicy_withoutRestoreWindowDays(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccBackupCompliancePolicy_UpdateSetsAllAttributes(t *testing.T) { | ||
var ( | ||
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") | ||
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid conflicts with backup compliance policy | ||
projectOwnerID = os.Getenv("MONGODB_ATLAS_PROJECT_OWNER_ID") | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { acc.PreCheckBasic(t) }, | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: configBasicWithOptionalAttributesWithNonDefaultValues(projectName, orgID, projectOwnerID), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
checkExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "authorized_user_first_name", "First"), | ||
resource.TestCheckResourceAttr(resourceName, "authorized_user_last_name", "Last"), | ||
resource.TestCheckResourceAttr(resourceName, "pit_enabled", "false"), | ||
resource.TestCheckResourceAttr(resourceName, "encryption_at_rest_enabled", "false"), | ||
resource.TestCheckResourceAttr(resourceName, "copy_protection_enabled", "true"), | ||
), | ||
}, | ||
{ | ||
Config: configBasicWithOptionalAttributesWithNonDefaultValues(projectName, orgID, projectOwnerID), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
PreApply: []plancheck.PlanCheck{ | ||
acc.DebugPlan(), | ||
plancheck.ExpectEmptyPlan(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func basicTestCase(tb testing.TB, useYearly bool) *resource.TestCase { | ||
tb.Helper() | ||
|
||
|
@@ -419,3 +455,48 @@ func basicChecks() []resource.TestCheckFunc { | |
checks = append(checks, checkExists(resourceName), checkExists(dataSourceName)) | ||
return checks | ||
} | ||
|
||
func configBasicWithOptionalAttributesWithNonDefaultValues(projectName, orgID, projectOwnerID string) string { | ||
return acc.ConfigProjectWithSettings(projectName, orgID, projectOwnerID, false) + | ||
`resource "mongodbatlas_backup_compliance_policy" "backup_policy_res" { | ||
project_id = mongodbatlas_project.test.id | ||
authorized_email = "[email protected]" | ||
authorized_user_first_name = "First" | ||
authorized_user_last_name = "Last" | ||
copy_protection_enabled = true | ||
pit_enabled = false | ||
encryption_at_rest_enabled = false | ||
restore_window_days = 7 | ||
on_demand_policy_item { | ||
frequency_interval = 0 | ||
retention_unit = "days" | ||
retention_value = 3 | ||
} | ||
policy_item_hourly { | ||
frequency_interval = 6 | ||
retention_unit = "days" | ||
retention_value = 7 | ||
} | ||
policy_item_daily { | ||
frequency_interval = 0 | ||
retention_unit = "days" | ||
retention_value = 7 | ||
} | ||
policy_item_weekly { | ||
frequency_interval = 0 | ||
retention_unit = "weeks" | ||
retention_value = 4 | ||
} | ||
policy_item_monthly { | ||
frequency_interval = 0 | ||
retention_unit = "months" | ||
retention_value = 12 | ||
} | ||
}` | ||
} |