Skip to content

Commit

Permalink
azurerm_eventhub_namespace: fix downgrade scenario (#10536)
Browse files Browse the repository at this point in the history
Fixes #10244.

In a corner case when we are downgrading from Standard to Basic SKU and namespace had both autoInflate enabled and
maximumThroughputUnits set - we need to force throughput units back to 0, otherwise downgrade fails
  • Loading branch information
favoretti authored Feb 11, 2021
1 parent 20d70f6 commit bca10e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ func resourceEventHubNamespaceCreateUpdate(d *schema.ResourceData, meta interfac
parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(int32(v.(int)))
}

// @favoretti: if we are downgrading from Standard to Basic SKU and namespace had both autoInflate enabled and
// maximumThroughputUnits set - we need to force throughput units back to 0, otherwise downgrade fails
//
// See: https://github.com/terraform-providers/terraform-provider-azurerm/issues/10244
//
if parameters.Sku.Tier == eventhub.SkuTierBasic && !autoInflateEnabled {
parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(0)
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, parameters)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,29 @@ func TestAccEventHubNamespace_BasicWithSkuUpdate(t *testing.T) {
})
}

func TestAccEventHubNamespace_SkuDowngradeFromAutoInflateWithMaxThroughput(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test")
r := EventHubNamespaceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.maximumThroughputUnits(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku").HasValue("Standard"),
check.That(data.ResourceName).Key("capacity").HasValue("2"),
),
},
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku").HasValue("Basic"),
),
},
})
}

func TestAccEventHubNamespace_maximumThroughputUnitsUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test")
r := EventHubNamespaceResource{}
Expand Down

0 comments on commit bca10e5

Please sign in to comment.