From 0310e846423a657d866b4c130482532437108736 Mon Sep 17 00:00:00 2001 From: magodo Date: Fri, 5 Feb 2021 15:06:20 +0800 Subject: [PATCH] azurerm_lb_backend_address_pool: mark `backend_address` as computed (#10481) Fix the regression caused by #10291, that the associated NIC will be cleared by LB BAP --- .../backend_address_pool_resource.go | 3 + ...ncer_backend_address_pool_resource_test.go | 72 ++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/loadbalancer/backend_address_pool_resource.go b/azurerm/internal/services/loadbalancer/backend_address_pool_resource.go index e8868ed484b5..7821e636879c 100644 --- a/azurerm/internal/services/loadbalancer/backend_address_pool_resource.go +++ b/azurerm/internal/services/loadbalancer/backend_address_pool_resource.go @@ -64,6 +64,9 @@ func resourceArmLoadBalancerBackendAddressPool() *schema.Resource { "backend_address": { Type: schema.TypeSet, Optional: true, + // Making this block optional for standard sku LB associating NIC, where the `name` will be computed after + // NIC associates with LB BAP by azurerm_network_interface_backend_address_pool_association. + Computed: true, MinItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/azurerm/internal/services/loadbalancer/loadbalancer_backend_address_pool_resource_test.go b/azurerm/internal/services/loadbalancer/loadbalancer_backend_address_pool_resource_test.go index 27cfb852e9aa..6fa594e8071f 100644 --- a/azurerm/internal/services/loadbalancer/loadbalancer_backend_address_pool_resource_test.go +++ b/azurerm/internal/services/loadbalancer/loadbalancer_backend_address_pool_resource_test.go @@ -275,11 +275,79 @@ func (r LoadBalancerBackendAddressPool) standardSkuNIC(data acceptance.TestData) return fmt.Sprintf(` %s +resource "azurerm_virtual_network" "test" { + name = "testvnet-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + address_space = ["192.168.0.0/16"] +} + +resource "azurerm_subnet" "test" { + name = "testsubnet-%[2]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["192.168.0.0/24"] +} + +resource "azurerm_network_interface" "test" { + name = "testnic-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_linux_virtual_machine_scale_set" "test" { + name = "acctestvmss-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "Standard_F2" + instances = 1 + admin_username = "adminuser" + admin_password = "P@ssword1234!" + + disable_password_authentication = false + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + os_disk { + storage_account_type = "Standard_LRS" + caching = "ReadWrite" + } + + network_interface { + name = "example" + primary = true + + ip_configuration { + name = "internal" + primary = true + subnet_id = azurerm_subnet.test.id + load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.test.id] + } + } +} + +resource "azurerm_network_interface_backend_address_pool_association" "test" { + ip_configuration_name = "testconfiguration1" + network_interface_id = azurerm_network_interface.test.id + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id +} + resource "azurerm_lb_backend_address_pool" "test" { loadbalancer_id = azurerm_lb.test.id - name = "Address-pool-%d" + name = "Address-pool-%[2]d" } -`, template, data.RandomInteger) +`, template, data.RandomIntOfLength(8)) } func (r LoadBalancerBackendAddressPool) standardSkuIPBasic(data acceptance.TestData) string {