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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 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("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,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)
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
@@ -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` - 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
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 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).
Expand Down