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

Add support for azurerm_virtual_machine #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SFAntti
Copy link

@SFAntti SFAntti commented Mar 25, 2018

An azurerm_network_interface must be defined and associated with
the VM. Only supports loading private IP addresses. If the nic
has multiple IP addresses defined, it will use the first one
(read from private_ip_address). This is the primary IP address
according to the Azure documentation.

If there are multiple nics defined for the VM, the nic declared
as the primary nic (via primary_network_interface_id) will be used.

An azurerm_network_interface must be defined and associated with
the VM. Only supports loading private IP addresses. If the nic
has multiple IP addresses defined, it will use the first one
(read from private_ip_address). This is the primary IP address
according to documentation.

If there are multiple nics defined for the VM, the nic declared
as the primary nic (via primary_network_interface_id) will be used.
Copy link
Owner

@adammck adammck left a comment

Choose a reason for hiding this comment

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

Thanks very much for adding this! I imagine we'll be seeing more and more of these types of NICs-as-resources things in future. A few requests below. Most importantly, could you add a test-case to the exampleStateFile in parser_test.go?

@@ -163,6 +193,13 @@ func (r Resource) NameWithCounter() string {

// Address returns the IP address of this resource.
func (r Resource) Address() string {

switch r.resourceType {
case azureNicResourceKey, azureVMResourceKey:
Copy link
Owner

Choose a reason for hiding this comment

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

  • Pretty weird to be using a switch for this; there's only a single case.
  • This part should go below the TF_KEY_NAME check, otherwise Azure resources won't be able to use that feature. Put it inside the else, or refactor the method if you'd like.
  • Since AzureAddress() returns an empty string for non-azure resources, we could just always call it and return early if it returns a non-empty string.

@@ -177,3 +214,30 @@ func (r Resource) Address() string {

return ""
}

func (r Resource) AzureAddress() string {
Copy link
Owner

Choose a reason for hiding this comment

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

Please add a docstring to this method.

@@ -146,6 +167,15 @@ func (r Resource) Tags() map[string]string {
t[kk] = vv
}
}
case "azurerm_virtual_machine":
Copy link
Owner

Choose a reason for hiding this comment

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

Should we be using azureVMResourceKey here?

// Everytime we encounter an azurerm_network_interface we will store the IP address
// in this map with the NIC id as the key. Then when we are looking for the VM address
// we'll check if the VM's (primary) NIC exists in the map.
var azureNICPrimaryIps map[string]string
Copy link
Owner

Choose a reason for hiding this comment

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

I really don't like this global mutable map of things. Could we eliminate by either doing the lookup lazily (i.e. re-scanning the entire struct when looking up IPs for Azure VMs), or make it a member of some other object (probably state)?

@zlatan010
Copy link

Hello,
Great work guys !
Is there any thing I could do to help validating this Pull request ?

@ComaToastUK
Copy link

@adammck Any chance this will get closed off? I don't mind getting involved and making any changes to the PR if that will help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants