Skip to content

Commit

Permalink
azurerm_application_gateway - allow frontend_ip_configuration blo…
Browse files Browse the repository at this point in the history
…cks to be changed (#16132)

* allow frontend_ip_configuration block to be changed

* fix linting

* fix zones test
  • Loading branch information
catriona-m authored Apr 4, 2022
1 parent ad01cc8 commit 0e75e9c
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 6 deletions.
7 changes: 2 additions & 5 deletions internal/services/network/application_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
191 changes: 190 additions & 1 deletion internal/services/network/application_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}

0 comments on commit 0e75e9c

Please sign in to comment.