From 8e63462f9bd595b5f89ab80f6e1e7a3fcd32d57b Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Fri, 11 Oct 2019 13:59:38 +0100 Subject: [PATCH 1/7] Data Source: azurerm_lb_backend_address_pool - exposed backend_ip_configurations and load_balancing_rules --- ...ource_loadbalancer_backend_address_pool.go | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index bc4ab6382f8a..ccecae1d3e98 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -5,8 +5,8 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { @@ -21,14 +21,36 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.NoZeroValues, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, }, "loadbalancer_id": { Type: schema.TypeString, Required: true, + ForceNew: true, ValidateFunc: azure.ValidateResourceID, }, + + "backend_ip_configurations": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validate.NoEmptyStrings, + }, + Set: schema.HashString, + }, + + "load_balancing_rules": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validate.NoEmptyStrings, + }, + Set: schema.HashString, + }, }, } } @@ -45,12 +67,32 @@ 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) + + var backendIpConfigurations []string + var loadBalancingRules []string + + if props := bap.BackendAddressPoolPropertiesFormat; props != nil { + if configs := props.BackendIPConfigurations; configs != nil { + for _, backendConfig := range *configs { + backendIpConfigurations = append(backendIpConfigurations, *backendConfig.ID) + } + } + + if rules := props.LoadBalancingRules; rules != nil { + for _, rule := range *rules { + loadBalancingRules = append(loadBalancingRules, *rule.ID) + } + } + } + + d.Set("backend_ip_configurations", backendIpConfigurations) + d.Set("load_balancing_rules", loadBalancingRules) return nil } From dda7a670998518c7fcffe4c04b73ea892e5793d9 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Fri, 11 Oct 2019 18:10:31 +0100 Subject: [PATCH 2/7] Fixed and documentation --- ...source_loadbalancer_backend_address_pool.go | 18 ------------------ ...balancer_backend_address_pool.html.markdown | 14 +++++++++++--- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index ccecae1d3e98..bc61dacda986 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -41,16 +41,6 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { }, Set: schema.HashString, }, - - "load_balancing_rules": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validate.NoEmptyStrings, - }, - Set: schema.HashString, - }, }, } } @@ -75,7 +65,6 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met d.SetId(*bap.ID) var backendIpConfigurations []string - var loadBalancingRules []string if props := bap.BackendAddressPoolPropertiesFormat; props != nil { if configs := props.BackendIPConfigurations; configs != nil { @@ -83,16 +72,9 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met backendIpConfigurations = append(backendIpConfigurations, *backendConfig.ID) } } - - if rules := props.LoadBalancingRules; rules != nil { - for _, rule := range *rules { - loadBalancingRules = append(loadBalancingRules, *rule.ID) - } - } } d.Set("backend_ip_configurations", backendIpConfigurations) - d.Set("load_balancing_rules", loadBalancingRules) return nil } diff --git a/website/docs/d/loadbalancer_backend_address_pool.html.markdown b/website/docs/d/loadbalancer_backend_address_pool.html.markdown index 8347ad0aa22a..61f9ee5f2d89 100644 --- a/website/docs/d/loadbalancer_backend_address_pool.html.markdown +++ b/website/docs/d/loadbalancer_backend_address_pool.html.markdown @@ -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 @@ -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_configurations" { + value = join(",", data.azurerm_lb_backend_address_pool.beap.backend_ip_configurations) } ``` @@ -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. From 277234811c5ed0e6dd46ca75740e6bbcdc020e79 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Fri, 11 Oct 2019 18:17:35 +0100 Subject: [PATCH 3/7] Corrected schema validations --- azurerm/data_source_loadbalancer_backend_address_pool.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index bc61dacda986..9d26c8237634 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -5,6 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) @@ -21,14 +22,12 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, + ValidateFunc: validation.NoZeroValues, }, "loadbalancer_id": { Type: schema.TypeString, Required: true, - ForceNew: true, ValidateFunc: azure.ValidateResourceID, }, From 6a836a015e86eae079e2473195af9b7fd4f70ec6 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:30:48 +0100 Subject: [PATCH 4/7] Improved out the backend_ip_configurations is output --- ...ource_loadbalancer_backend_address_pool.go | 35 ++++++++++++------- ...alancer_backend_address_pool.html.markdown | 4 +-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index 9d26c8237634..b12b6ed04633 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { @@ -32,13 +31,17 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { }, "backend_ip_configurations": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validate.NoEmptyStrings, + Type: schema.TypeList, + Optional: true, + MinItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": { + Type: schema.TypeString, + Computed: true, + }, + }, }, - Set: schema.HashString, }, }, } @@ -63,17 +66,25 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met d.SetId(*bap.ID) - var backendIpConfigurations []string + backendIPConfigurations := make([]interface{}, 0) if props := bap.BackendAddressPoolPropertiesFormat; props != nil { - if configs := props.BackendIPConfigurations; configs != nil { - for _, backendConfig := range *configs { - backendIpConfigurations = append(backendIpConfigurations, *backendConfig.ID) + + 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) + d.Set("backend_ip_configurations", backendIPConfigurations) return nil } diff --git a/website/docs/d/loadbalancer_backend_address_pool.html.markdown b/website/docs/d/loadbalancer_backend_address_pool.html.markdown index 61f9ee5f2d89..b3458b7cec80 100644 --- a/website/docs/d/loadbalancer_backend_address_pool.html.markdown +++ b/website/docs/d/loadbalancer_backend_address_pool.html.markdown @@ -28,8 +28,8 @@ output "backend_address_pool_id" { value = data.azurerm_lb_backend_address_pool.test.id } -output "backend_ip_configurations" { - value = join(",", data.azurerm_lb_backend_address_pool.beap.backend_ip_configurations) +output "backend_ip_configuration_ids" { + value = data.azurerm_lb_backend_address_pool.beap.backend_ip_configurations.*.id } ``` From 124f01ed80af8798c70dfaa4797cd8246c424834 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Fri, 11 Oct 2019 23:34:31 +0100 Subject: [PATCH 5/7] Removed minitems --- azurerm/data_source_loadbalancer_backend_address_pool.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index b12b6ed04633..fa466740cbfc 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -33,7 +33,6 @@ func dataSourceArmLoadBalancerBackendAddressPool() *schema.Resource { "backend_ip_configurations": { Type: schema.TypeList, Optional: true, - MinItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "id": { From 4c2ae77d0b714cfeaf9724126c17f9d26b8989e1 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Sat, 12 Oct 2019 07:45:33 +0100 Subject: [PATCH 6/7] Fixed some formatting issues --- azurerm/data_source_loadbalancer_backend_address_pool.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index fa466740cbfc..82cbe672e074 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -66,9 +66,7 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met d.SetId(*bap.ID) backendIPConfigurations := make([]interface{}, 0) - if props := bap.BackendAddressPoolPropertiesFormat; props != nil { - if beipConfigs := props.BackendIPConfigurations; beipConfigs != nil { for _, config := range *beipConfigs { From 0b31f12c630364139adf2c6c66968fe73008deb5 Mon Sep 17 00:00:00 2001 From: Lee Wilson <264361+leewilson86@users.noreply.github.com> Date: Sat, 12 Oct 2019 12:46:02 +0100 Subject: [PATCH 7/7] Fixed linting issues --- azurerm/data_source_loadbalancer_backend_address_pool.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/data_source_loadbalancer_backend_address_pool.go index 82cbe672e074..ec695049b6f1 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/data_source_loadbalancer_backend_address_pool.go @@ -68,13 +68,10 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met 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) } }