From 579e193bca20ed9b03af3e7f78cc4da73a73cc82 Mon Sep 17 00:00:00 2001 From: xiaxyi Date: Sun, 24 Apr 2022 10:46:58 +0800 Subject: [PATCH 1/2] fix servicebus namespace sku --- .../servicebus_namespace_resource.go | 9 +++- .../servicebus_namespace_resource_test.go | 43 +++++++++++++++++++ .../docs/r/eventhub_namespace.html.markdown | 2 +- .../docs/r/servicebus_namespace.html.markdown | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/internal/services/servicebus/servicebus_namespace_resource.go b/internal/services/servicebus/servicebus_namespace_resource.go index 04ec2fdfb845..61d11ebdb126 100644 --- a/internal/services/servicebus/servicebus_namespace_resource.go +++ b/internal/services/servicebus/servicebus_namespace_resource.go @@ -78,7 +78,6 @@ func resourceServiceBusNamespace() *pluginsdk.Resource { "sku": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(servicebus.SkuNameBasic), string(servicebus.SkuNameStandard), @@ -165,6 +164,14 @@ func resourceServiceBusNamespace() *pluginsdk.Resource { if len(oldCustomerManagedKey.([]interface{})) != 0 && len(newCustomerManagedKey.([]interface{})) == 0 { diff.ForceNew("customer_managed_key") } + + oldSku, newSku := diff.GetChange("sku") + if diff.HasChange("sku") { + if strings.EqualFold(newSku.(string), string(servicebus.SkuNamePremium)) || strings.EqualFold(oldSku.(string), string(servicebus.SkuNamePremium)) { + log.Printf("[DEBUG] cannot migrate a namespace from or to Premium SKU") + diff.ForceNew("sku") + } + } return nil }), } diff --git a/internal/services/servicebus/servicebus_namespace_resource_test.go b/internal/services/servicebus/servicebus_namespace_resource_test.go index c1aa42a3c401..8950816f36fc 100644 --- a/internal/services/servicebus/servicebus_namespace_resource_test.go +++ b/internal/services/servicebus/servicebus_namespace_resource_test.go @@ -44,6 +44,26 @@ func TestAccAzureRMServiceBusNamespace_complete(t *testing.T) { }) } +func TestAccAzureRMServiceBusNamespace_updateSku(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + r := ServiceBusNamespaceResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r)), + }, + data.ImportStep(), + { + Config: r.standardSku(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r)), + }, + data.ImportStep(), + }) +} + func TestAccAzureRMServiceBusNamespace_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") r := ServiceBusNamespaceResource{} @@ -244,6 +264,29 @@ resource "azurerm_servicebus_namespace" "test" { `, data.RandomInteger, data.Locations.Primary) } +func (ServiceBusNamespaceResource) standardSku(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_servicebus_namespace" "test" { + name = "acctestservicebusnamespace-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + local_auth_enabled = false + tags = { + ENV = "Test" + } +}`, data.RandomInteger, data.Locations.Primary) +} + func (r ServiceBusNamespaceResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 7a55d329f486..ffc194480ae8 100644 --- a/website/docs/r/eventhub_namespace.html.markdown +++ b/website/docs/r/eventhub_namespace.html.markdown @@ -41,7 +41,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `sku` - (Required) Defines which tier to use. Valid options are `Basic`, `Standard`, and `Premium`. Please not that setting this field to `Premium` will force the creation of a new resource and also requires setting `zone_redundant` to true. +* `sku` - (Required) Defines which tier to use. Valid options are `Basic`, `Standard`, and `Premium`. Please note that setting this field to `Premium` will force the creation of a new resource and also requires setting `zone_redundant` to true. * `capacity` - (Optional) Specifies the Capacity / Throughput Units for a `Standard` SKU namespace. Default capacity has a maximum of `2`, but can be increased in blocks of 2 on a committed purchase basis. diff --git a/website/docs/r/servicebus_namespace.html.markdown b/website/docs/r/servicebus_namespace.html.markdown index d2ec109dba14..f1f1f144e0c6 100644 --- a/website/docs/r/servicebus_namespace.html.markdown +++ b/website/docs/r/servicebus_namespace.html.markdown @@ -46,7 +46,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `sku` - (Required) Defines which tier to use. Options are basic, standard or premium. Changing this forces a new resource to be created. +* `sku` - (Required) Defines which tier to use. Options are `Basic`, `Standard` or `Premium`. Please note that setting this field to `Premium` will force the creation of a new resource. * `identity` - (Optional) An `identity` block as defined below. From 9e02291fa5bf440331e562ec10635b8918940ad8 Mon Sep 17 00:00:00 2001 From: xiaxyi Date: Sun, 24 Apr 2022 14:08:36 +0800 Subject: [PATCH 2/2] update --- .../services/servicebus/servicebus_namespace_resource_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/services/servicebus/servicebus_namespace_resource_test.go b/internal/services/servicebus/servicebus_namespace_resource_test.go index 8950816f36fc..a6500e5a2e1e 100644 --- a/internal/services/servicebus/servicebus_namespace_resource_test.go +++ b/internal/services/servicebus/servicebus_namespace_resource_test.go @@ -281,9 +281,6 @@ resource "azurerm_servicebus_namespace" "test" { resource_group_name = azurerm_resource_group.test.name sku = "Standard" local_auth_enabled = false - tags = { - ENV = "Test" - } }`, data.RandomInteger, data.Locations.Primary) }