Skip to content

Commit

Permalink
F #467: configurable service timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh authored and frousselet committed Aug 28, 2023
1 parent b8be2ce commit 1c7b694
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.3.0 (Unreleased)
# 1.3.1 (Unreleased)

BUG FIXES:

Expand All @@ -7,6 +7,7 @@ BUG FIXES:
ENHANCEMENTS:

* provider: `insecure` attribute now also skips TLS verification for the flow client (#482)
* opennebula_service: allows timeout to be user configurable (#467)

# 1.3.0 (July 28th, 2023)

Expand Down
19 changes: 15 additions & 4 deletions opennebula/resource_opennebula_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ import (
"github.com/OpenNebula/one/src/oca/go/src/goca/schemas/service"
)

var (
defaultServiceTimeoutMin = 20
defaultServiceTimeout = time.Duration(defaultVMTimeoutMin) * time.Minute
)

func resourceOpennebulaService() *schema.Resource {
return &schema.Resource{
CreateContext: resourceOpennebulaServiceCreate,
ReadContext: resourceOpennebulaServiceRead,
Exists: resourceOpennebulaServiceExists,
UpdateContext: resourceOpennebulaServiceUpdate,
DeleteContext: resourceOpennebulaServiceDelete,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(defaultServiceTimeout),
Delete: schema.DefaultTimeout(defaultServiceTimeout),
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -235,7 +244,8 @@ func resourceOpennebulaServiceCreate(ctx context.Context, d *schema.ResourceData
}
}

_, err = waitForServiceState(ctx, d, meta, "running")
timeout := d.Timeout(schema.TimeoutCreate)
_, err = waitForServiceState(ctx, d, meta, "running", timeout)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down Expand Up @@ -375,7 +385,8 @@ func resourceOpennebulaServiceDelete(ctx context.Context, d *schema.ResourceData

}

_, err = waitForServiceState(ctx, d, meta, "done")
timeout := d.Timeout(schema.TimeoutDelete)
_, err = waitForServiceState(ctx, d, meta, "done", timeout)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down Expand Up @@ -648,7 +659,7 @@ func changeServiceName(d *schema.ResourceData, meta interface{}, sc *goca.Servic
return nil
}

func waitForServiceState(ctx context.Context, d *schema.ResourceData, meta interface{}, state string) (interface{}, error) {
func waitForServiceState(ctx context.Context, d *schema.ResourceData, meta interface{}, state string, timeout time.Duration) (interface{}, error) {
var service *service.Service
var err error

Expand Down Expand Up @@ -709,7 +720,7 @@ func waitForServiceState(ctx context.Context, d *schema.ResourceData, meta inter
return service, "anythingelse", nil
}
},
Timeout: 3 * time.Minute,
Timeout: timeout,
Delay: 10 * time.Second,
MinTimeout: 3 * time.Second,
}
Expand Down

0 comments on commit 1c7b694

Please sign in to comment.