From 8ae6169e4c6d0c01cd4508cbfbdef603258154c0 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 16 Nov 2017 12:21:32 +0000 Subject: [PATCH] Support for Auto Inflating ``` $ acctests azurerm TestAccAzureRMEventHubNamespace_maximumThroughputUnits === RUN TestAccAzureRMEventHubNamespace_maximumThroughputUnits --- PASS: TestAccAzureRMEventHubNamespace_maximumThroughputUnits (202.41s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 202.432s ``` --- azurerm/resource_arm_eventhub_namespace.go | 29 ++++++++++++++ .../resource_arm_eventhub_namespace_test.go | 40 +++++++++++++++++++ .../docs/r/eventhub_namespace.html.markdown | 16 ++++---- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_eventhub_namespace.go b/azurerm/resource_arm_eventhub_namespace.go index 76171f7ef3b8..3c6097400120 100644 --- a/azurerm/resource_arm_eventhub_namespace.go +++ b/azurerm/resource_arm_eventhub_namespace.go @@ -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" ) @@ -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, @@ -88,6 +102,8 @@ 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{ @@ -95,9 +111,17 @@ func resourceArmEventHubNamespaceCreate(d *schema.ResourceData, meta interface{} 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 { @@ -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 diff --git a/azurerm/resource_arm_eventhub_namespace_test.go b/azurerm/resource_arm_eventhub_namespace_test.go index 96641e7d1ef9..369ff20f7f89 100644 --- a/azurerm/resource_arm_eventhub_namespace_test.go +++ b/azurerm/resource_arm_eventhub_namespace_test.go @@ -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() @@ -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) +} diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 0f6ddf9ce797..8d7b959eb3e1 100644 --- a/website/docs/r/eventhub_namespace.html.markdown +++ b/website/docs/r/eventhub_namespace.html.markdown @@ -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 @@ -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.