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

Conversation

Felivel
Copy link
Contributor

@Felivel Felivel commented May 8, 2016

  • Adding private ip address reference
  • Updating the docs.

@Felivel
Copy link
Contributor Author

Felivel commented May 8, 2016

I am working on creating the test for this PR.

@stack72 stack72 changed the title Adding private ip address reference to azurerm network interface [WIP] Adding private ip address reference to azurerm network interface May 8, 2016
@stack72
Copy link
Contributor

stack72 commented May 9, 2016

Hi @Felivel

Please let me know when you are happy for this to go on review. We hope to release 0.6.16 tomorrow (Monday) and this would be a nice addition to it :)

Paul

* adding private ip address reference
* Updating the docs.
@Felivel
Copy link
Contributor Author

Felivel commented May 9, 2016

Hello @stack72, Please review my change.

I have added an extra attribute called private_ip_address to the root of the azurerm_network_interface schema, in order to be able to access the private ip directly from the terraform configuration.
E.g.: ${azurerm_network_interface.test.private_ip_address}"

Is there way to access an attribute of an attribute? or are we limited to TYPE.NAME.ATTRIBUTE?

Thanks.

@Felivel Felivel changed the title [WIP] Adding private ip address reference to azurerm network interface Adding private ip address reference to azurerm network interface May 9, 2016
@Felivel
Copy link
Contributor Author

Felivel commented May 9, 2016

I have done testing with a private build and have integrated the changes to my workflows. Everything seems to be working fine.

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.

@stack72
Copy link
Contributor

stack72 commented May 9, 2016

Hi @Felivel

I have a few questions inline. Once answered, we should be able to merge this.

P.

@@ -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.

Removing optional attribute from private_ip_address, this element is only being used in the read.
@stack72
Copy link
Contributor

stack72 commented May 9, 2016

Hi @Felivel

this looks great :)

At the end of a Terraform run, I can now get the following:

output "private_ip" {
    value = "${azurerm_network_interface.test.private_ip_address}"
}

Outputs:

  private_ip = 10.0.2.4

@stack72 stack72 merged commit 156d291 into hashicorp:master May 9, 2016
cristicalin pushed a commit to cristicalin/terraform that referenced this pull request May 24, 2016
…hicorp#6538)

* Adding private ip address reference

* adding private ip address reference
* Updating the docs.

* Removing optional attrib from private_ip_address

Removing optional attribute from private_ip_address, this element is only being used in the read.

* Selecting the first element instead of using a loop for now.
Change this to a loop when Azure/azure-sdk-for-go#259 is fixed
@ghost
Copy link

ghost commented Apr 26, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants