Skip to content

Commit

Permalink
r/key_vault: waiting for 10 successful dns locators before returnin…
Browse files Browse the repository at this point in the history
…g as created
  • Loading branch information
tombuildsstuff committed Apr 6, 2018
1 parent e2434c4 commit 847c521
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions azurerm/resource_arm_key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
uuid "github.com/satori/go.uuid"
"github.com/satori/go.uuid"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -230,9 +230,18 @@ func resourceArmKeyVaultCreate(d *schema.ResourceData, meta interface{}) error {
if d.IsNewResource() {
if props := read.Properties; props != nil {
if vault := props.VaultURI; vault != nil {
err := resource.Retry(120*time.Second, checkKeyVaultDNSIsAvailable(*vault))
if err != nil {
return err
log.Printf("[DEBUG] Waiting for Key Vault %q (Resource Group %q) to become available", name, resGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Found"},
Refresh: keyVaultRefreshFunc(*vault),
Timeout: 30 * time.Minute,
MinTimeout: 15 * time.Second,
ContinuousTargetOccurence: 10,
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Key Vault %q (Resource Group %q) to become available: %s", name, resGroup, err)
}
}
}
Expand Down Expand Up @@ -409,19 +418,21 @@ func validateKeyVaultName(v interface{}, k string) (ws []string, errors []error)
return
}

func checkKeyVaultDNSIsAvailable(vaultUri string) func() *resource.RetryError {
return func() *resource.RetryError {
func keyVaultRefreshFunc(vaultUri string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
uri, err := url.Parse(vaultUri)
if err != nil {
return resource.NonRetryableError(err)
return nil, "Failed", fmt.Errorf("Error parsing URI %q: %s", vaultUri, err)
}

conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", uri.Host))
hostAndPort := fmt.Sprintf("%s:443", uri.Host)
conn, err := net.Dial("tcp", hostAndPort)
if err != nil {
return resource.RetryableError(err)
return nil, "NotFound", fmt.Errorf("Error connecting to %q: %s", hostAndPort, err)
}

_ = conn.Close()
return nil

return nil, "Found", nil
}
}

0 comments on commit 847c521

Please sign in to comment.