From 5ff6598e6564432c8ddf0e5d9e29a81431171fe9 Mon Sep 17 00:00:00 2001 From: aznashwan Date: Tue, 30 Jun 2015 02:12:12 +0300 Subject: [PATCH] Fixed void Azure network config bug. --- builtin/providers/azure/resource_azure_dns_server.go | 8 +++++++- builtin/providers/azure/resource_azure_local_network.go | 8 +++++++- builtin/providers/azure/resource_azure_virtual_network.go | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/builtin/providers/azure/resource_azure_dns_server.go b/builtin/providers/azure/resource_azure_dns_server.go index 0f9db9eec..dd4e380dc 100644 --- a/builtin/providers/azure/resource_azure_dns_server.go +++ b/builtin/providers/azure/resource_azure_dns_server.go @@ -4,6 +4,7 @@ import ( "fmt" "log" + "github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management/virtualnetwork" "github.com/hashicorp/terraform/helper/schema" ) @@ -46,7 +47,12 @@ func resourceAzureDnsServerCreate(d *schema.ResourceData, meta interface{}) erro defer azureClient.mutex.Unlock() netConf, err := vnetClient.GetVirtualNetworkConfiguration() if err != nil { - return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) + if management.IsResourceNotFoundError(err) { + // if no network configuration exists yet; create one now: + netConf = virtualnetwork.NetworkConfiguration{} + } else { + return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) + } } log.Println("[DEBUG] Adding new DNS server definition to Azure.") diff --git a/builtin/providers/azure/resource_azure_local_network.go b/builtin/providers/azure/resource_azure_local_network.go index c0cc74d61..5c2f4f3d8 100644 --- a/builtin/providers/azure/resource_azure_local_network.go +++ b/builtin/providers/azure/resource_azure_local_network.go @@ -4,6 +4,7 @@ import ( "fmt" "log" + "github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management/virtualnetwork" "github.com/hashicorp/terraform/helper/schema" ) @@ -54,7 +55,12 @@ func resourceAzureLocalNetworkConnectionCreate(d *schema.ResourceData, meta inte defer azureClient.mutex.Unlock() netConf, err := vnetClient.GetVirtualNetworkConfiguration() if err != nil { - return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) + if management.IsResourceNotFoundError(err) { + // if no network config exists yet; create a new one now: + netConf = virtualnetwork.NetworkConfiguration{} + } else { + return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) + } } // get provided configuration: diff --git a/builtin/providers/azure/resource_azure_virtual_network.go b/builtin/providers/azure/resource_azure_virtual_network.go index cc195e742..dcb008f07 100644 --- a/builtin/providers/azure/resource_azure_virtual_network.go +++ b/builtin/providers/azure/resource_azure_virtual_network.go @@ -3,7 +3,6 @@ package azure import ( "fmt" "log" - "strings" "github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management/virtualnetwork" @@ -88,7 +87,8 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) nc, err := vnetClient.GetVirtualNetworkConfiguration() if err != nil { - if strings.Contains(err.Error(), "ResourceNotFound") { + if management.IsResourceNotFoundError(err) { + // if no network config exists yet; create a new one now: nc = virtualnetwork.NetworkConfiguration{} } else { return fmt.Errorf(virtualNetworkRetrievalError, err)