From 78ae688878358bf58419cd849f8243fadbe72191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fern=C3=A1ndez?= Date: Fri, 1 Nov 2024 17:32:19 -0300 Subject: [PATCH] Removed ForceNew flag from default_outbound_access_enabled property. Updated TestAccSubnet_defaultOutbound to evaluate the update on the property. --- internal/services/network/subnet_resource.go | 5 ++- .../services/network/subnet_resource_test.go | 34 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/internal/services/network/subnet_resource.go b/internal/services/network/subnet_resource.go index 83b99797b94b..2dd98d9f9d91 100644 --- a/internal/services/network/subnet_resource.go +++ b/internal/services/network/subnet_resource.go @@ -204,7 +204,6 @@ func resourceSubnet() *pluginsdk.Resource { Type: pluginsdk.TypeBool, Default: true, Optional: true, - ForceNew: true, }, "private_endpoint_network_policies": { @@ -514,6 +513,10 @@ func resourceSubnetUpdate(d *pluginsdk.ResourceData, meta interface{}) error { } } + if d.HasChange("default_outbound_access_enabled") { + props.DefaultOutboundAccess = pointer.To(d.Get("default_outbound_access_enabled").(bool)) + } + if d.HasChange("delegation") { delegationsRaw := d.Get("delegation").([]interface{}) props.Delegations = expandSubnetDelegation(delegationsRaw) diff --git a/internal/services/network/subnet_resource_test.go b/internal/services/network/subnet_resource_test.go index b3de11245f2f..025f7d73c369 100644 --- a/internal/services/network/subnet_resource_test.go +++ b/internal/services/network/subnet_resource_test.go @@ -127,20 +127,25 @@ func TestAccSubnet_disappears(t *testing.T) { } func TestAccSubnet_defaultOutbound(t *testing.T) { - dataInternal := acceptance.BuildTestData(t, "azurerm_subnet", "internal") - dataPublic := acceptance.BuildTestData(t, "azurerm_subnet", "public") + data := acceptance.BuildTestData(t, "azurerm_subnet", "internal") r := SubnetResource{} - dataInternal.ResourceTest(t, r, []acceptance.TestStep{ + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.defaultOutbound(data, true), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("default_outbound_access_enabled").HasValue("true"), + ), + }, + data.ImportStep(), { - Config: r.defaultOutbound(dataInternal), + Config: r.defaultOutbound(data, false), Check: acceptance.ComposeTestCheckFunc( - check.That(dataInternal.ResourceName).ExistsInAzure(r), - check.That(dataInternal.ResourceName).Key("default_outbound_access_enabled").HasValue("false"), - check.That(dataPublic.ResourceName).ExistsInAzure(r), - check.That(dataPublic.ResourceName).Key("default_outbound_access_enabled").HasValue("true"), + check.That(data.ResourceName).Key("default_outbound_access_enabled").HasValue("false"), ), }, + data.ImportStep(), }) } @@ -839,7 +844,7 @@ resource "azurerm_subnet" "test" { `, r.template(data)) } -func (r SubnetResource) defaultOutbound(data acceptance.TestData) string { +func (r SubnetResource) defaultOutbound(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` %s resource "azurerm_subnet" "internal" { @@ -847,16 +852,9 @@ resource "azurerm_subnet" "internal" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefixes = ["10.0.2.0/24"] - default_outbound_access_enabled = false -} -resource "azurerm_subnet" "public" { - name = "public" - resource_group_name = azurerm_resource_group.test.name - virtual_network_name = azurerm_virtual_network.test.name - address_prefixes = ["10.0.3.0/24"] - default_outbound_access_enabled = true + default_outbound_access_enabled = %t } -`, r.template(data)) +`, r.template(data), enabled) } func (r SubnetResource) delegationUpdated(data acceptance.TestData) string {