-
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.
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
- Loading branch information
1 parent
452be9c
commit fe8157f
Showing
3 changed files
with
68 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ceph | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const ( | ||
maxDuration = time.Hour | ||
sleepDuration = time.Minute | ||
) | ||
|
||
func dataSourceWaitOnline() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "This dummy resource is waiting to Ceph to be online for up to 1 hour. " + | ||
"This is useful for example on a boostrap procedure.", | ||
ReadContext: dataSourceWaitOnlineRead, | ||
Schema: map[string]*schema.Schema{}, | ||
} | ||
} | ||
|
||
func dataSourceWaitOnlineRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
startTime := time.Now() | ||
|
||
for time.Since(startTime) < maxDuration { | ||
_, err := config.GetCephConnection() | ||
log.Printf("[DEBUG] Cannot connect to Ceph on ceph_wait_online: %s", err) | ||
if err == nil { | ||
log.Printf("[DEBUG] Ceph online on ceph_wait_online") | ||
return nil | ||
} | ||
time.Sleep(sleepDuration) | ||
} | ||
|
||
return diag.Errorf("Error time out after trying to connect to Ceph many times") | ||
} |
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,22 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "ceph_wait_online Data Source - terraform-provider-ceph" | ||
subcategory: "" | ||
description: |- | ||
This dummy resource is waiting to Ceph to be online for up to 1 hour. This is useful for example on a boostrap procedure. | ||
--- | ||
|
||
# ceph_wait_online (Data Source) | ||
|
||
This dummy resource is waiting to Ceph to be online for up to 1 hour. This is useful for example on a boostrap procedure. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
|