From 4ef407e6308cb9e202c7520ba9bda7169cd7e459 Mon Sep 17 00:00:00 2001 From: Kyriakos Oikonomakos Date: Thu, 22 Jul 2021 15:09:59 +0100 Subject: [PATCH 1/2] support for Azure Event Hubs Namespace Premium tier Adds support for the Premium tier of the event hubs namespace resource. It is not possible to actually move from/to that tier so setting the sku to `Premium` forces the resource to be re-created. This will also throw an error if someone attempts to create a premium namespace without setting zone_redundant to true. --- .../eventhub/eventhub_namespace_resource.go | 21 +++++++++++-- .../eventhub_namespace_resource_test.go | 30 +++++++++++++++++++ .../docs/r/eventhub_namespace.html.markdown | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index e35630fced2a..8e259e99d88b 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go @@ -69,8 +69,9 @@ func resourceEventHubNamespace() *pluginsdk.Resource { Required: true, DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ - string(eventhub.Basic), - string(eventhub.Standard), + string(namespaces.SkuNameBasic), + string(namespaces.SkuNameStandard), + string(namespaces.SkuNamePremium), }, true), }, @@ -249,6 +250,22 @@ func resourceEventHubNamespace() *pluginsdk.Resource { "tags": tags.Schema(), }, + CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error { + oldSku, newSku := d.GetChange("sku") + if d.HasChange("sku") { + if newSku.(string) == string(namespaces.SkuNamePremium) || oldSku.(string) == string(namespaces.SkuTierPremium) { + log.Printf("[DEBUG] cannot migrate a namespace from or to Premium SKU") + d.ForceNew("sku") + } + if newSku.(string) == string(namespaces.SkuTierPremium) { + zoneRedundant := d.Get("zone_redundant").(bool) + if !zoneRedundant { + return fmt.Errorf("zone_redundant needs to be set to true when using premium SKU.") + } + } + } + return nil + }), } } diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource_test.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource_test.go index 11dacb7223fa..693e1264c7cc 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource_test.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource_test.go @@ -388,6 +388,14 @@ func TestAccEventHubNamespace_BasicWithSkuUpdate(t *testing.T) { check.That(data.ResourceName).Key("capacity").HasValue("2"), ), }, + { + Config: r.premium(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku").HasValue("Premium"), + check.That(data.ResourceName).Key("capacity").HasValue("1"), + ), + }, }) } @@ -588,6 +596,28 @@ resource "azurerm_eventhub_namespace" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func (EventHubNamespaceResource) premium(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eh-%d" + location = "%s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Premium" + capacity = "1" + zone_redundant = true +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + func (EventHubNamespaceResource) standardWithIdentity(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 96af0b2b7d58..4cd7e95ce6df 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` and `Standard`. +* `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. * `capacity` - (Optional) Specifies the Capacity / Throughput Units for a `Standard` SKU namespace. Default capacity has a maximum of `20`, but can be increased in blocks of 20 on a committed purchase basis. From 58d12c6d6204b4d89d8267bd9bd295796d600767 Mon Sep 17 00:00:00 2001 From: Kyriakos Oikonomakos Date: Thu, 22 Jul 2021 15:43:57 +0100 Subject: [PATCH 2/2] make case insensitive checks in CustomDiff function --- .../services/eventhub/eventhub_namespace_resource.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index 8e259e99d88b..f0ee82c183ee 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "strconv" + "strings" "time" "github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" @@ -253,14 +254,14 @@ func resourceEventHubNamespace() *pluginsdk.Resource { CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error { oldSku, newSku := d.GetChange("sku") if d.HasChange("sku") { - if newSku.(string) == string(namespaces.SkuNamePremium) || oldSku.(string) == string(namespaces.SkuTierPremium) { + if strings.EqualFold(newSku.(string), string(namespaces.SkuNamePremium)) || strings.EqualFold(oldSku.(string), string(namespaces.SkuTierPremium)) { log.Printf("[DEBUG] cannot migrate a namespace from or to Premium SKU") d.ForceNew("sku") } - if newSku.(string) == string(namespaces.SkuTierPremium) { + if strings.EqualFold(newSku.(string), string(namespaces.SkuTierPremium)) { zoneRedundant := d.Get("zone_redundant").(bool) if !zoneRedundant { - return fmt.Errorf("zone_redundant needs to be set to true when using premium SKU.") + return fmt.Errorf("zone_redundant needs to be set to true when using premium SKU") } } }