mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
provider/arukas: Increase timeout to 15mins & use standard helper (#12849)
This commit is contained in:
parent
f772212c7e
commit
17afcf2708
@ -35,7 +35,7 @@ func Provider() terraform.ResourceProvider {
|
||||
"timeout": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc(JSONTimeoutParamName, "600"),
|
||||
DefaultFunc: schema.EnvDefaultFunc(JSONTimeoutParamName, "900"),
|
||||
},
|
||||
},
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
|
@ -2,10 +2,11 @@ package arukas
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
API "github.com/arukasio/cli"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
API "github.com/arukasio/cli"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceArukasContainer() *schema.Resource {
|
||||
@ -169,11 +170,27 @@ func resourceArukasContainerCreate(d *schema.ResourceData, meta interface{}) err
|
||||
return err
|
||||
}
|
||||
|
||||
if err := sleepUntilUp(client, appSet.Container.ID, client.Timeout); err != nil {
|
||||
d.SetId(appSet.Container.ID)
|
||||
|
||||
stateConf := &resource.StateChangeConf{
|
||||
Target: []string{"running"},
|
||||
Pending: []string{"stopped", "booting"},
|
||||
Timeout: client.Timeout,
|
||||
Refresh: func() (interface{}, string, error) {
|
||||
var container API.Container
|
||||
err := client.Get(&container, fmt.Sprintf("/containers/%s", appSet.Container.ID))
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return container, container.StatusText, nil
|
||||
},
|
||||
}
|
||||
_, err := stateConf.WaitForState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.SetId(appSet.Container.ID)
|
||||
return resourceArukasContainerRead(d, meta)
|
||||
}
|
||||
|
||||
@ -270,24 +287,3 @@ func resourceArukasContainerDelete(d *schema.ResourceData, meta interface{}) err
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func sleepUntilUp(client *ArukasClient, containerID string, timeout time.Duration) error {
|
||||
current := 0 * time.Second
|
||||
interval := 5 * time.Second
|
||||
for {
|
||||
var container API.Container
|
||||
if err := client.Get(&container, fmt.Sprintf("/containers/%s", containerID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if container.IsRunning {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(interval)
|
||||
current += interval
|
||||
|
||||
if timeout > 0 && current > timeout {
|
||||
return fmt.Errorf("Timeout: sleepUntilUp")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user