diff --git a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go index df9e6fb41..5ef71a1f5 100644 --- a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go +++ b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/model.go @@ -4,28 +4,31 @@ package resource // Model is autogenerated from the json schema type Model struct { - ProjectId *string `json:",omitempty"` - InstanceType *string `json:",omitempty"` - InstanceName *string `json:",omitempty"` - Id *string `json:",omitempty"` - DeliveryType *string `json:",omitempty"` - DeliveryUrl []string `json:",omitempty"` - Cancelled *bool `json:",omitempty"` - Failed *bool `json:",omitempty"` - Expired *bool `json:",omitempty"` - ExpiresAt *string `json:",omitempty"` - FinishedAt *string `json:",omitempty"` - Timestamp *string `json:",omitempty"` - SnapshotId *string `json:",omitempty"` - Links []Links `json:",omitempty"` - OpLogTs *string `json:",omitempty"` - OpLogInc *string `json:",omitempty"` - PointInTimeUtcSeconds *int `json:",omitempty"` - TargetProjectId *string `json:",omitempty"` - TargetClusterName *string `json:",omitempty"` - Profile *string `json:",omitempty"` - EnableSynchronousCreation *bool `json:",omitempty"` - SynchronousCreationOptions *SynchronousCreationOptions `json:",omitempty"` + ProjectId *string `json:",omitempty"` + InstanceType *string `json:",omitempty"` + InstanceName *string `json:",omitempty"` + Id *string `json:",omitempty"` + DeliveryType *string `json:",omitempty"` + DeliveryUrl []string `json:",omitempty"` + Cancelled *bool `json:",omitempty"` + Failed *bool `json:",omitempty"` + Expired *bool `json:",omitempty"` + ExpiresAt *string `json:",omitempty"` + FinishedAt *string `json:",omitempty"` + Timestamp *string `json:",omitempty"` + SnapshotId *string `json:",omitempty"` + Links []Links `json:",omitempty"` + DesiredTimestamp *DesiredTimestamp `json:",omitempty"` + PrivateDownloadDeliveryUrls []PrivateDownloadDeliveryUrl `json:",omitempty"` + Components []Component `json:",omitempty"` + OpLogTs *string `json:",omitempty"` + OpLogInc *string `json:",omitempty"` + PointInTimeUtcSeconds *int `json:",omitempty"` + TargetProjectId *string `json:",omitempty"` + TargetClusterName *string `json:",omitempty"` + Profile *string `json:",omitempty"` + EnableSynchronousCreation *bool `json:",omitempty"` + SynchronousCreationOptions *SynchronousCreationOptions `json:",omitempty"` } // Links is autogenerated from the json schema @@ -34,6 +37,25 @@ type Links struct { Href *string `json:",omitempty"` } +// DesiredTimestamp is autogenerated from the json schema +type DesiredTimestamp struct { + Date *string `json:",omitempty"` + Increment *int `json:",omitempty"` +} + +// PrivateDownloadDeliveryUrl is autogenerated from the json schema +type PrivateDownloadDeliveryUrl struct { + DeliveryUrl *string `json:",omitempty"` + EndpointId *string `json:",omitempty"` +} + +// Component is autogenerated from the json schema +type Component struct { + DownloadUrl *string `json:",omitempty"` + ReplicaSetName *string `json:",omitempty"` + PrivateDownloadDeliveryUrls []PrivateDownloadDeliveryUrl `json:",omitempty"` +} + // SynchronousCreationOptions is autogenerated from the json schema type SynchronousCreationOptions struct { TimeOutInSeconds *int `json:",omitempty"` diff --git a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go index b9bdcbb0c..d67cbf61c 100644 --- a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go @@ -20,11 +20,11 @@ import ( "fmt" "time" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" - "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "go.mongodb.org/atlas-sdk/v20250312013/admin" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -105,7 +105,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler currentModel.Id = serverless.Id } else { params := paramsServer(currentModel) - server, resp, err := client.Atlas20231115014.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute() + server, resp, err := client.AtlasSDK.CloudBackupsApi.CreateBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, params).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), resp), nil } @@ -205,7 +205,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler }, nil } - _, resp, err := client.Atlas20231115014.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute() + resp, err := client.AtlasSDK.CloudBackupsApi.CancelBackupRestoreJob(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName, *currentModel.Id).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), resp), nil } @@ -250,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P } } } else { - server, resp, err := client.Atlas20231115014.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() + server, resp, err := client.AtlasSDK.CloudBackupsApi.ListBackupRestoreJobs(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), resp), nil } @@ -362,7 +362,7 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha } updateModelServerless(model, serverless) } else { - server, resp, err := client.Atlas20231115014.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute() + server, resp, err := client.AtlasSDK.CloudBackupsApi.GetBackupRestoreJob(context.Background(), *model.ProjectId, *model.InstanceName, *model.Id).Execute() if err != nil { pe := progressevent.GetFailedEventByResponse(err.Error(), resp) return &pe @@ -372,38 +372,49 @@ func updateModel(client *util.MongoDBClient, model *Model, checkFinish bool) *ha return nil } -func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) { - model.TargetClusterName = &job.TargetClusterName +func updateModelServer(model *Model, job *admin.DiskBackupSnapshotRestoreJob) { + model.TargetClusterName = job.TargetClusterName model.DeliveryType = &job.DeliveryType model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt) model.Id = job.Id model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt) model.SnapshotId = job.SnapshotId - model.TargetProjectId = &job.TargetGroupId + model.TargetProjectId = job.TargetGroupId model.Timestamp = util.TimePtrToStringPtr(job.Timestamp) model.Cancelled = job.Cancelled + model.Failed = job.Failed model.Expired = job.Expired model.DeliveryUrl = job.GetDeliveryUrl() model.Links = flattenLinks(job.GetLinks()) + model.DesiredTimestamp = flattenDesiredTimestamp(job.DesiredTimestamp) + model.PrivateDownloadDeliveryUrls = flattenPrivateDownloadDeliveryUrls(job.PrivateDownloadDeliveryUrls) + model.Components = flattenComponents(job.Components) } -func updateModelServer(model *Model, job *admin20231115014.DiskBackupSnapshotRestoreJob) { - model.TargetClusterName = job.TargetClusterName +func updateModelServerless(model *Model, job *admin20231115014.ServerlessBackupRestoreJob) { + if job.TargetClusterName != "" { + model.TargetClusterName = &job.TargetClusterName + } model.DeliveryType = &job.DeliveryType model.ExpiresAt = util.TimePtrToStringPtr(job.ExpiresAt) model.Id = job.Id model.FinishedAt = util.TimePtrToStringPtr(job.FinishedAt) model.SnapshotId = job.SnapshotId - model.TargetProjectId = job.TargetGroupId + if job.TargetGroupId != "" { + model.TargetProjectId = &job.TargetGroupId + } model.Timestamp = util.TimePtrToStringPtr(job.Timestamp) model.Cancelled = job.Cancelled model.Failed = job.Failed model.Expired = job.Expired model.DeliveryUrl = job.GetDeliveryUrl() - model.Links = flattenLinks(job.GetLinks()) + model.Links = flattenLinksV20231115014(job.GetLinks()) + model.DesiredTimestamp = nil + model.PrivateDownloadDeliveryUrls = nil + model.Components = nil } -func flattenLinks(linksResult []admin20231115014.Link) []Links { +func flattenLinks(linksResult []admin.Link) []Links { links := make([]Links, 0) for _, link := range linksResult { var lin Links @@ -414,8 +425,60 @@ func flattenLinks(linksResult []admin20231115014.Link) []Links { return links } -func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob { - return &admin20231115014.DiskBackupSnapshotRestoreJob{ +func flattenLinksV20231115014(linksResult []admin20231115014.Link) []Links { + links := make([]Links, 0) + for _, link := range linksResult { + var lin Links + lin.Href = link.Href + lin.Rel = link.Rel + links = append(links, lin) + } + return links +} + +func flattenDesiredTimestamp(timestamp *admin.ApiBSONTimestamp) *DesiredTimestamp { + if timestamp == nil { + return nil + } + return &DesiredTimestamp{ + Date: util.TimePtrToStringPtr(timestamp.Date), + Increment: timestamp.Increment, + } +} + +func flattenPrivateDownloadDeliveryUrls(urls *[]admin.ApiPrivateDownloadDeliveryUrl) []PrivateDownloadDeliveryUrl { + if urls == nil || len(*urls) == 0 { + return nil + } + + result := make([]PrivateDownloadDeliveryUrl, 0, len(*urls)) + for _, url := range *urls { + result = append(result, PrivateDownloadDeliveryUrl{ + DeliveryUrl: url.DeliveryUrl, + EndpointId: url.EndpointId, + }) + } + return result +} + +func flattenComponents(components *[]admin.DiskBackupRestoreMember) []Component { + if components == nil || len(*components) == 0 { + return nil + } + + result := make([]Component, 0, len(*components)) + for _, comp := range *components { + result = append(result, Component{ + DownloadUrl: comp.DownloadUrl, + ReplicaSetName: comp.ReplicaSetName, + PrivateDownloadDeliveryUrls: flattenPrivateDownloadDeliveryUrls(comp.PrivateDownloadDeliveryUrls), + }) + } + return result +} + +func paramsServer(model *Model) *admin.DiskBackupSnapshotRestoreJob { + return &admin.DiskBackupSnapshotRestoreJob{ SnapshotId: model.SnapshotId, DeliveryType: *model.DeliveryType, TargetClusterName: model.TargetClusterName, @@ -427,13 +490,18 @@ func paramsServer(model *Model) *admin20231115014.DiskBackupSnapshotRestoreJob { } func paramsServerless(model *Model) *admin20231115014.ServerlessBackupRestoreJob { - return &admin20231115014.ServerlessBackupRestoreJob{ + params := &admin20231115014.ServerlessBackupRestoreJob{ SnapshotId: model.SnapshotId, DeliveryType: *model.DeliveryType, - TargetClusterName: *model.TargetClusterName, - TargetGroupId: *model.TargetProjectId, OplogTs: util.StrPtrToIntPtr(model.OpLogTs), OplogInc: util.StrPtrToIntPtr(model.OpLogInc), PointInTimeUTCSeconds: model.PointInTimeUtcSeconds, } + if model.TargetClusterName != nil { + params.TargetClusterName = *model.TargetClusterName + } + if model.TargetProjectId != nil { + params.TargetGroupId = *model.TargetProjectId + } + return params } diff --git a/cfn-resources/cloud-backup-restore-jobs/docs/README.md b/cfn-resources/cloud-backup-restore-jobs/docs/README.md index 2e3aef4f3..e019b6ceb 100644 --- a/cfn-resources/cloud-backup-restore-jobs/docs/README.md +++ b/cfn-resources/cloud-backup-restore-jobs/docs/README.md @@ -229,3 +229,15 @@ Timestamp in ISO 8601 date and time format in UTC when the snapshot associated t One or more links to sub-resources and/or related resources. +#### DesiredTimestamp + +BSON timestamp that indicates when the checkpoint token entry in the oplog occurred. + +#### PrivateDownloadDeliveryUrls + +One or more URLs that point to the compressed snapshot files for manual download via private endpoints. + +#### Components + +Information on the restore job for each replica set in the sharded cluster. + diff --git a/cfn-resources/cloud-backup-restore-jobs/docs/component.md b/cfn-resources/cloud-backup-restore-jobs/docs/component.md new file mode 100644 index 000000000..0a225e027 --- /dev/null +++ b/cfn-resources/cloud-backup-restore-jobs/docs/component.md @@ -0,0 +1,57 @@ +# MongoDB::Atlas::CloudBackUpRestoreJobs Component + +Information on the restore job for each replica set in the sharded cluster. + +## Syntax + +To declare this entity in your AWS CloudFormation template, use the following syntax: + +### JSON + +
+{
+    "DownloadUrl" : String,
+    "ReplicaSetName" : String,
+    "PrivateDownloadDeliveryUrls" : [ PrivateDownloadDeliveryUrl, ... ]
+}
+
+ +### YAML + +
+DownloadUrl: String
+ReplicaSetName: String
+PrivateDownloadDeliveryUrls: 
+      - PrivateDownloadDeliveryUrl
+
+ +## Properties + +#### DownloadUrl + +One URL that points to the compressed snapshot files for this replica set. + +_Required_: No + +_Type_: String + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + +#### ReplicaSetName + +Human-readable label that identifies the replica set. + +_Required_: No + +_Type_: String + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + +#### PrivateDownloadDeliveryUrls + +_Required_: No + +_Type_: List of PrivateDownloadDeliveryUrl + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + diff --git a/cfn-resources/cloud-backup-restore-jobs/docs/desiredtimestamp.md b/cfn-resources/cloud-backup-restore-jobs/docs/desiredtimestamp.md new file mode 100644 index 000000000..a7bed3ec4 --- /dev/null +++ b/cfn-resources/cloud-backup-restore-jobs/docs/desiredtimestamp.md @@ -0,0 +1,46 @@ +# MongoDB::Atlas::CloudBackUpRestoreJobs DesiredTimestamp + +BSON timestamp that indicates when the checkpoint token entry in the oplog occurred. + +## Syntax + +To declare this entity in your AWS CloudFormation template, use the following syntax: + +### JSON + +
+{
+    "Date" : String,
+    "Increment" : Integer
+}
+
+ +### YAML + +
+Date: String
+Increment: Integer
+
+ +## Properties + +#### Date + +Date and time when the oplog recorded this database operation. + +_Required_: No + +_Type_: String + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + +#### Increment + +Order of the database operation that the oplog recorded at specific date and time. + +_Required_: No + +_Type_: Integer + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + diff --git a/cfn-resources/cloud-backup-restore-jobs/docs/privatedownloaddeliveryurl.md b/cfn-resources/cloud-backup-restore-jobs/docs/privatedownloaddeliveryurl.md new file mode 100644 index 000000000..58a8590c2 --- /dev/null +++ b/cfn-resources/cloud-backup-restore-jobs/docs/privatedownloaddeliveryurl.md @@ -0,0 +1,46 @@ +# MongoDB::Atlas::CloudBackUpRestoreJobs PrivateDownloadDeliveryUrl + +Private endpoint delivery URL for manual download. + +## Syntax + +To declare this entity in your AWS CloudFormation template, use the following syntax: + +### JSON + +
+{
+    "DeliveryUrl" : String,
+    "EndpointId" : String
+}
+
+ +### YAML + +
+DeliveryUrl: String
+EndpointId: String
+
+ +## Properties + +#### DeliveryUrl + +One URL that points to the compressed snapshot files for manual download. + +_Required_: No + +_Type_: String + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + +#### EndpointId + +Unique identifier of the private endpoint. + +_Required_: No + +_Type_: String + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + diff --git a/cfn-resources/cloud-backup-restore-jobs/mongodb-atlas-cloudbackuprestorejobs.json b/cfn-resources/cloud-backup-restore-jobs/mongodb-atlas-cloudbackuprestorejobs.json index d7cc521ff..f25da3292 100644 --- a/cfn-resources/cloud-backup-restore-jobs/mongodb-atlas-cloudbackuprestorejobs.json +++ b/cfn-resources/cloud-backup-restore-jobs/mongodb-atlas-cloudbackuprestorejobs.json @@ -20,6 +20,59 @@ } }, "additionalProperties": false + }, + "DesiredTimestamp": { + "type": "object", + "description": "BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.", + "properties": { + "Date": { + "type": "string", + "description": "Date and time when the oplog recorded this database operation." + }, + "Increment": { + "type": "integer", + "description": "Order of the database operation that the oplog recorded at specific date and time." + } + }, + "additionalProperties": false + }, + "PrivateDownloadDeliveryUrl": { + "type": "object", + "description": "Private endpoint delivery URL for manual download.", + "properties": { + "DeliveryUrl": { + "type": "string", + "description": "One URL that points to the compressed snapshot files for manual download." + }, + "EndpointId": { + "type": "string", + "description": "Unique identifier of the private endpoint." + } + }, + "additionalProperties": false + }, + "Component": { + "type": "object", + "description": "Information on the restore job for each replica set in the sharded cluster.", + "properties": { + "DownloadUrl": { + "type": "string", + "description": "One URL that points to the compressed snapshot files for this replica set." + }, + "ReplicaSetName": { + "type": "string", + "description": "Human-readable label that identifies the replica set." + }, + "PrivateDownloadDeliveryUrls": { + "type": "array", + "description": "Private endpoint URLs for this replica set.", + "insertionOrder": false, + "items": { + "$ref": "#/definitions/PrivateDownloadDeliveryUrl" + } + } + }, + "additionalProperties": false } }, "properties": { @@ -105,6 +158,26 @@ "additionalProperties": false } }, + "DesiredTimestamp": { + "description": "BSON timestamp that indicates when the checkpoint token entry in the oplog occurred.", + "$ref": "#/definitions/DesiredTimestamp" + }, + "PrivateDownloadDeliveryUrls": { + "description": "One or more URLs that point to the compressed snapshot files for manual download via private endpoints.", + "type": "array", + "insertionOrder": false, + "items": { + "$ref": "#/definitions/PrivateDownloadDeliveryUrl" + } + }, + "Components": { + "description": "Information on the restore job for each replica set in the sharded cluster.", + "type": "array", + "insertionOrder": false, + "items": { + "$ref": "#/definitions/Component" + } + }, "OpLogTs": { "description": "Timestamp in the number of seconds that have elapsed since the UNIX epoch from which to you want to restore this snapshot. This is the first part of an Oplog timestamp.", "type": "string" @@ -162,7 +235,10 @@ "/properties/ExpiresAt", "/properties/FinishedAt", "/properties/Timestamp", - "/properties/Links" + "/properties/Links", + "/properties/DesiredTimestamp", + "/properties/PrivateDownloadDeliveryUrls", + "/properties/Components" ], "primaryIdentifier": [ "/properties/ProjectId", diff --git a/examples/cloud-backup-restore-jobs/restore.json b/examples/cloud-backup-restore-jobs/restore.json index e022f5a46..1d8dd57c6 100644 --- a/examples/cloud-backup-restore-jobs/restore.json +++ b/examples/cloud-backup-restore-jobs/restore.json @@ -44,9 +44,12 @@ "ProjectId": { "Ref": "ProjectId" }, - "ClusterName": { + "InstanceName": { "Ref": "InstanceName" }, + "InstanceType": { + "Ref": "InstanceType" + }, "Profile": { "Ref": "Profile" }, diff --git a/examples/cloud-backup-restore-jobs/restore_synchronous.json b/examples/cloud-backup-restore-jobs/restore_synchronous.json index 9370cdb18..7a7f32094 100644 --- a/examples/cloud-backup-restore-jobs/restore_synchronous.json +++ b/examples/cloud-backup-restore-jobs/restore_synchronous.json @@ -45,6 +45,9 @@ "Ref": "ProjectId" }, "InstanceName": { + "Ref": "InstanceName" + }, + "InstanceType": { "Ref": "InstanceType" }, "Profile": {