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

d/azurerm_lb_backend_address_pool: exposed backend_ip_configurations #4605

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