From 13f8938a6c2ab79d92de8cb2a2e5bb4a03388660 Mon Sep 17 00:00:00 2001 From: Kyriakos Oikonomakos Date: Thu, 22 Jul 2021 16:28:22 +0100 Subject: [PATCH] support for Azure Event Hubs Namespace Premium tier (#12695) 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 | 22 ++++++++++++-- .../eventhub_namespace_resource_test.go | 30 +++++++++++++++++++ .../docs/r/eventhub_namespace.html.markdown | 2 +- 3 files changed, 51 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..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" @@ -69,8 +70,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 +251,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 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 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 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.