Skip to content

Commit

Permalink
Merge pull request #401 from terraform-providers/key-vault-polling
Browse files Browse the repository at this point in the history
`azurerm_key_vault` - waiting for the DNS to propagate
  • Loading branch information
tombuildsstuff authored Oct 6, 2017
2 parents 57a61ad + 19b8e00 commit 9737dba
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions azurerm/resource_arm_key_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import (
"log"
"regexp"

"time"

"net"

"github.com/Azure/azure-sdk-for-go/arm/keyvault"
"github.com/hashicorp/go-getter/helper/url"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/satori/uuid"
Expand Down Expand Up @@ -217,6 +223,17 @@ func resourceArmKeyVaultCreate(d *schema.ResourceData, meta interface{}) error {

d.SetId(*read.ID)

if d.IsNewResource() {
if props := read.Properties; props != nil {
if vault := props.VaultURI; vault != nil {
err := resource.Retry(30*time.Second, checkKeyVaultDNSIsAvailable(*vault))
if err != nil {
return err
}
}
}
}

return resourceArmKeyVaultRead(d, meta)
}

Expand Down Expand Up @@ -383,3 +400,20 @@ func validateKeyVaultName(v interface{}, k string) (ws []string, errors []error)

return
}

func checkKeyVaultDNSIsAvailable(vaultUri string) func() *resource.RetryError {
return func() *resource.RetryError {
uri, err := url.Parse(vaultUri)
if err != nil {
return resource.NonRetryableError(err)
}

conn, err := net.Dial("tcp", fmt.Sprintf("%s:443", uri.Host))
if err != nil {
return resource.RetryableError(err)
}

_ = conn.Close()
return nil
}
}

0 comments on commit 9737dba

Please sign in to comment.