Skip to content

Commit

Permalink
feat: hashicorp#25973 azurerm_application_gateway basic sku support
Browse files Browse the repository at this point in the history
  • Loading branch information
tedsmitt committed Oct 20, 2024
1 parent d5f2fee commit 645a4da
Show file tree
Hide file tree
Showing 3 changed files with 353 additions and 252 deletions.
6 changes: 6 additions & 0 deletions internal/services/network/application_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ func resourceApplicationGateway() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(applicationgateways.ApplicationGatewaySkuNameBasic),
string(applicationgateways.ApplicationGatewaySkuNameStandardSmall),
string(applicationgateways.ApplicationGatewaySkuNameStandardMedium),
string(applicationgateways.ApplicationGatewaySkuNameStandardLarge),
Expand All @@ -825,6 +826,7 @@ func resourceApplicationGateway() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(applicationgateways.ApplicationGatewayTierBasic),
string(applicationgateways.ApplicationGatewayTierStandard),
string(applicationgateways.ApplicationGatewayTierStandardVTwo),
string(applicationgateways.ApplicationGatewayTierWAF),
Expand Down Expand Up @@ -4714,6 +4716,10 @@ func applicationGatewayCustomizeDiff(ctx context.Context, d *pluginsdk.ResourceD
capacity, hasCapacity := d.GetOk("sku.0.capacity")
tier := d.Get("sku.0.tier").(string)

if tier == "Basic" && (hasAutoscaleConfig || hasCapacity) {
return fmt.Errorf("The Application Gateway does not support `autoscale_configuration` blocks or `capacity` values for the selected SKU tier %q", tier)
}

if !hasAutoscaleConfig && !hasCapacity {
return fmt.Errorf("The Application Gateway must specify either `capacity` or `autoscale_configuration` for the selected SKU tier %q", tier)
}
Expand Down
88 changes: 88 additions & 0 deletions internal/services/network/application_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,25 @@ func TestAccApplicationGateway_removeFirewallPolicy(t *testing.T) {
})
}

func TestAccApplicationGateway_basicSku(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test")
r := ApplicationGatewayResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic_basicSku(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku.0.name").HasValue("Basic"),
check.That(data.ResourceName).Key("sku.0.tier").HasValue("Basic"),
check.That(data.ResourceName).Key("sku.0.capacity").IsEmpty(),
check.That(data.ResourceName).Key("autoscale_configuration").IsEmpty(),
),
},
data.ImportStep(),
})
}

func (t ApplicationGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := applicationgateways.ParseApplicationGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1584,6 +1603,75 @@ resource "azurerm_application_gateway" "test" {
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r ApplicationGatewayResource) basic_basicSku(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"
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 = "Basic"
tier = "Basic"
}
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
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
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) createGlobalConfiguration(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
Loading

0 comments on commit 645a4da

Please sign in to comment.