Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_application_gateway - allow frontend_ip_configuration blocks to be changed #16132

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}