-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTMDB-546: [Terraform] Feature Add: Shared-Tier Restore Job (#1324)
- Loading branch information
1 parent
6f52189
commit 7f06cac
Showing
6 changed files
with
362 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -79,7 +79,6 @@ linters-settings: | |
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
- deadcode | ||
- depguard | ||
- dogsled | ||
|
127 changes: 127 additions & 0 deletions
127
mongodbatlas/data_source_mongodbatlas_cloud_shared_tier_restore_job.go
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,127 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// This datasource does not have a resource: we tested it manually | ||
func dataSourceMongoDBAtlasCloudSharedTierRestoreJob() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasCloudSharedTierRestoreJobsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"cluster_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"job_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"target_project_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"target_deployment_item_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_finished_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"restore_scheduled_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"restore_finished_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"delivery_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"expiration_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasCloudSharedTierRestoreJobsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*MongoDBClient).AtlasV2 | ||
|
||
jobID := d.Get("job_id").(string) | ||
projectID := d.Get("project_id").(string) | ||
clusterName := d.Get("cluster_name").(string) | ||
|
||
job, _, err := conn.SharedTierRestoreJobsApi.GetSharedClusterBackupRestoreJob(ctx, clusterName, projectID, jobID).Execute() | ||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error getting shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("status", job.Status); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `status` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("target_project_id", job.TargetProjectId); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `target_project_id` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("target_deployment_item_name", job.TargetDeploymentItemName); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `target_deployment_item_name` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("snapshot_url", job.SnapshotUrl); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `snapshot_url` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("snapshot_id", job.SnapshotId); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `snapshot_id` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("snapshot_finished_date", job.GetSnapshotFinishedDate().String()); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `snapshot_finished_date` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("restore_scheduled_date", job.GetRestoreScheduledDate().String()); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `restore_scheduled_date` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("restore_finished_date", job.GetRestoreFinishedDate().String()); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `restore_finished_date` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("delivery_type", job.DeliveryType); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `delivery_type` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
if err = d.Set("expiration_date", job.GetExpirationDate().String()); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `expiration_date` for shared tier restore job '%s': %w", jobID, err)) | ||
} | ||
|
||
d.SetId(*job.Id) | ||
|
||
return nil | ||
} |
133 changes: 133 additions & 0 deletions
133
mongodbatlas/data_source_mongodbatlas_cloud_shared_tier_restore_jobs.go
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,133 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
atlasSDK "go.mongodb.org/atlas-sdk/v20230201002/admin" | ||
) | ||
|
||
// This datasource does not have a resource: we tested it manually | ||
func dataSourceMongoDBAtlasCloudSharedTierRestoreJobs() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead, | ||
Schema: map[string]*schema.Schema{ | ||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"cluster_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"results": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"job_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"target_project_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"target_deployment_item_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_finished_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"restore_scheduled_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"restore_finished_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"delivery_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"expiration_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"total_count": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*MongoDBClient).AtlasV2 | ||
|
||
projectID := d.Get("project_id").(string) | ||
clusterName := d.Get("cluster_name").(string) | ||
|
||
jobs, _, err := conn.SharedTierRestoreJobsApi.ListSharedClusterBackupRestoreJobs(ctx, clusterName, projectID).Execute() | ||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error getting shared tier restore jobs for cluster '%s': %w", clusterName, err)) | ||
} | ||
|
||
if err := d.Set("results", flattenShardTierRestoreJobs(jobs.Results)); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) | ||
} | ||
|
||
if err := d.Set("total_count", jobs.TotalCount); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting `total_count`: %w", err)) | ||
} | ||
|
||
d.SetId(id.UniqueId()) | ||
return nil | ||
} | ||
|
||
func flattenShardTierRestoreJobs(sharedTierJobs []atlasSDK.TenantRestore) []map[string]interface{} { | ||
if len(sharedTierJobs) == 0 { | ||
return nil | ||
} | ||
|
||
results := make([]map[string]interface{}, len(sharedTierJobs)) | ||
for i := range sharedTierJobs { | ||
sharedTierJob := &sharedTierJobs[i] | ||
results[i] = map[string]interface{}{ | ||
"job_id": sharedTierJob.Id, | ||
"status": sharedTierJob.Status, | ||
"target_project_id": sharedTierJob.TargetProjectId, | ||
"target_deployment_item_name": sharedTierJob.TargetDeploymentItemName, | ||
"snapshot_url": sharedTierJob.SnapshotUrl, | ||
"snapshot_id": sharedTierJob.SnapshotId, | ||
"delivery_type": sharedTierJob.DeliveryType, | ||
"snapshot_finished_date": sharedTierJob.GetSnapshotFinishedDate().String(), | ||
"restore_scheduled_date": sharedTierJob.GetRestoreScheduledDate().String(), | ||
"restore_finished_date": sharedTierJob.GetRestoreFinishedDate().String(), | ||
"expiration_date": sharedTierJob.GetExpirationDate().String(), | ||
} | ||
} | ||
|
||
return results | ||
} |
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
47 changes: 47 additions & 0 deletions
47
website/docs/d/cloud_provider_shared_tier_restore_job.html.markdown
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,47 @@ | ||
--- | ||
layout: "mongodbatlas" | ||
page_title: "MongoDB Atlas: mongodbatlas_shared_tier_restore_job" | ||
sidebar_current: "docs-mongodbatlas-datasource-mongodbatlas-shared-tier-restore-jobs" | ||
description: |- | ||
Provides a Cloud Backup Shared Tier Snapshot Restore Job Datasource. | ||
--- | ||
|
||
|
||
# Data Source: mongodbatlas_shared_tier_restore_job | ||
|
||
`mongodbatlas_shared_tier_restore_job` provides a Cloud Backup Snapshot Restore Job data source for Shared Tier Clusters. Gets the cloud backup snapshot restore jobs for the specified shared tier cluster. | ||
|
||
-> **NOTE:** Groups and projects are synonymous terms. You may find `groupId` in the official documentation. | ||
-> **NOTE:** This data source is only for Shared Tier Clusters (M2 and M5). See [here](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/) for more details on Shared Tier Cluster Limitations. | ||
|
||
## Example Usage | ||
```terraform | ||
data "mongodbatlas_shared_tier_restore_job" "test" { | ||
project_id = "5d0f1f73cf09a29120e173cf" | ||
cluster_name = "MyClusterTest" | ||
job_id = "5d1285acd5ec13b6c2d1726a" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `project_id` - (Required) The unique identifier of the project for the Atlas cluster. | ||
* `cluster_name` - (Required) Unique 24-hexadecimal digit string that identifies your project. | ||
* `job_id` - (Required) Unique 24-hexadecimal digit string that identifies the restore job to return. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `status` - Indicates whether the restore job was canceled. | ||
* `target_project_id` - UTC ISO 8601 formatted point in time when Atlas created the restore job. | ||
* `target_deployment_item_name` - Type of restore job to create. Possible values are: automated and download. | ||
* `snapshot_url` - Internet address from which you can download the compressed snapshot files. The resource returns this parameter when `deliveryType: DOWNLOAD`. | ||
* `snapshot_id` - Unique 24-hexadecimal digit string that identifies the snapshot to restore. | ||
* `snapshot_finished_date` - Date and time when MongoDB Cloud completed writing this snapshot. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `restore_scheduled_date` - Date and time when MongoDB Cloud will restore this snapshot. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `restore_finished_date` - Date and time when MongoDB Cloud completed writing this snapshot. MongoDB Cloud changes the status of the restore job to `CLOSED`. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `delivery_type` - Means by which this resource returns the snapshot to the requesting MongoDB Cloud user. Values: `RESTORE`, `DOWNLOAD`. | ||
* `expiration_date` - Date and time when the download link no longer works. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
|
||
For more information see: [MongoDB Atlas API Reference.](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Shared-Tier-Restore-Jobs/operation/getSharedClusterBackupRestoreJob) |
53 changes: 53 additions & 0 deletions
53
website/docs/d/cloud_provider_shared_tier_restore_jobs.html.markdown
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,53 @@ | ||
--- | ||
layout: "mongodbatlas" | ||
page_title: "MongoDB Atlas: mongodbatlas_shared_tier_restore_job" | ||
sidebar_current: "docs-mongodbatlas-datasource-mongodbatlas-shared-tier-restore-job" | ||
description: |- | ||
Provides a Cloud Backup Shared Tier Snapshot Restore Jobs Datasource. | ||
--- | ||
|
||
# Data Source: mongodbatlas_shared_tier_restore_jobs | ||
|
||
`mongodbatlas_shared_tier_restore_jobs` provides Cloud Backup Snapshot Restore Jobs data source for Shared Tier Clusters. Gets all the cloud backup snapshot restore jobs for the specified shared tier cluster. | ||
|
||
-> **NOTE:** Groups and projects are synonymous terms. You may find `groupId` in the official documentation. | ||
-> **NOTE:** This data source is only for Shared Tier Clusters (M2 and M5). See [here](https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/) for more details on Shared Tier Cluster Limitations. | ||
|
||
## Example Usage | ||
```terraform | ||
data "mongodbatlas_shared_tier_restore_jobs" "test" { | ||
project_id = "5d0f1f73cf09a29120e173cf" | ||
cluster_name = "MyClusterTest" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `project_id` - (Required) The unique identifier of the project for the Atlas cluster. | ||
* `cluster_name` - (Required) Unique 24-hexadecimal digit string that identifies your project. | ||
|
||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `results` - Includes shared tier snapshot restore job for each item detailed in the results array section. | ||
* `totalCount` - Count of the total number of items in the result set. It may be greater than the number of objects in the results array if the entire result set is paginated. | ||
|
||
### Shared Tier Snapshot Restore Job | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `job_id` - (Required) Unique 24-hexadecimal digit string that identifies the restore job to return. | ||
* `status` - Indicates whether the restore job was canceled. | ||
* `target_project_id` - UTC ISO 8601 formatted point in time when Atlas created the restore job. | ||
* `target_deployment_item_name` - Type of restore job to create. Possible values are: automated and download. | ||
* `snapshot_url` - Internet address from which you can download the compressed snapshot files. The resource returns this parameter when `deliveryType: DOWNLOAD`. | ||
* `snapshot_id` - Unique 24-hexadecimal digit string that identifies the snapshot to restore. | ||
* `snapshot_finished_date` - Date and time when MongoDB Cloud completed writing this snapshot. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `restore_scheduled_date` - Date and time when MongoDB Cloud will restore this snapshot. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `restore_finished_date` - Date and time when MongoDB Cloud completed writing this snapshot. MongoDB Cloud changes the status of the restore job to `CLOSED`. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
* `delivery_type` - Means by which this resource returns the snapshot to the requesting MongoDB Cloud user. Values: `RESTORE`, `DOWNLOAD`. | ||
* `expiration_date` - Date and time when the download link no longer works. This parameter expresses its value in the ISO 8601 timestamp format in UTC. | ||
|
||
For more information see: [MongoDB Atlas API Reference.](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Shared-Tier-Restore-Jobs/operation/getSharedClusterBackupRestoreJob) |