Skip to content

Commit

Permalink
Merge pull request #4605 from leewilson86/DataSource/LoadbalancerBack…
Browse files Browse the repository at this point in the history
…endAddressPool/ExposeBIPConfigLbRules

d/azurerm_lb_backend_address_pool: exposed backend_ip_configurations
  • Loading branch information
tombuildsstuff authored Oct 14, 2019
2 parents e82c86b + 0b31f12 commit c01268d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
32 changes: 30 additions & 2 deletions azurerm/data_source_loadbalancer_backend_address_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource {
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"backend_ip_configurations": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand All @@ -45,12 +58,27 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met
return fmt.Errorf("Unable to retrieve Backend Address Pool %q since Load Balancer %q was not found", name, loadBalancerId)
}

config, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name)
bap, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name)
if !exists {
return fmt.Errorf("Backend Address Pool %q was not found in Load Balancer %q", name, loadBalancerId)
}

d.SetId(*config.ID)
d.SetId(*bap.ID)

backendIPConfigurations := make([]interface{}, 0)
if props := bap.BackendAddressPoolPropertiesFormat; props != nil {
if beipConfigs := props.BackendIPConfigurations; beipConfigs != nil {
for _, config := range *beipConfigs {
ipConfig := make(map[string]interface{})
if id := config.ID; id != nil {
ipConfig["id"] = *id
backendIPConfigurations = append(backendIPConfigurations, ipConfig)
}
}
}
}

d.Set("backend_ip_configurations", backendIPConfigurations)

return nil
}
14 changes: 11 additions & 3 deletions website/docs/d/loadbalancer_backend_address_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: |-

# Data Source: azurerm_lb_backend_address_pool

Use this data source to access information about an existing Load Balancer Backend Address Pool.
Use this data source to access information about an existing Load Balancer's Backend Address Pool.

## Example Usage

Expand All @@ -21,11 +21,15 @@ data "azurerm_lb" "test" {
data "azurerm_lb_backend_address_pool" "test" {
name = "first"
loadbalancer_id = "${data.azurerm_lb.test.id}"
loadbalancer_id = data.azurerm_lb.test.id
}
output "backend_address_pool_id" {
value = "${data.azurerm_lb_backend_address_pool.test.id}"
value = data.azurerm_lb_backend_address_pool.test.id
}
output "backend_ip_configuration_ids" {
value = data.azurerm_lb_backend_address_pool.beap.backend_ip_configurations.*.id
}
```

Expand All @@ -40,3 +44,7 @@ output "backend_address_pool_id" {
The following attributes are exported:

* `id` - The ID of the Backend Address Pool.

* `name` - The name of the Backend Address Pool.

* `backend_ip_configurations` - An array of references to IP addresses defined in network interfaces.

0 comments on commit c01268d

Please sign in to comment.