diff --git a/internal/services/network/application_gateway_resource.go b/internal/services/network/application_gateway_resource.go index c5ff92a33e69d..22b76ed7b9ce2 100644 --- a/internal/services/network/application_gateway_resource.go +++ b/internal/services/network/application_gateway_resource.go @@ -359,30 +359,27 @@ func resourceApplicationGateway() *pluginsdk.Resource { "subnet_id": { Type: pluginsdk.TypeString, Optional: true, - Computed: true, }, "private_ip_address": { Type: pluginsdk.TypeString, Optional: true, - Computed: true, }, "public_ip_address_id": { Type: pluginsdk.TypeString, Optional: true, - Computed: true, }, "private_ip_address_allocation": { Type: pluginsdk.TypeString, Optional: true, - Computed: true, DiffSuppressFunc: suppress.CaseDifferenceV2Only, + Default: string(network.IPAllocationMethodDynamic), ValidateFunc: validation.StringInSlice([]string{ string(network.IPAllocationMethodDynamic), string(network.IPAllocationMethodStatic), - }, !features.ThreePointOhBeta()), + }, false), }, "private_link_configuration_name": { diff --git a/internal/services/network/application_gateway_resource_test.go b/internal/services/network/application_gateway_resource_test.go index de9fd68582708..b5aec77168a12 100644 --- a/internal/services/network/application_gateway_resource_test.go +++ b/internal/services/network/application_gateway_resource_test.go @@ -1175,6 +1175,44 @@ func TestAccApplicationGateway_updateEnableFips(t *testing.T) { }) } +func TestAccApplicationGateway_updateFeipConfig(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") + r := ApplicationGatewayResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.public_ip_address_id").IsSet(), + ), + }, + { + Config: r.updateFeipConfig(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.public_ip_address_id").IsEmpty(), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.subnet_id").IsSet(), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.private_ip_address_allocation").HasValue("Static"), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.private_ip_address").HasValue("10.0.0.10"), + check.That(data.ResourceName).Key("frontend_ip_configuration.1.public_ip_address_id").IsSet(), + ), + }, + data.ImportStep(), + { + Config: r.deletePublicFeip(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.public_ip_address_id").IsEmpty(), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.subnet_id").IsSet(), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.private_ip_address_allocation").HasValue("Static"), + check.That(data.ResourceName).Key("frontend_ip_configuration.0.private_ip_address").HasValue("10.0.0.10"), + check.That(data.ResourceName).Key("frontend_ip_configuration.1").DoesNotExist(), + ), + }, + }) +} + func (t ApplicationGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.ApplicationGatewayID(state.ID) if err != nil { @@ -1447,7 +1485,7 @@ resource "azurerm_public_ip" "test_standard" { resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" - zones = ["1", "2"] + zones = ["1", "2", "3"] } resource "azurerm_application_gateway" "test" { @@ -7487,3 +7525,154 @@ resource "azurerm_application_gateway" "test" { } `, r.template(data), data.RandomInteger, enableFips) } + +func (r ApplicationGatewayResource) updateFeipConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +# since these variables are re-used - a locals block makes this more maintainable +locals { + backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" + frontend_port_name = "${azurerm_virtual_network.test.name}-feport" + frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" + frontend_ip_configuration_name_new = "${azurerm_virtual_network.test.name}-feip-new" + http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" + listener_name = "${azurerm_virtual_network.test.name}-httplstn" + request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +} + +resource "azurerm_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + sku { + name = "Standard_Small" + tier = "Standard" + capacity = 2 + } + + gateway_ip_configuration { + name = "my-gateway-ip-configuration" + subnet_id = azurerm_subnet.test.id + } + + frontend_port { + name = local.frontend_port_name + port = 80 + } + + frontend_ip_configuration { + name = local.frontend_ip_configuration_name_new + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Static" + private_ip_address = "10.0.0.10" + } + + frontend_ip_configuration { + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id + } + + backend_address_pool { + name = local.backend_address_pool_name + } + + backend_http_settings { + name = local.http_setting_name + cookie_based_affinity = "Disabled" + port = 80 + protocol = "Http" + request_timeout = 1 + } + + http_listener { + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name_new + frontend_port_name = local.frontend_port_name + protocol = "Http" + } + + request_routing_rule { + name = local.request_routing_rule_name + rule_type = "Basic" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name + } +} +`, r.template(data), data.RandomInteger) +} + +func (r ApplicationGatewayResource) deletePublicFeip(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +# since these variables are re-used - a locals block makes this more maintainable +locals { + backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" + frontend_port_name = "${azurerm_virtual_network.test.name}-feport" + frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" + frontend_ip_configuration_name_new = "${azurerm_virtual_network.test.name}-feip-new" + http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" + listener_name = "${azurerm_virtual_network.test.name}-httplstn" + request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +} + +resource "azurerm_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + sku { + name = "Standard_Small" + tier = "Standard" + capacity = 2 + } + + gateway_ip_configuration { + name = "my-gateway-ip-configuration" + subnet_id = azurerm_subnet.test.id + } + + frontend_port { + name = local.frontend_port_name + port = 80 + } + + frontend_ip_configuration { + name = local.frontend_ip_configuration_name_new + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Static" + private_ip_address = "10.0.0.10" + } + + backend_address_pool { + name = local.backend_address_pool_name + } + + backend_http_settings { + name = local.http_setting_name + cookie_based_affinity = "Disabled" + port = 80 + protocol = "Http" + request_timeout = 1 + } + + http_listener { + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name_new + frontend_port_name = local.frontend_port_name + protocol = "Http" + } + + request_routing_rule { + name = local.request_routing_rule_name + rule_type = "Basic" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name + } +} +`, r.template(data), data.RandomInteger) +}