DimensionDataResearch / terraform-provider-ddcloud

Terraform provider for Dimension Data cloud compute.
MIT License
16 stars 13 forks source link

Handle RESOURCE_BUSY responses from CloudControl API #11

Closed tintoy closed 7 years ago

tintoy commented 8 years ago

Sometimes CloudControl will indicate a transient problem due to resource contention by returning RESOURCE_BUSY. If that happens we should be able to retry operations.

For example, deploying a VLAN while another VLAN is being deployed for the same organisation will result in RESOURCE_BUSY. The provider should be able to retry the operation until it succeeds or times out.

Let's do something like:

var apiClient *compute.Client

var result string
err := retry.Action("Deploy VLAN", 3 * time.Minute, func(context retry.Context) {
  var e error
  result, e := apiClient.DeployVLAN(name, description, baseAddress, prefixSize)
  if e != nil {
    context.Fail(e)

    return
  }

  if isBusy(result) {
    context.Retry()
  }
}

if err != nil {
  return "", err
}

return result, nil
tintoy commented 7 years ago

Have given this a quick test-drive, @mingsheng36, and it looks promising :)