Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for Azure Event Hubs Namespace Premium tier #12695

Merged
merged 2 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions azurerm/internal/services/eventhub/eventhub_namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
},

Expand Down Expand Up @@ -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
}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
})
}

Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/eventhub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down