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

Fixes #628 - multiple output IPs for azurerm_lb #633

Merged
merged 5 commits into from
Dec 18, 2017
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
19 changes: 16 additions & 3 deletions azurerm/resource_arm_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func resourceArmLoadBalancer() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"private_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"tags": tagsSchema(),
},
Expand Down Expand Up @@ -177,14 +184,20 @@ func resourecArmLoadBalancerRead(d *schema.ResourceData, meta interface{}) error
ipconfigs := loadBalancer.LoadBalancerPropertiesFormat.FrontendIPConfigurations
d.Set("frontend_ip_configuration", flattenLoadBalancerFrontendIpConfiguration(ipconfigs))

privateIpAddress := ""
privateIpAddresses := make([]string, 0, len(*ipconfigs))
for _, config := range *ipconfigs {
if config.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress != nil {
d.Set("private_ip_address", config.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress)
if privateIpAddress == "" {
privateIpAddress = *config.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress
}

// set the private IP address at most once
break
privateIpAddresses = append(privateIpAddresses, *config.FrontendIPConfigurationPropertiesFormat.PrivateIPAddress)
}
}

d.Set("private_ip_address", privateIpAddress)
d.Set("private_ip_addresses", privateIpAddresses)
}

flattenAndSetTags(d, loadBalancer.Tags)
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/loadbalancer.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ The following arguments are supported:
The following attributes are exported:

* `id` - The LoadBalancer ID.
* `private_ip_address` - The private IP address assigned to the load balancer, if any.
* `private_ip_address` - The first private IP address assigned to the load balancer in `frontend_ip_configuration` blocks, if any.
* `private_ip_addresses` - The list of private IP address assigned to the load balancer in `frontend_ip_configuration` blocks, if any.

## Import

Expand Down