From b573930e127537cbb7cea6a30df74803328b224a Mon Sep 17 00:00:00 2001 From: Dikla Tzemah Weyl Date: Sun, 10 Jul 2022 15:25:52 +0300 Subject: [PATCH 1/6] change sku tier to ot force new --- internal/services/firewall/firewall_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/firewall/firewall_resource.go b/internal/services/firewall/firewall_resource.go index 6624a11d54c0..d64547d2c0c3 100644 --- a/internal/services/firewall/firewall_resource.go +++ b/internal/services/firewall/firewall_resource.go @@ -77,7 +77,7 @@ func resourceFirewall() *pluginsdk.Resource { "sku_tier": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, + ForceNew: false, ValidateFunc: validation.StringInSlice([]string{ string(network.AzureFirewallSkuTierPremium), string(network.AzureFirewallSkuTierStandard), From 1bcb9118f9f07bec1b54cc086fa7eedc2ef0d5da Mon Sep 17 00:00:00 2001 From: Dikla Tzemah Weyl Date: Wed, 13 Jul 2022 15:39:05 +0300 Subject: [PATCH 2/6] add test --- .../firewall/firewall_resource_test.go | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/internal/services/firewall/firewall_resource_test.go b/internal/services/firewall/firewall_resource_test.go index a4b9b8a095ac..1fd23c649b72 100644 --- a/internal/services/firewall/firewall_resource_test.go +++ b/internal/services/firewall/firewall_resource_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -194,6 +195,31 @@ func TestAccFirewall_withZones(t *testing.T) { }) } +func TestAccFirewall_skuTier(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") + r := FirewallResource{} + skuTier := string(network.AzureFirewallSkuTierStandard) + skuTierUpdate := string(network.AzureFirewallSkuTierPremium) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.withSkuTier(data, skuTier), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_tier").HasValue("Standard"), + ), + }, + { + Config: r.withSkuTier(data, skuTierUpdate), + Check: acceptance.ComposeTestCheckFunc( + + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_tier").HasValue("Premium"), + ), + }, + }) +} + func TestAccFirewall_withoutZone(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") r := FirewallResource{} @@ -764,6 +790,58 @@ resource "azurerm_firewall" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (FirewallResource) withSkuTier(data acceptance.TestData, skuTier string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-fw-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvirtnet%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "AzureFirewallSubnet" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["10.0.1.0/24"] +} + +resource "azurerm_public_ip" "test" { + name = "acctestpip%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + allocation_method = "Static" + sku = "Standard" + zones = [] +} + +resource "azurerm_firewall" "test" { + name = "acctestfirewall%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "AZFW_VNet" + sku_tier = %s + + ip_configuration { + name = "configuration" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id + } + + zones = [] +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, skuTier) +} + func (FirewallResource) withZones(data acceptance.TestData, zones []string) string { zoneString := strings.Join(zones, ",") return fmt.Sprintf(` From a514e9fadd9c05a7f16c431e73187468e37293b0 Mon Sep 17 00:00:00 2001 From: diklatze Date: Sun, 31 Jul 2022 09:46:57 +0300 Subject: [PATCH 3/6] Update internal/services/firewall/firewall_resource.go Co-authored-by: kt --- internal/services/firewall/firewall_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/firewall/firewall_resource.go b/internal/services/firewall/firewall_resource.go index d64547d2c0c3..288d3a3db59e 100644 --- a/internal/services/firewall/firewall_resource.go +++ b/internal/services/firewall/firewall_resource.go @@ -77,7 +77,6 @@ func resourceFirewall() *pluginsdk.Resource { "sku_tier": { Type: pluginsdk.TypeString, Required: true, - ForceNew: false, ValidateFunc: validation.StringInSlice([]string{ string(network.AzureFirewallSkuTierPremium), string(network.AzureFirewallSkuTierStandard), From 83f319fd8571057bfc11f329663d3e7f8c693b7a Mon Sep 17 00:00:00 2001 From: diklatze Date: Sun, 31 Jul 2022 09:47:09 +0300 Subject: [PATCH 4/6] Update internal/services/firewall/firewall_resource_test.go Co-authored-by: kt --- internal/services/firewall/firewall_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/firewall/firewall_resource_test.go b/internal/services/firewall/firewall_resource_test.go index 1fd23c649b72..3257b1dae850 100644 --- a/internal/services/firewall/firewall_resource_test.go +++ b/internal/services/firewall/firewall_resource_test.go @@ -195,7 +195,7 @@ func TestAccFirewall_withZones(t *testing.T) { }) } -func TestAccFirewall_skuTier(t *testing.T) { +func TestAccFirewall_skuTierUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") r := FirewallResource{} skuTier := string(network.AzureFirewallSkuTierStandard) From 4d5f6db1a9c02f6be1bc529a65d8d77bf006b4b7 Mon Sep 17 00:00:00 2001 From: Dikla Tzemah Weyl Date: Sun, 31 Jul 2022 15:09:12 +0300 Subject: [PATCH 5/6] add cost and upadated doc --- internal/services/firewall/firewall_resource_test.go | 8 +++++--- website/docs/r/firewall.html.markdown | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/services/firewall/firewall_resource_test.go b/internal/services/firewall/firewall_resource_test.go index 1fd23c649b72..311610efd2a0 100644 --- a/internal/services/firewall/firewall_resource_test.go +++ b/internal/services/firewall/firewall_resource_test.go @@ -6,7 +6,6 @@ import ( "strings" "testing" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -17,6 +16,9 @@ import ( type FirewallResource struct{} +const premium = "Premium" +const standard = "Standard" + func TestAccFirewall_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") r := FirewallResource{} @@ -198,8 +200,8 @@ func TestAccFirewall_withZones(t *testing.T) { func TestAccFirewall_skuTier(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") r := FirewallResource{} - skuTier := string(network.AzureFirewallSkuTierStandard) - skuTierUpdate := string(network.AzureFirewallSkuTierPremium) + skuTier := string(standard) + skuTierUpdate := string(premium) data.ResourceTest(t, r, []acceptance.TestStep{ { diff --git a/website/docs/r/firewall.html.markdown b/website/docs/r/firewall.html.markdown index db006c50d7d8..15071f52acb3 100644 --- a/website/docs/r/firewall.html.markdown +++ b/website/docs/r/firewall.html.markdown @@ -68,7 +68,7 @@ The following arguments are supported: * `sku_name` - (Required) SKU name of the Firewall. Possible values are `AZFW_Hub` and `AZFW_VNet`. Changing this forces a new resource to be created. -* `sku_tier` - (Required) SKU tier of the Firewall. Possible values are `Premium` and `Standard`. Changing this forces a new resource to be created. +* `sku_tier` - (Required) SKU tier of the Firewall. Possible values are `Premium` and `Standard`. * `firewall_policy_id` - (Optional) The ID of the Firewall Policy applied to this Firewall. From 3b4fc23b85aad7517d4941212911f51b58d6f0ea Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 2 Aug 2022 14:07:06 +0200 Subject: [PATCH 6/6] add quotes to around sku value in test config --- internal/services/firewall/firewall_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/firewall/firewall_resource_test.go b/internal/services/firewall/firewall_resource_test.go index a94513be19a7..84b5ebdf6ccc 100644 --- a/internal/services/firewall/firewall_resource_test.go +++ b/internal/services/firewall/firewall_resource_test.go @@ -200,8 +200,8 @@ func TestAccFirewall_withZones(t *testing.T) { func TestAccFirewall_skuTierUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") r := FirewallResource{} - skuTier := string(standard) - skuTierUpdate := string(premium) + skuTier := standard + skuTierUpdate := premium data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -831,7 +831,7 @@ resource "azurerm_firewall" "test" { location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name sku_name = "AZFW_VNet" - sku_tier = %s + sku_tier = "%s" ip_configuration { name = "configuration"