diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go index 408dac82c905..b383494ff9a7 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_data_source.go @@ -53,6 +53,11 @@ func dataSourceEventHubNamespace() *schema.Resource { Computed: true, }, + "dedicated_cluster_id": { + Type: schema.TypeString, + Computed: true, + }, + "capacity": { Type: schema.TypeInt, Computed: true, @@ -147,6 +152,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/azurerm/internal/services/eventhub/eventhub_namespace_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_resource.go index 2f394c50ede2..f34e8adbc7c1 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("dedicated_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,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) + d.Set("dedicated_cluster_id", props.ClusterArmID) } ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) 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_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/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/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 +} diff --git a/website/docs/d/eventhub_namespace.html.markdown b/website/docs/d/eventhub_namespace.html.markdown index 651acb36c253..1fcdee8ccdba 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` - The ID of the EventHub Dedicated Cluster where this Namespace exists. + * `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.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. diff --git a/website/docs/r/eventhub_namespace.html.markdown b/website/docs/r/eventhub_namespace.html.markdown index 2c54bef9b0eb..3ebdd60a0427 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 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`. * `zone_redundant` - (Optional) Specifies if the EventHub Namespace should be Zone Redundant (created across Availability Zones).