From 55567e0d0cd013c6c3a46c63192bf860320339cb Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:30:09 +0200 Subject: [PATCH 1/7] Update azurerm_eventhub_namespace with optional dedicated_cluster_id property --- .../eventhub/eventhub_namespace_resource.go | 15 ++++++ .../tests/eventhub_namespace_resource_test.go | 48 +++++++++++++++++++ .../validate/eventhub_dedicated_cluster_id.go | 22 +++++++++ 3 files changed, 85 insertions(+) create mode 100644 azurerm/internal/services/eventhub/validate/eventhub_dedicated_cluster_id.go diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index 2f394c50ede2..1d6fcbb3aeb9 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go @@ -17,6 +17,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/eventhub/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -85,6 +86,13 @@ func resourceArmEventHubNamespace() *schema.Resource { Default: false, }, + "dedicated_cluster_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.ValidateEventHubDedicatedClusterID, + }, + "maximum_throughput_units": { Type: schema.TypeInt, Optional: true, @@ -248,6 +256,10 @@ func resourceArmEventHubNamespaceCreateUpdate(d *schema.ResourceData, meta inter Tags: tags.Expand(t), } + if v := d.Get("cluster_id").(string); v != "" { + parameters.EHNamespaceProperties.ClusterArmID = utils.String(v) + } + if v, ok := d.GetOk("maximum_throughput_units"); ok { parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(int32(v.(int))) } @@ -332,6 +344,9 @@ func resourceArmEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled) d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) d.Set("zone_redundant", props.ZoneRedundant) + if dedicatedClusterID := props.ClusterArmID; dedicatedClusterID != nil { + d.Set("dedicated_cluster_id", dedicatedClusterID) + } } ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go index 1ffa9e40cb6d..f3faa0c82404 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_resource_test.go @@ -219,6 +219,25 @@ func TestAccAzureRMEventHubNamespace_zoneRedundant(t *testing.T) { }) } +func TestAccAzureRMEventHubNamespace_dedicatedClusterID(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespace_dedicatedClusterID(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMEventHubNamespace_NonStandardCasing(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") @@ -745,6 +764,35 @@ resource "azurerm_eventhub_namespace" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func testAccAzureRMEventHubNamespace_dedicatedClusterID(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_eventhub_cluster" "test" { + name = "acctesteventhubcluster-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" +} + +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" + dedicated_cluster_id = azurerm_eventhub_cluster.test.id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + func testAccAzureRMEventHubNamespace_basicWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/azurerm/internal/services/eventhub/validate/eventhub_dedicated_cluster_id.go b/azurerm/internal/services/eventhub/validate/eventhub_dedicated_cluster_id.go new file mode 100644 index 000000000000..d4b15a75691b --- /dev/null +++ b/azurerm/internal/services/eventhub/validate/eventhub_dedicated_cluster_id.go @@ -0,0 +1,22 @@ +package validate + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/eventhub/parse" +) + +func ValidateEventHubDedicatedClusterID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.ClusterID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} From f06e36eb78c0e4f6fbb2e3e68daff5ffdd1e5e3e Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:41:16 +0200 Subject: [PATCH 2/7] Update datasource, update docs --- .../services/eventhub/eventhub_namespace_data_source.go | 7 +++++++ website/docs/d/eventhub_namespace.html.markdown | 2 ++ website/docs/r/eventhub_namespace.html.markdown | 2 ++ 3 files changed, 11 insertions(+) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go index 408dac82c905..6220ca3a1a82 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go @@ -53,6 +53,12 @@ func dataSourceEventHubNamespace() *schema.Resource { Computed: true, }, + "dedicated_cluster_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "capacity": { Type: schema.TypeInt, Computed: true, @@ -147,6 +153,7 @@ func dataSourceEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) e d.Set("kafka_enabled", props.KafkaEnabled) d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) d.Set("zone_redundant", props.ZoneRedundant) + d.Set("dedicated_cluster_id", props.ClusterArmID) } return tags.FlattenAndSet(d, resp.Tags) diff --git a/website/docs/d/eventhub_namespace.html.markdown b/website/docs/d/eventhub_namespace.html.markdown index 651acb36c253..a84c83cdc6fc 100644 --- a/website/docs/d/eventhub_namespace.html.markdown +++ b/website/docs/d/eventhub_namespace.html.markdown @@ -44,6 +44,8 @@ output "eventhub_namespace_id" { * `zone_redundant` - Is this EventHub Namespace deployed across Availability Zones? +* `dedicated_cluster_id` - Is this EventHub Namespace deployed on a Dedicated Event Hubs Cluster? + * `tags` - A mapping of tags to assign to the EventHub Namespace. The following attributes are exported only if there is an authorization rule named diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 2c54bef9b0eb..aaa3a794715c 100644 --- a/website/docs/r/eventhub_namespace.html.markdown +++ b/website/docs/r/eventhub_namespace.html.markdown @@ -47,6 +47,8 @@ The following arguments are supported: * `auto_inflate_enabled` - (Optional) Is Auto Inflate enabled for the EventHub Namespace? +* `dedicated_cluster_id` - (Optional) Specifies if the EventHub Namespace should be deployed on a Dedicated EventHubs Cluster. Changing this forces a new resource to be created. + * `maximum_throughput_units` - (Optional) Specifies the maximum number of throughput units when Auto Inflate is Enabled. Valid values range from `1` - `20`. * `zone_redundant` - (Optional) Specifies if the EventHub Namespace should be Zone Redundant (created across Availability Zones). From df47a59898947b4f9ab4452394887a403bf1e4ff Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:53:41 +0200 Subject: [PATCH 3/7] Update azurerm/internal/services/eventhub/eventhub_namespace_data_source.go Co-authored-by: Tom Harvey --- .../internal/services/eventhub/eventhub_namespace_data_source.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go index 6220ca3a1a82..b383494ff9a7 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go @@ -55,7 +55,6 @@ func dataSourceEventHubNamespace() *schema.Resource { "dedicated_cluster_id": { Type: schema.TypeString, - Optional: true, Computed: true, }, From dd800fb4386a49fd01fcf402638660c41c749822 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:53:55 +0200 Subject: [PATCH 4/7] Update website/docs/r/eventhub_namespace.html.markdown Co-authored-by: Tom Harvey --- website/docs/r/eventhub_namespace.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index aaa3a794715c..3ebdd60a0427 100644 --- a/website/docs/r/eventhub_namespace.html.markdown +++ b/website/docs/r/eventhub_namespace.html.markdown @@ -47,7 +47,7 @@ The following arguments are supported: * `auto_inflate_enabled` - (Optional) Is Auto Inflate enabled for the EventHub Namespace? -* `dedicated_cluster_id` - (Optional) Specifies if the EventHub Namespace should be deployed on a Dedicated EventHubs Cluster. Changing this forces a new resource to be created. +* `dedicated_cluster_id` - (Optional) Specifies the ID of the EventHub Dedicated Cluster where this Namespace should created. Changing this forces a new resource to be created. * `maximum_throughput_units` - (Optional) Specifies the maximum number of throughput units when Auto Inflate is Enabled. Valid values range from `1` - `20`. From 4fd7e68fd3b8035ee2ba8d868404b286930beccf Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:54:10 +0200 Subject: [PATCH 5/7] Update website/docs/d/eventhub_namespace.html.markdown Co-authored-by: Tom Harvey --- website/docs/d/eventhub_namespace.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/eventhub_namespace.html.markdown b/website/docs/d/eventhub_namespace.html.markdown index a84c83cdc6fc..1fcdee8ccdba 100644 --- a/website/docs/d/eventhub_namespace.html.markdown +++ b/website/docs/d/eventhub_namespace.html.markdown @@ -44,7 +44,7 @@ output "eventhub_namespace_id" { * `zone_redundant` - Is this EventHub Namespace deployed across Availability Zones? -* `dedicated_cluster_id` - Is this EventHub Namespace deployed on a Dedicated Event Hubs Cluster? +* `dedicated_cluster_id` - The ID of the EventHub Dedicated Cluster where this Namespace exists. * `tags` - A mapping of tags to assign to the EventHub Namespace. From 24e57761b69be177bb4d2860526f417356e17430 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 18:59:44 +0200 Subject: [PATCH 6/7] Typo in property name, remove unnecessary if --- .../services/eventhub/eventhub_namespace_resource.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index 1d6fcbb3aeb9..f34e8adbc7c1 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go @@ -256,7 +256,7 @@ func resourceArmEventHubNamespaceCreateUpdate(d *schema.ResourceData, meta inter Tags: tags.Expand(t), } - if v := d.Get("cluster_id").(string); v != "" { + if v := d.Get("dedicated_cluster_id").(string); v != "" { parameters.EHNamespaceProperties.ClusterArmID = utils.String(v) } @@ -344,9 +344,7 @@ func resourceArmEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled) d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) d.Set("zone_redundant", props.ZoneRedundant) - if dedicatedClusterID := props.ClusterArmID; dedicatedClusterID != nil { - d.Set("dedicated_cluster_id", dedicatedClusterID) - } + d.Set("dedicated_cluster_id", props.ClusterArmID) } ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) From fee5e5c780dbeca077a2e87475bac6eeafd6951c Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 1 Jul 2020 19:08:33 +0200 Subject: [PATCH 7/7] Change eventhub limits validation and update docs --- azurerm/internal/services/eventhub/eventhub_resource.go | 8 ++++---- .../services/eventhub/tests/eventhub_resource_test.go | 8 ++++---- website/docs/r/eventhub.html.markdown | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_resource.go b/azurerm/internal/services/eventhub/eventhub_resource.go index 99412de2b860..0c85edc0ba86 100644 --- a/azurerm/internal/services/eventhub/eventhub_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_resource.go @@ -273,8 +273,8 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error { func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) - if !(32 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32")) + if !(1024 >= value && value >= 1) { + errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32 or between 1 and 1024 if using a dedicated Event Hubs Cluster")) } return warnings, errors @@ -283,8 +283,8 @@ func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, func ValidateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) - if !(7 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7")) + if !(90 >= value && value >= 1) { + errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7 or between 1 and 90 if using a dedicated Event Hubs Cluster")) } return warnings, errors diff --git a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go index fc3b76b2e0e0..5a477fa65984 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go @@ -40,11 +40,11 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) { ErrCount: 0, }, { - Value: 32, + Value: 1024, ErrCount: 0, }, { - Value: 33, + Value: 1025, ErrCount: 1, }, } @@ -85,10 +85,10 @@ func TestAccAzureRMEventHubMessageRetentionCount_validation(t *testing.T) { Value: 6, ErrCount: 0, }, { - Value: 7, + Value: 90, ErrCount: 0, }, { - Value: 8, + Value: 91, ErrCount: 1, }, } diff --git a/website/docs/r/eventhub.html.markdown b/website/docs/r/eventhub.html.markdown index a9d78ec4052c..adc128509426 100644 --- a/website/docs/r/eventhub.html.markdown +++ b/website/docs/r/eventhub.html.markdown @@ -51,7 +51,11 @@ The following arguments are supported: * `partition_count` - (Required) Specifies the current number of shards on the Event Hub. Changing this forces a new resource to be created. -* `message_retention` - (Required) Specifies the number of days to retain the events for this Event Hub. Needs to be between 1 and 7 days; or 1 day when using a Basic SKU for the parent EventHub Namespace. +~> **Note:** When using a dedicated Event Hubs cluster, maximum value of `partition_count` is 1024. When using a shared parent EventHub Namespace, maximum value is 32. + +* `message_retention` - (Required) Specifies the number of days to retain the events for this Event Hub. + +~> **Note:** When using a dedicated Event Hubs cluster, maximum value of `message_retention` is 90 days. When using a shared parent EventHub Namespace, maximum value is 7 days; or 1 day when using a Basic SKU for the shared parent EventHub Namespace. * `capture_description` - (Optional) A `capture_description` block as defined below.