Skip to content

Commit

Permalink
Merge branch 'waiting'
Browse files Browse the repository at this point in the history
  • Loading branch information
alkar committed Jan 31, 2020
2 parents 89659b8 + 6347225 commit a6656cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions megaport/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ func compareNillableUints(a *uint64, b uint64) bool {

func waitUntilVxcIsConfigured(client *api.Client, productUid string, timeout time.Duration) error {
scc := &resource.StateChangeConf{
Pending: []string{api.ProductStatusDeployable},
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Refresh: func() (interface{}, string, error) {
v, err := client.GetVxc(productUid)
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions megaport/resource_megaport_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func resourceMegaportPortCreate(d *schema.ResourceData, m interface{}) error {
return err
}
d.SetId(*uid)
if err := waitUntilPortIsConfigured(cfg.Client, *uid, 5*time.Minute); err != nil {
return err
}
return resourceMegaportPortRead(d, m)
}

Expand All @@ -111,6 +114,9 @@ func resourceMegaportPortUpdate(d *schema.ResourceData, m interface{}) error {
}); err != nil {
return err
}
if err := waitUntilPortIsConfigured(cfg.Client, d.Id(), 5*time.Minute); err != nil {
return err
}
return resourceMegaportPortRead(d, m)
}

Expand All @@ -125,3 +131,26 @@ func resourceMegaportPortDelete(d *schema.ResourceData, m interface{}) error {
}
return nil
}

func waitUntilPortIsConfigured(client *api.Client, productUid string, timeout time.Duration) error {
scc := &resource.StateChangeConf{
Target: []string{api.ProductStatusConfigured, api.ProductStatusLive},
Refresh: func() (interface{}, string, error) {
v, err := client.GetPort(productUid)
if err != nil {
log.Printf("[ERROR] Could not retrieve Port while waiting for setup to finish: %v", err)
return nil, "", err
}
if v == nil {
return nil, "", nil
}
return v, v.ProvisioningStatus, nil
},
Timeout: timeout,
MinTimeout: 10 * time.Second,
Delay: 5 * time.Second,
}
log.Printf("[INFO] Waiting for Port (%s) to be configured", productUid)
_, err := scc.WaitForState()
return err
}

0 comments on commit a6656cc

Please sign in to comment.