Skip to content

Commit

Permalink
Removed ForceNew flag from default_outbound_access_enabled property. (#…
Browse files Browse the repository at this point in the history
…27858)

Updated TestAccSubnet_defaultOutbound to evaluate the update on the property.
  • Loading branch information
CorrenSoft authored Nov 4, 2024
1 parent 5aa08cf commit 8766b56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
5 changes: 4 additions & 1 deletion internal/services/network/subnet_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func resourceSubnet() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Default: true,
Optional: true,
ForceNew: true,
},

"private_endpoint_network_policies": {
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 16 additions & 18 deletions internal/services/network/subnet_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -839,24 +844,17 @@ 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" {
name = "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 {
Expand Down

0 comments on commit 8766b56

Please sign in to comment.