From 7a45b4c7d739abb480a2cf3be3c77e09cedd8156 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Thu, 14 Jun 2018 09:39:11 +0100 Subject: [PATCH 1/2] Moving from net.dial to http.get so environment proxy settings can be picked up --- azurerm/resource_arm_key_vault.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/azurerm/resource_arm_key_vault.go b/azurerm/resource_arm_key_vault.go index 2a30b0b92069..f5072a7411bd 100644 --- a/azurerm/resource_arm_key_vault.go +++ b/azurerm/resource_arm_key_vault.go @@ -3,12 +3,11 @@ package azurerm import ( "fmt" "log" - "net" + "net/http" "regexp" "time" "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/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" @@ -445,21 +444,22 @@ func validateKeyVaultName(v interface{}, k string) (ws []string, errors []error) func keyVaultRefreshFunc(vaultUri string) resource.StateRefreshFunc { return func() (interface{}, string, error) { log.Printf("[DEBUG] Checking to see if KeyVault %q is available..", vaultUri) - uri, err := url.Parse(vaultUri) - if err != nil { - return nil, "error", fmt.Errorf("Error parsing URI %q: %s", vaultUri, err) + + var PTransport = &http.Transport{Proxy: http.ProxyFromEnvironment} + + client := &http.Client{ + Transport: PTransport, } - hostAndPort := fmt.Sprintf("%s:443", uri.Host) - conn, err := net.Dial("tcp", hostAndPort) + conn, err := client.Get(vaultUri) if err != nil { - log.Printf("[DEBUG] Didn't find KeyVault at %q", hostAndPort) - return nil, "pending", fmt.Errorf("Error connecting to %q: %s", hostAndPort, err) + log.Printf("[DEBUG] Didn't find KeyVault at %q", vaultUri) + return nil, "pending", fmt.Errorf("Error connecting to %q: %s %s", vaultUri, err, conn) } - _ = conn.Close() + defer conn.Body.Close() - log.Printf("[DEBUG] Found KeyVault at %q", hostAndPort) + log.Printf("[DEBUG] Found KeyVault at %q", vaultUri) return "available", "available", nil } } From c7bd08cabf16b95665c755c0c5ec9369a809eb44 Mon Sep 17 00:00:00 2001 From: lstolyarov Date: Thu, 14 Jun 2018 11:00:59 +0100 Subject: [PATCH 2/2] Clean up --- azurerm/resource_arm_key_vault.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_key_vault.go b/azurerm/resource_arm_key_vault.go index f5072a7411bd..ef9e1b3a8819 100644 --- a/azurerm/resource_arm_key_vault.go +++ b/azurerm/resource_arm_key_vault.go @@ -454,7 +454,7 @@ func keyVaultRefreshFunc(vaultUri string) resource.StateRefreshFunc { conn, err := client.Get(vaultUri) if err != nil { log.Printf("[DEBUG] Didn't find KeyVault at %q", vaultUri) - return nil, "pending", fmt.Errorf("Error connecting to %q: %s %s", vaultUri, err, conn) + return nil, "pending", fmt.Errorf("Error connecting to %q: %s", vaultUri, err) } defer conn.Body.Close()