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

azurerm_eventhub_namespace - support for AutoInflating/MaximumThroughputCapacity #569

Merged
merged 1 commit into from
Nov 17, 2017
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
29 changes: 29 additions & 0 deletions azurerm/resource_arm_eventhub_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Azure/azure-sdk-for-go/arm/eventhub"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -51,6 +52,19 @@ func resourceArmEventHubNamespace() *schema.Resource {
ValidateFunc: validateEventHubNamespaceCapacity,
},

"auto_inflate_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"maximum_throughput_units": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(1, 20),
},

"default_primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -88,16 +102,26 @@ func resourceArmEventHubNamespaceCreate(d *schema.ResourceData, meta interface{}
capacity := int32(d.Get("capacity").(int))
tags := d.Get("tags").(map[string]interface{})

autoInflateEnabled := d.Get("auto_inflate_enabled").(bool)

parameters := eventhub.EHNamespace{
Location: &location,
Sku: &eventhub.Sku{
Name: eventhub.SkuName(sku),
Tier: eventhub.SkuTier(sku),
Capacity: &capacity,
},
EHNamespaceProperties: &eventhub.EHNamespaceProperties{
IsAutoInflateEnabled: utils.Bool(autoInflateEnabled),
},
Tags: expandTags(tags),
}

if v, ok := d.GetOk("maximum_throughput_units"); ok {
maximumThroughputUnits := v.(int)
parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(int32(maximumThroughputUnits))
}

_, error := namespaceClient.CreateOrUpdate(resGroup, name, parameters, make(chan struct{}))
err := <-error
if err != nil {
Expand Down Expand Up @@ -153,6 +177,11 @@ func resourceArmEventHubNamespaceRead(d *schema.ResourceData, meta interface{})
d.Set("default_secondary_key", keys.SecondaryKey)
}

if props := resp.EHNamespaceProperties; props != nil {
d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled)
d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits))
}

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down
40 changes: 40 additions & 0 deletions azurerm/resource_arm_eventhub_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) {
})
}

func TestAccAzureRMEventHubNamespace_maximumThroughputUnits(t *testing.T) {
resourceName := "azurerm_eventhub_namespace.test"
ri := acctest.RandInt()
config := testAccAzureRMEventHubNamespace_maximumThroughputUnits(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMEventHubNamespaceExists(resourceName),
),
},
},
})
}

func TestAccAzureRMEventHubNamespace_NonStandardCasing(t *testing.T) {

ri := acctest.RandInt()
Expand Down Expand Up @@ -273,3 +293,23 @@ resource "azurerm_eventhub_namespace" "test" {
}
`, rInt, location, rInt)
}

func testAccAzureRMEventHubNamespace_maximumThroughputUnits(rInt int, location string) string {
return fmt.Sprintf(`

resource "azurerm_resource_group" "test" {
name = "acctestRG-%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 = "Standard"
capacity = "2"
auto_inflate_enabled = true
maximum_throughput_units = 20
}
`, rInt, location, rInt)
}
16 changes: 9 additions & 7 deletions website/docs/r/eventhub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ resource "azurerm_resource_group" "test" {

resource "azurerm_eventhub_namespace" "test" {
name = "acceptanceTestEventHubNamespace"
location = "West US"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Standard"
capacity = 2
Expand All @@ -35,17 +35,19 @@ resource "azurerm_eventhub_namespace" "test" {

The following arguments are supported:

* `name` - (Required) Specifies the name of the EventHub Namespace resource . Changing this forces a
new resource to be created.
* `name` - (Required) Specifies the name of the EventHub Namespace resource. Changing this forces a new resource to be created.

* `resource_group_name` - (Required) The name of the resource group in which to
create the namespace. Changing this forces a new resource to be created.
* `resource_group_name` - (Required) The name of the resource group in which to create the namespace. Changing this forces a new resource to be created.

* `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 or Standard.
* `sku` - (Required) Defines which tier to use. Valid options are `Basic` and `Standard`.

* `capacity` - (Optional) Specifies the capacity of a Standard namespace. Can be 1, 2 or 4
* `capacity` - (Optional) Specifies the Capacity / Throughput Units for a `Standard` SKU namespace. Valid values range from 1 - 20.

* `auto_inflate_enabled` - (Optional) Is Auto Inflate enabled for the EventHub Namespace?

* `maximum_throughput_units` - (Optional) Specifies the maximum number of throughput units when Auto Inflate is Enabled. Valid values range from 1 - 20.

* `tags` - (Optional) A mapping of tags to assign to the resource.

Expand Down