-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wait_online: convert to resource to properly use retry
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
- Loading branch information
1 parent
cd95566
commit 8a7df0b
Showing
5 changed files
with
106 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,65 @@ | ||
package ceph | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceWaitOnline() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "This dummy resource is waiting to Ceph to be online at creation time for up to 1 hour. " + | ||
"This is useful for example on a boostrap procedure.", | ||
CreateContext: resourceWaitOnlineCreate, | ||
ReadContext: resourceWaitOnlineDummy, | ||
DeleteContext: resourceWaitOnlineDummy, | ||
Timeouts: &schema.ResourceTimeout{ | ||
Create: schema.DefaultTimeout(time.Hour), | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"cluster_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "That's a workaround to actually have an id, set this to something unique (i.e.: the cluster name).", | ||
}, | ||
|
||
"online": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "If the cluster is online, only checked at creationg time (always true)", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceWaitOnlineCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
log.Printf("[DEBUG] Ceph starting ceph_wait_online") | ||
|
||
err := resource.RetryContext(ctx, d.Timeout(schema.TimeoutRead), func() *resource.RetryError { | ||
_, err := config.GetCephConnection() | ||
if err == nil { | ||
log.Printf("[DEBUG] Ceph online on ceph_wait_online") | ||
d.SetId(d.Get("cluster_name").(string)) | ||
if err := d.Set("online", true); err != nil { | ||
return resource.NonRetryableError(fmt.Errorf("Unable to set online: %s", err)) | ||
} | ||
return nil | ||
} | ||
|
||
log.Printf("[DEBUG] Cannot connect to Ceph on ceph_wait_online: %s", err) | ||
return resource.RetryableError(err) | ||
}) | ||
|
||
return diag.FromErr(err) | ||
} | ||
|
||
func resourceWaitOnlineDummy(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
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,38 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "ceph_wait_online Resource - terraform-provider-ceph" | ||
subcategory: "" | ||
description: |- | ||
This dummy resource is waiting to Ceph to be online at creation time for up to 1 hour. This is useful for example on a boostrap procedure. | ||
--- | ||
|
||
# ceph_wait_online (Resource) | ||
|
||
This dummy resource is waiting to Ceph to be online at creation time for up to 1 hour. This is useful for example on a boostrap procedure. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `cluster_name` (String) That's a workaround to actually have an id, set this to something unique (i.e.: the cluster name). | ||
|
||
### Optional | ||
|
||
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `online` (Boolean) If the cluster is online, only checked at creationg time (always true) | ||
|
||
<a id="nestedblock--timeouts"></a> | ||
### Nested Schema for `timeouts` | ||
|
||
Optional: | ||
|
||
- `create` (String) | ||
|
||
|