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

INTMDB-587: New Feature: Backup Compliance Policy Support #1127

Merged
merged 69 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
20eaa3a
Add support for mongodbatlas_backup_compliance_policy
martinstibbe Apr 14, 2023
010e899
Update SDK
martinstibbe Apr 14, 2023
79af0ad
Preliminary Documentation
martinstibbe Apr 14, 2023
8e381b6
Add tests for BackupCompliancePolicy
martinstibbe Apr 18, 2023
a193d85
Update website/docs/r/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
d8e9937
Update mongodbatlas/resource_mongodbatlas_backup_compliance_policy.go
martinstibbe Apr 18, 2023
af24bad
Update website/docs/d/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
bdad77a
Update website/docs/d/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
0da8f52
Update website/docs/r/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
d1dc2d5
Update website/docs/d/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
ff3527e
Update website/docs/r/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
c645010
Update website/docs/r/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
b6cd7f0
Update website/docs/d/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
e67551b
Update website/docs/d/backup_compliance_policy.html.markdown
martinstibbe Apr 18, 2023
e4287dc
Update Email
martinstibbe Apr 18, 2023
ac1aaa9
Trim line length
martinstibbe Apr 18, 2023
18934db
Update SDK
martinstibbe Apr 18, 2023
1e8e619
doc updates to related resources
Zuhairahmed Apr 18, 2023
b2f53f4
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 18, 2023
6bc2c02
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 18, 2023
4258428
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 18, 2023
352b952
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 18, 2023
b030edd
Update website/docs/r/cloud_backup_schedule.html.markdown
Zuhairahmed Apr 18, 2023
0d4f70b
Update website/docs/r/cloud_backup_snapshot.html.markdown
Zuhairahmed Apr 18, 2023
ef92d94
Update website/docs/r/cluster.html.markdown
Zuhairahmed Apr 18, 2023
4d55f8c
Update website/docs/r/project.html.markdown
Zuhairahmed Apr 18, 2023
e21b378
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 18, 2023
b58b894
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 18, 2023
252f347
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 18, 2023
468ca06
cluster termination note
Zuhairahmed Apr 18, 2023
8d8b14d
Restructure parameters
martinstibbe Apr 20, 2023
b9443d5
Merge branch 'INTMDB-587' of https://github.com/mongodb/terraform-pro…
martinstibbe Apr 20, 2023
0d14808
Remove unused expandScheduledPolicyItems Update Docs tests
martinstibbe Apr 20, 2023
247be42
Update examples
martinstibbe Apr 20, 2023
e1d8591
Update docs with requested changes
martinstibbe Apr 20, 2023
3d4aba7
Update docs
martinstibbe Apr 21, 2023
0cfab9e
Remove reference_minute_of_hour parameter not used in backup policy
martinstibbe Apr 21, 2023
899d282
Update backup_compliance_policy.html.markdown
Zuhairahmed Apr 24, 2023
c259ff2
Update backup_compliance_policy.html.markdown
martinstibbe Apr 24, 2023
f024b22
Docs updates
martinstibbe Apr 24, 2023
2c2c856
Lowercase lint error
martinstibbe Apr 24, 2023
9e16437
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
97d09b1
Update website/docs/r/cluster.html.markdown
Zuhairahmed Apr 26, 2023
6cee8f0
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
889c844
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
41858e5
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 26, 2023
906a280
Update website/docs/r/cloud_backup_schedule.html.markdown
Zuhairahmed Apr 26, 2023
e0e18cf
Update website/docs/r/cloud_backup_snapshot.html.markdown
Zuhairahmed Apr 26, 2023
58ab1c4
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 26, 2023
3703ee1
Update website/docs/r/cloud_backup_snapshot.html.markdown
Zuhairahmed Apr 26, 2023
e69cccd
Update website/docs/r/cluster.html.markdown
Zuhairahmed Apr 26, 2023
21bc1ee
Update website/docs/r/project.html.markdown
Zuhairahmed Apr 26, 2023
0462b69
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
c9c3ba2
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
248a15d
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
8a2109b
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
ddec5a3
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
b3b3f67
Update website/docs/d/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
2682caf
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 26, 2023
08bbadd
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 26, 2023
cb88d34
Update website/docs/r/advanced_cluster.html.markdown
Zuhairahmed Apr 26, 2023
29ac4aa
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
f532232
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
833ea7a
Update website/docs/r/cluster.html.markdown
Zuhairahmed Apr 26, 2023
77c2e9b
Update website/docs/r/cloud_backup_snapshot.html.markdown
Zuhairahmed Apr 26, 2023
c129383
Update website/docs/r/cloud_backup_schedule.html.markdown
Zuhairahmed Apr 26, 2023
a295cac
Update mongodbatlas/resource_mongodbatlas_backup_compliance_policy_te…
Zuhairahmed Apr 26, 2023
ea8e714
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
c913bb9
Update website/docs/r/backup_compliance_policy.html.markdown
Zuhairahmed Apr 26, 2023
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.5.0
github.com/zclconf/go-cty v1.13.1
go.mongodb.org/atlas v0.24.0
go.mongodb.org/atlas v0.25.0
go.mongodb.org/realm v0.1.0
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a
)
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,8 @@ github.com/zclconf/go-cty v1.13.1 h1:0a6bRwuiSHtAmqCqNOE+c2oHgepv0ctoxU4FUe43kwc
github.com/zclconf/go-cty v1.13.1/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
go.mongodb.org/atlas v0.23.1 h1:nQjqIzAizf4uaD7lECpVF6kldnZvJnmCTDrqkS4hVyc=
go.mongodb.org/atlas v0.23.1/go.mod h1:XTjsxWgoOSwaZrQUvhTEuwjymxnF0r12RPibZuW1Uts=
go.mongodb.org/atlas v0.24.0 h1:n9ibqbxrtFOInLD6MhNupK9GKFmaH08rLwU5qnr4mpA=
go.mongodb.org/atlas v0.24.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
go.mongodb.org/atlas v0.25.0 h1:K+b9iU8TXuRByTUnL+wEwj+wx3L0UDUgXNDX/a7B0gU=
go.mongodb.org/atlas v0.25.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
286 changes: 286 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_backup_compliance_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
package mongodbatlas
Zuhairahmed marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"
"fmt"
"net/http"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
matlas "go.mongodb.org/atlas/mongodbatlas"
)

func dataSourceMongoDBAtlasBackupCompliancePolicy() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMongoDBAtlasBackupCompliancePolicyRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Required: true,
},
"authorized_email": {
Type: schema.TypeString,
Computed: true,
},
"copy_protection_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"encryption_at_rest_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"on_demand_policy_item": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"frequency_interval": {
Type: schema.TypeInt,
Computed: true,
},
"frequency_type": {
Type: schema.TypeString,
Computed: true,
},
"retention_unit": {
Type: schema.TypeString,
Computed: true,
},
"retention_value": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"pit_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"state": {
Type: schema.TypeString,
Computed: true,
},
"updated_date": {
Type: schema.TypeString,
Computed: true,
},
"updated_user": {
Type: schema.TypeString,
Computed: true,
},
"restore_window_days": {
Type: schema.TypeInt,
Computed: true,
},
"policy_item_hourly": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"frequency_type": {
Type: schema.TypeString,
Computed: true,
},
"frequency_interval": {
Type: schema.TypeInt,
Required: true,
},
"retention_value": {
Type: schema.TypeInt,
Required: true,
},
"retention_unit": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"policy_item_daily": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"frequency_type": {
Type: schema.TypeString,
Computed: true,
},
"frequency_interval": {
Type: schema.TypeInt,
Required: true,
},
"retention_unit": {
Type: schema.TypeString,
Required: true,
},
"retention_value": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"policy_item_weekly": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"frequency_type": {
Type: schema.TypeString,
Computed: true,
},
"frequency_interval": {
Type: schema.TypeInt,
Required: true,
},
"retention_unit": {
Type: schema.TypeString,
Required: true,
},
"retention_value": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"policy_item_monthly": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"frequency_type": {
Type: schema.TypeString,
Computed: true,
},
"frequency_interval": {
Type: schema.TypeInt,
Required: true,
},
"retention_unit": {
Type: schema.TypeString,
Required: true,
},
"retention_value": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
},
}
}

func dataSourceMongoDBAtlasBackupCompliancePolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*MongoDBClient).Atlas

projectID := d.Get("project_id").(string)

backupPolicy, resp, err := conn.BackupCompliancePolicy.Get(ctx, projectID)
if resp != nil && resp.StatusCode == http.StatusNotFound || backupPolicy.ProjectID == "" {
return nil
}
if err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicyRead, projectID, err))
}

if err := d.Set("authorized_email", backupPolicy.AuthorizedEmail); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "authorized_email", projectID, err))
}

if err := d.Set("state", backupPolicy.State); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "state", projectID, err))
}

if err := d.Set("restore_window_days", backupPolicy.RestoreWindowDays); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "restore_window_days", projectID, err))
}

if err := d.Set("pit_enabled", backupPolicy.PitEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "pit_enabled", projectID, err))
}

if err := d.Set("copy_protection_enabled", backupPolicy.CopyProtectionEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "copy_protection_enabled", projectID, err))
}

if err := d.Set("encryption_at_rest_enabled", backupPolicy.EncryptionAtRestEnabled); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "encryption_at_rest_enabled", projectID, err))
}

if err := d.Set("updated_date", backupPolicy.UpdatedDate); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "updated_date", projectID, err))
}

if err := d.Set("updated_user", backupPolicy.UpdatedUser); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "updated_user", projectID, err))
}

if err := d.Set("on_demand_policy_item", flattenOnDemandBackupPolicyItem(backupPolicy.OnDemandPolicyItem)); err != nil {
return diag.FromErr(fmt.Errorf(errorSnapshotBackupPolicySetting, "policies", projectID, err))
}

if err := d.Set("policy_item_hourly", flattenBackupPolicyItems(backupPolicy.ScheduledPolicyItems, snapshotScheduleHourly)); err != nil {
return diag.Errorf(errorSnapshotBackupPolicySetting, "policy_item_hourly", projectID, err)
}

if err := d.Set("policy_item_daily", flattenBackupPolicyItems(backupPolicy.ScheduledPolicyItems, snapshotScheduleDaily)); err != nil {
return diag.Errorf(errorSnapshotBackupPolicySetting, "policy_item_daily", projectID, err)
}

if err := d.Set("policy_item_weekly", flattenBackupPolicyItems(backupPolicy.ScheduledPolicyItems, snapshotScheduleWeekly)); err != nil {
return diag.Errorf(errorSnapshotBackupPolicySetting, "policy_item_weekly", projectID, err)
}

if err := d.Set("policy_item_monthly", flattenBackupPolicyItems(backupPolicy.ScheduledPolicyItems, snapshotScheduleMonthly)); err != nil {
return diag.Errorf(errorSnapshotBackupPolicySetting, "policy_item_monthly", projectID, err)
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID,
}))

return nil
}

func flattenBackupPolicyItems(items []matlas.ScheduledPolicyItem, frequencyType string) []map[string]interface{} {
policyItems := make([]map[string]interface{}, 0)
for _, v := range items {
if frequencyType == v.FrequencyType {
policyItems = append(policyItems, map[string]interface{}{
"id": v.ID,
"frequency_interval": v.FrequencyInterval,
"frequency_type": v.FrequencyType,
"retention_unit": v.RetentionUnit,
"retention_value": v.RetentionValue,
})
}
}
return policyItems
}
Loading