Skip to content

Commit

Permalink
Support for Auto Inflating
Browse files Browse the repository at this point in the history
```
$ acctests azurerm TestAccAzureRMEventHubNamespace_maximumThroughputUnits
=== RUN   TestAccAzureRMEventHubNamespace_maximumThroughputUnits
--- PASS: TestAccAzureRMEventHubNamespace_maximumThroughputUnits (202.41s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm    202.432s
```
  • Loading branch information
tombuildsstuff committed Nov 16, 2017
1 parent 5907ba4 commit 3afa533
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
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(0, 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

0 comments on commit 3afa533

Please sign in to comment.