Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIC: setting internal_fqdn and some other missing props regardless of if they're empty #977

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 22 additions & 26 deletions azurerm/resource_arm_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,11 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error making Read request on Azure Network Interface %q (Resource Group %q): %+v", name, resGroup, err)
}

iface := *resp.InterfacePropertiesFormat
props := *resp.InterfacePropertiesFormat

if iface.MacAddress != nil {
if *iface.MacAddress != "" {
d.Set("mac_address", iface.MacAddress)
}
}

if iface.IPConfigurations != nil && len(*iface.IPConfigurations) > 0 {
configs := *iface.IPConfigurations
d.Set("mac_address", props.MacAddress)
if props.IPConfigurations != nil && len(*props.IPConfigurations) > 0 {
configs := *props.IPConfigurations

if configs[0].InterfaceIPConfigurationPropertiesFormat != nil {
privateIPAddress := configs[0].InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress
Expand All @@ -336,48 +331,49 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
}
}

if iface.IPConfigurations != nil {
configs := flattenNetworkInterfaceIPConfigurations(iface.IPConfigurations)
if props.IPConfigurations != nil {
configs := flattenNetworkInterfaceIPConfigurations(props.IPConfigurations)
if err := d.Set("ip_configuration", configs); err != nil {
return fmt.Errorf("Error setting `ip_configuration`: %+v", err)
}
}

if iface.VirtualMachine != nil {
d.Set("virtual_machine_id", *iface.VirtualMachine.ID)
if vm := props.VirtualMachine; vm != nil {
d.Set("virtual_machine_id", *vm.ID)
}

var appliedDNSServers []string
var dnsServers []string
if iface.DNSSettings != nil {
if iface.DNSSettings.AppliedDNSServers != nil && len(*iface.DNSSettings.AppliedDNSServers) > 0 {
for _, applied := range *iface.DNSSettings.AppliedDNSServers {
if dns := props.DNSSettings; dns != nil {
if appliedServers := dns.AppliedDNSServers; appliedServers != nil && len(appliedDNSServers) > 0 {
for _, applied := range appliedDNSServers {
appliedDNSServers = append(appliedDNSServers, applied)
}
}

if iface.DNSSettings.DNSServers != nil && len(*iface.DNSSettings.DNSServers) > 0 {
for _, dns := range *iface.DNSSettings.DNSServers {
if servers := dns.DNSServers; servers != nil && len(*servers) > 0 {
for _, dns := range *servers {
dnsServers = append(dnsServers, dns)
}
}

if iface.DNSSettings.InternalFqdn != nil && *iface.DNSSettings.InternalFqdn != "" {
d.Set("internal_fqdn", iface.DNSSettings.InternalFqdn)
}

d.Set("internal_dns_name_label", iface.DNSSettings.InternalDNSNameLabel)
d.Set("internal_fqdn", props.DNSSettings.InternalFqdn)
d.Set("internal_dns_name_label", props.DNSSettings.InternalDNSNameLabel)
}

if iface.NetworkSecurityGroup != nil {
d.Set("network_security_group_id", resp.NetworkSecurityGroup.ID)
if nsg := props.NetworkSecurityGroup; nsg != nil {
d.Set("network_security_group_id", nsg.ID)
} else {
d.Set("network_security_group_id", "")
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("location", azureRMNormalizeLocation(*resp.Location))

if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

d.Set("applied_dns_servers", appliedDNSServers)
d.Set("dns_servers", dnsServers)
d.Set("enable_ip_forwarding", resp.EnableIPForwarding)
Expand Down
55 changes: 55 additions & 0 deletions azurerm/resource_arm_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,25 @@ func TestAccAzureRMNetworkInterface_applicationSecurityGroups(t *testing.T) {
})
}

func TestAccAzureRMNetworkInterface_internalFQDN(t *testing.T) {
resourceName := "azurerm_network_interface.test"
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMNetworkInterface_internalFQDN(rInt, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMNetworkInterfaceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "internal_fqdn", fmt.Sprintf("acctestnic-%d.example.com", rInt)),
),
},
},
})
}

func testCheckAzureRMNetworkInterfaceExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -1073,3 +1092,39 @@ resource "azurerm_network_interface" "test" {
}
`, rInt, location, rInt, rInt, rInt)
}

func testAccAzureRMNetworkInterface_internalFQDN(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctest-rg-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}

resource "azurerm_network_interface" "test" {
name = "acctestnic-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
internal_fqdn = "acctestnic-%d.example.com"

ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
`, rInt, location, rInt, rInt, rInt)
}