Skip to content

Commit 8f898a1

Browse files
authored
fixes failing snapshots because timeout is too short (#583)
* fixes failing snapshots because timeout is too short * uses default timeout from Default field * improves documentation of the duration field * fixes failing tests
1 parent 9556ef0 commit 8f898a1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mongodbatlas/resource_mongodbatlas_cloud_provider_snapshot.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func resourceMongoDBAtlasCloudProviderSnapshot() *schema.Resource {
7979
Type: schema.TypeString,
8080
Computed: true,
8181
},
82+
"timeout": {
83+
Type: schema.TypeString,
84+
Optional: true,
85+
ForceNew: true,
86+
Default: "10m",
87+
},
8288
},
8389
DeprecationMessage: "this resource is deprecated, please transition as soon as possible to mongodbatlas_cloud_backup_snapshot",
8490
}
@@ -158,17 +164,24 @@ func resourceMongoDBAtlasCloudProviderSnapshotCreate(ctx context.Context, d *sch
158164
RetentionInDays: d.Get("retention_in_days").(int),
159165
}
160166

167+
var timeout time.Duration
168+
169+
timeout, err := time.ParseDuration(d.Get("timeout").(string))
170+
if err != nil {
171+
return diag.FromErr(err)
172+
}
173+
161174
stateConf := &resource.StateChangeConf{
162175
Pending: []string{"CREATING", "UPDATING", "REPAIRING", "REPEATING"},
163176
Target: []string{"IDLE"},
164177
Refresh: resourceClusterRefreshFunc(ctx, d.Get("cluster_name").(string), d.Get("project_id").(string), conn),
165-
Timeout: 10 * time.Minute,
178+
Timeout: timeout,
166179
MinTimeout: 10 * time.Second,
167180
Delay: 3 * time.Minute,
168181
}
169182

170183
// Wait, catching any errors
171-
_, err := stateConf.WaitForStateContext(ctx)
184+
_, err = stateConf.WaitForStateContext(ctx)
172185
if err != nil {
173186
return diag.FromErr(err)
174187
}

website/docs/r/cloud_provider_snapshot.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ On-demand snapshots happen immediately, unlike scheduled snapshots which occur a
3535
cluster_name = mongodbatlas_cluster.my_cluster.name
3636
description = "myDescription"
3737
retention_in_days = 1
38+
timeout = "10m"
3839
}
3940
4041
resource "mongodbatlas_cloud_provider_snapshot_restore_job" "test" {
@@ -53,6 +54,7 @@ On-demand snapshots happen immediately, unlike scheduled snapshots which occur a
5354
* `cluster_name` - (Required) The name of the Atlas cluster that contains the snapshots you want to retrieve.
5455
* `description` - (Required) Description of the on-demand snapshot.
5556
* `retention_in_days` - (Required) The number of days that Atlas should retain the on-demand snapshot. Must be at least 1.
57+
* `timeout`- (Optional) The duration of time to wait to finish the on-demand snapshot. The timeout value is definded by a signed sequence of decimal numbers with an time unit suffix such as: `1h45m`, `300s`, `10m`, .... The valid time units are: `ns`, `us` (or `µs`), `ms`, `s`, `m`, `h`. Default value for the timeout is `10m`
5658

5759
## Attributes Reference
5860

0 commit comments

Comments
 (0)