From 7ddc7211cacfef1895afd1f408f9a863f978faa0 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Mon, 31 Oct 2016 17:03:12 +0000 Subject: [PATCH] provider/azurerm: Guard against panic when importing arm_virtual_network (#9739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #9410 When importing an azurerm_virtual_network that has no DNSServers, terraform was throwing a panic as it was trying to dereference that list of servers to set to state This commit adds a simple check to make sure there are DNSServers before dereferencing them ``` make testacc TEST=./builtin/providers/azurerm TESTARGS='-run=TestAccAzureRMVirtualNetwork_' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/10/31 11:20:36 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMVirtualNetwork_ -timeout 120m === RUN TestAccAzureRMVirtualNetwork_importBasic --- PASS: TestAccAzureRMVirtualNetwork_importBasic (150.63s) === RUN TestAccAzureRMVirtualNetwork_basic --- PASS: TestAccAzureRMVirtualNetwork_basic (122.90s) === RUN TestAccAzureRMVirtualNetwork_disappears --- PASS: TestAccAzureRMVirtualNetwork_disappears (113.07s) === RUN TestAccAzureRMVirtualNetwork_withTags --- PASS: TestAccAzureRMVirtualNetwork_withTags (139.56s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm526.168 ``` --- .../providers/azurerm/resource_arm_virtual_network.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_virtual_network.go b/builtin/providers/azurerm/resource_arm_virtual_network.go index f2a36484a..25a02d999 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_network.go +++ b/builtin/providers/azurerm/resource_arm_virtual_network.go @@ -165,11 +165,13 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err } d.Set("subnet", subnets) - dnses := []string{} - for _, dns := range *vnet.DhcpOptions.DNSServers { - dnses = append(dnses, dns) + if vnet.DhcpOptions != nil && vnet.DhcpOptions.DNSServers != nil { + dnses := []string{} + for _, dns := range *vnet.DhcpOptions.DNSServers { + dnses = append(dnses, dns) + } + d.Set("dns_servers", dnses) } - d.Set("dns_servers", dnses) flattenAndSetTags(d, resp.Tags)