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

Adding private ip address reference to azurerm network interface #6538

Merged
merged 3 commits into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion builtin/providers/azurerm/resource_arm_network_interface_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func resourceArmNetworkInterface() *schema.Resource {
Computed: true,
},

"private_ip_address": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only using this part of the schema in the Read func. Is this not allowed to be set specifically? If not, then we can just make it Computed, and remove optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Type: schema.TypeString,
Optional: true,
Computed: true,
},

"virtual_machine_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -241,7 +247,7 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
return nil
}
if err != nil {
return fmt.Errorf("Error making Read request on Azure Netowkr Interface %s: %s", name, err)
return fmt.Errorf("Error making Read request on Azure Network Interface %s: %s", name, err)
}

iface := *resp.Properties
Expand All @@ -252,6 +258,17 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
}
}

if iface.IPConfigurations != nil && len(*iface.IPConfigurations) > 0 {
var privateIPAddress *string
for _, ipConfig := range *iface.IPConfigurations {
privateIPAddress = ipConfig.Properties.PrivateIPAddress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are ranging over a collection here and adding each private ip address in an IPConfig to the same string variable

Should the schema have private_ip_address as a List? Or can we guarantee that only 1 private IP will be in place?

Copy link
Contributor Author

@Felivel Felivel May 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment we can only specify one ip configuration.
Azure/azure-sdk-for-go#259

Maybe we can pick the primary ip configuration once we are able to multiple configurations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if there is only 1, then we shouldn't range over right now

We should do something like this:

if iface.IPConfigurations != nil && len(*iface.IPConfigurations) > 0 {
        var privateIPAddress *string
                 if iface.IPConfigurations[0] != nil {
                     privateIPAddress = iface.IPConfigurations[0].Properties.PrivateIPAddress
                 }
}

Then leave a note in place referencing that Azure SDK issue where only 1 NIC is allowed - thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I tried doing that but I was getting some errors. I will try it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hit the same problem as last time.

builtin/providers/azurerm/resource_arm_network_interface_card.go:264: 
invalid operation: iface.IPConfigurations[0] (type *[]network.InterfaceIPConfiguration does not support indexing)

Should I assign the pointer value to a variable and try like that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Felivel

The issue here is that you cannot index when a pointer is in play. So it has to be dereferrenced like this:

(*iface.IPConfigurations)[0].Properties.PrivateIPAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will push the change in a moment.

}

if *privateIPAddress != "" {
d.Set("private_ip_address", *privateIPAddress)
}
}

if iface.VirtualMachine != nil {
if *iface.VirtualMachine.ID != "" {
d.Set("virtual_machine_id", *iface.VirtualMachine.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The following attributes are exported:

* `id` - The virtual NetworkConfiguration ID.
* `mac_address` - The media access control (MAC) address of the network interface.
* `private_ip_address` - The private ip address of the network interface.
* `virtual_machine_id` - Reference to a VM with which this NIC has been associated.
* `applied_dns_servers` - If the VM that uses this NIC is part of an Availability Set, then this list will have the union of all DNS servers from all NICs that are part of the Availability Set
* `internal_fqdn` - Fully qualified DNS name supporting internal communications between VMs in the same VNet