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

Update azurerm_eventhub_namespace with optional dedicated_cluster_id #7548

Merged
merged 7 commits into from
Jul 6, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func dataSourceEventHubNamespace() *schema.Resource {
Computed: true,
},

"dedicated_cluster_id": {
Type: schema.TypeString,
Computed: true,
},

"capacity": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions azurerm/internal/services/eventhub/eventhub_namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions azurerm/internal/services/eventhub/eventhub_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) {
ErrCount: 0,
},
{
Value: 32,
Value: 1024,
ErrCount: 0,
},
{
Value: 33,
Value: 1025,
ErrCount: 1,
},
}
Expand Down Expand Up @@ -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,
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions website/docs/d/eventhub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/eventhub.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/eventhub_namespace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down