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

New data source - azurerm_virtual_machine_scale_set_network_interfaces #6752

Closed
wants to merge 18 commits into from

Conversation

hbuckle
Copy link
Contributor

@hbuckle hbuckle commented May 4, 2020

Data source for scale set NICs - particularly useful to get the IP addresses of a scale set
Resolves #7333

@hbuckle
Copy link
Contributor Author

hbuckle commented May 18, 2020

@tombuildsstuff @katbyte - Anyone available to review this?

@hbuckle
Copy link
Contributor Author

hbuckle commented Jun 4, 2020

@tombuildsstuff @katbyte - Anyone available to review this?

Copy link
Contributor

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

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

Hi @hbuckle thank you so much for this new data source!

This PR looks great to me 👍 and I left some minor comments inline, could you please have a look?

BTW, could you please also modify your description to emphasize this PR could resolves #7333 ?

resGroup := d.Get("resource_group_name").(string)
vmssName := d.Get("virtual_machine_scale_set_name").(string)

resp, err := client.ListVirtualMachineScaleSetNetworkInterfaces(ctx, resGroup, vmssName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this API is a pagable request, could we switch to the ListVirtualMachineScaleSetNetworkInterfacesComplete method and use the iterator to iterate the result?


results := make([]interface{}, 0)

for _, iface := range resp.Values() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually the result may have multiple pages, therefore you should add an outer loop to iterate all of the pages.
But it would be more clear if you use the ListVirtualMachineScaleSetNetworkInterfacesComplete and iterate over the iterator.

Comment on lines 197 to 201
if iface.Name != nil {
result["name"] = *iface.Name
} else {
result["name"] = ""
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually we would write this like this:

Suggested change
if iface.Name != nil {
result["name"] = *iface.Name
} else {
result["name"] = ""
}
name := "" // var name string also works
if iface.Name != nil {
name = *iface.Name
}
// other fields
results = append(results, map[string]interface{}{
"name": name,
// other fields
})

Comment on lines 232 to 237
addresses := make([]interface{}, 0)
for _, config := range configs {
if config.InterfaceIPConfigurationPropertiesFormat != nil {
addresses = append(addresses, config.InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we please extract this into an flatten function? Which may make this more clear

Comment on lines 245 to 254
var appliedDNSServers []string
var dnsServers []string
if dnsSettings := iface.DNSSettings; dnsSettings != nil {
if s := dnsSettings.AppliedDNSServers; s != nil {
appliedDNSServers = *s
}

if s := dnsSettings.DNSServers; s != nil {
dnsServers = *s
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we have a built-in helper function utils.FlattenStringSlice(), could we please use this function instead? By doing this, these nil-checks can be removed.

Comment on lines 265 to 266
result["enable_ip_forwarding"] = *iface.EnableIPForwarding
result["enable_accelerated_networking"] = *iface.EnableAcceleratedNetworking
Copy link
Contributor

Choose a reason for hiding this comment

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

These two would also need nil-checks

Comment on lines 131 to 136
"dns_servers": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a Computed attribute, we should just use TypeList instead of TypeSet. And this would also benefit the users when they are trying to use one of the element.

Comment on lines 143 to 148
"applied_dns_servers": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar with the above, should use TypeList

Comment on lines 95 to 121
"application_gateway_backend_address_pools_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"load_balancer_backend_address_pools_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"load_balancer_inbound_nat_rules_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"application_security_group_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a Computed attribute, we should just use TypeList instead of TypeSet. And this would also benefit the users when they are trying to use one of the element.

@jackofallops jackofallops added service/vmss Virtual Machine Scale Sets new-data-source labels Jun 17, 2020
@hbuckle
Copy link
Contributor Author

hbuckle commented Jun 27, 2020

@ArcturusZhang - I think I've addressed everything

Copy link
Contributor

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

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

Hi @hbuckle thanks for the revision! LGTM aside from one extra empty line

@svyotov
Copy link

svyotov commented Jul 24, 2020

This looks like a useful/required PR 👍

@hbuckle
Copy link
Contributor Author

hbuckle commented Jul 29, 2020

It should be ready to go, @ArcturusZhang can you confirm?

@karlbohlmark
Copy link

This looks like a really valuable change that is very close to actually happening. Will it be merged or is it advisable to look for workarounds for this instead of waiting for this to be accepted?

@hbuckle
Copy link
Contributor Author

hbuckle commented Sep 16, 2020

I've resolved the merge conflict so just needs a reviewer

@hbuckle
Copy link
Contributor Author

hbuckle commented Oct 5, 2020

@ArcturusZhang @tombuildsstuff bumping this one again

@JonShelley
Copy link

Looks like this fell through the cracks. Any update on this?

@katbyte
Copy link
Collaborator

katbyte commented Feb 10, 2021

Hey @hbuckle - is there a reason for this to be specific to NICs and not a general windows/linux vmss datasource?

@hbuckle
Copy link
Contributor Author

hbuckle commented Feb 10, 2021

@katbyte I think it was following the model of azurerm_network_interface which has its own data source. It is also a separate API to get the nics so made sense as a separate data source

@katbyte
Copy link
Collaborator

katbyte commented Apr 16, 2021

@hbuckle - i'm still not sure what we gain by having this as a separate resource other then part of existing data source giving us azure_virtual_machine_scale_set.network_interfaces?

azurerm_network_interface has a direct resource counterpoint, while this just pulls the list of nics for the vmss? thus it makes sense to be part of that datasource rather then sepreate

@hbuckle
Copy link
Contributor Author

hbuckle commented Apr 19, 2021

@katbyte sure it can go as part of the existing data source. TBH I've forgotten what I even needed this for now.

@katbyte
Copy link
Collaborator

katbyte commented Apr 26, 2021

Sounds good @hbuckle - mind if i close this until you've done so and can open a new PR?

@katbyte
Copy link
Collaborator

katbyte commented Apr 26, 2021

It looks like there is a PR already open to do this! #10585 - as such i'm going to close this in favour of that pr

@katbyte katbyte closed this Apr 26, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2021
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.

azurerm_linux_virtual_machine_scale_set output private ip
7 participants