Skip to content

Commit e1e21ed

Browse files
authored
fix: improved error handling for cloud_backup_schedule resource. (#1474)
* Added documentation details regarding the creation process of the cloud_backup_schedule. * fix: checked existing policy ID only if connection request does not return error.
1 parent 0dfe33d commit e1e21ed

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mongodbatlas/resource_mongodbatlas_cloud_backup_schedule.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,16 @@ func resourceMongoDBAtlasCloudBackupScheduleImportState(ctx context.Context, d *
454454
}
455455

456456
func cloudBackupScheduleCreateOrUpdate(ctx context.Context, conn *matlas.Client, d *schema.ResourceData, projectID, clusterName string) error {
457+
policy := matlas.Policy{}
457458
// Get policies items
458459
resp, _, err := conn.CloudProviderSnapshotBackupPolicies.Get(ctx, projectID, clusterName)
459460
if err != nil {
460461
log.Printf("error getting MongoDB Cloud Backup Schedule (%s): %s", clusterName, err)
462+
} else if len(resp.Policies) == 1 {
463+
policy.ID = resp.Policies[0].ID
461464
}
462465

463466
req := &matlas.CloudProviderSnapshotBackupPolicy{}
464-
policy := matlas.Policy{}
465467
policyItem := matlas.PolicyItem{}
466468
var policiesItem []matlas.PolicyItem
467469
export := matlas.Export{}
@@ -535,10 +537,6 @@ func cloudBackupScheduleCreateOrUpdate(ctx context.Context, conn *matlas.Client,
535537
req.UseOrgAndGroupNamesInExportPrefix = pointy.Bool(d.Get("use_org_and_group_names_in_export_prefix").(bool))
536538
}
537539

538-
if len(resp.Policies) == 1 {
539-
policy.ID = resp.Policies[0].ID
540-
}
541-
542540
policy.PolicyItems = policiesItem
543541
if len(policiesItem) > 0 {
544542
req.Policies = []matlas.Policy{policy}

website/docs/r/cloud_backup_schedule.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ description: |-
1616

1717
-> **NOTE:** If Backup Compliance Policy is enabled for the project for which this backup schedule is defined, you cannot modify the backup schedule for an individual cluster below the minimum requirements set in the Backup Compliance Policy. See [Backup Compliance Policy Prohibited Actions and Considerations](https://www.mongodb.com/docs/atlas/backup/cloud-backup/backup-compliance-policy/#configure-a-backup-compliance-policy).
1818

19+
-> **NOTE:** When creating a backup schedule you **must either** use the `depends_on` clause to indicate the cluster to which it refers **or** specify the values of `project_id` and `cluster_name` as reference of the cluster resource (e.g. `cluster_name = mongodbatlas_cluster.my_cluster.name` - see the example below). Failure in doing so will result in an error when executing the plan.
20+
1921
In the Terraform MongoDB Atlas Provider 1.0.0 we have re-architected the way in which Cloud Backup Policies are manged with Terraform to significantly reduce the complexity. Due to this change we've provided multiple examples below to help express how this new resource functions.
2022

2123

0 commit comments

Comments
 (0)