From 39b309f7202d15aec59732d373aa4fe964876533 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 17 Jun 2020 00:29:27 +0200 Subject: [PATCH 01/48] Adjust partition count validator Adjust partition count validator to support Event Hubs Cluster partition counts. See https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dedicated-overview#event-hubs-dedicated-quotas-and-limits for details. --- azurerm/internal/services/eventhub/eventhub_resource.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_resource.go b/azurerm/internal/services/eventhub/eventhub_resource.go index 99412de2b860..17cf58d54dac 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 for standard hubs and 1024 for Event Hubs Clusters")) } return warnings, errors From cec7b0f47e0385c85f674e87cc92b6553f7d6ec8 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 17 Jun 2020 00:32:48 +0200 Subject: [PATCH 02/48] Update tests --- .../internal/services/eventhub/tests/eventhub_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go index fc3b76b2e0e0..fc4723cbff93 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go @@ -44,7 +44,7 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) { ErrCount: 0, }, { - Value: 33, + Value: 1025, ErrCount: 1, }, } From f8f4f58ca7754829b521c554b2b7c71a5d5fee8b Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 17 Jun 2020 00:36:38 +0200 Subject: [PATCH 03/48] Up retention limits to fit eventhub clusters --- azurerm/internal/services/eventhub/eventhub_resource.go | 4 ++-- .../services/eventhub/tests/eventhub_resource_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_resource.go b/azurerm/internal/services/eventhub/eventhub_resource.go index 17cf58d54dac..ce37196ebd03 100644 --- a/azurerm/internal/services/eventhub/eventhub_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_resource.go @@ -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 for standard hubs and 90 for Event Hubs Clusters")) } 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 fc4723cbff93..6e0d2704a45f 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go @@ -88,7 +88,7 @@ func TestAccAzureRMEventHubMessageRetentionCount_validation(t *testing.T) { Value: 7, ErrCount: 0, }, { - Value: 8, + Value: 91, ErrCount: 1, }, } From 977375b335891a0df2dfd13d0ca023da3b239671 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 15:12:25 +0200 Subject: [PATCH 04/48] WIP: dedicated eventhubs --- .../eventhub/eventhub_dedicated_resource.go | 409 ++++++++++++ .../eventhub_namespace_dedicated_resource.go | 508 ++++++++++++++ .../services/eventhub/eventhub_resource.go | 4 +- .../tests/eventhub_dedicated_resource_test.go | 625 ++++++++++++++++++ .../eventhub/tests/eventhub_resource_test.go | 4 +- 5 files changed, 1546 insertions(+), 4 deletions(-) create mode 100644 azurerm/internal/services/eventhub/eventhub_dedicated_resource.go create mode 100644 azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go create mode 100644 azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go new file mode 100644 index 000000000000..e5bb701cc49b --- /dev/null +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -0,0 +1,409 @@ +package eventhub + +import ( + "fmt" + "log" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "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/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +var eventHubDedicatedResourceName = "azurerm_eventhub_dedicated" + +func resourceArmEventHubDedicatedDedicated() *schema.Resource { + return &schema.Resource{ + Create: resourceArmEventHubDedicatedCreateUpdate, + Read: resourceArmEventHubDedicatedRead, + Update: resourceArmEventHubDedicatedCreateUpdate, + Delete: resourceArmEventHubDedicatedDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubName(), + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "partition_count": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + ValidateFunc: ValidateEventHubDedicatedPartitionCount, + }, + + "message_retention": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: ValidateEventHubDedicatedMessageRetentionCount, + }, + + "capture_description": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Required: true, + }, + "skip_empty_archives": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "encoding": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validation.StringInSlice([]string{ + string(eventhub.Avro), + string(eventhub.AvroDeflate), + }, true), + }, + "interval_in_seconds": { + Type: schema.TypeInt, + Optional: true, + Default: 300, + ValidateFunc: validation.IntBetween(60, 900), + }, + "size_limit_in_bytes": { + Type: schema.TypeInt, + Optional: true, + Default: 314572800, + ValidateFunc: validation.IntBetween(10485760, 524288000), + }, + "destination": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "EventHubArchive.AzureBlockBlob", + // TODO: support `EventHubArchive.AzureDataLake` once supported in the Swagger / SDK + // https://github.com/Azure/azure-rest-api-specs/issues/2255 + // BlobContainerName & StorageAccountID can then become Optional + }, false), + }, + "archive_name_format": { + Type: schema.TypeString, + Required: true, + ValidateFunc: ValidateEventHubArchiveNameFormat, + }, + "blob_container_name": { + Type: schema.TypeString, + Required: true, + }, + "storage_account_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + }, + }, + }, + }, + }, + + "partition_ids": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Computed: true, + }, + }, + } +} + +func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.EventHubsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + log.Printf("[INFO] preparing arguments for Azure ARM EventHub creation.") + + name := d.Get("name").(string) + namespaceName := d.Get("namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing EventHub %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_eventhub", *existing.ID) + } + } + + partitionCount := int64(d.Get("partition_count").(int)) + messageRetention := int64(d.Get("message_retention").(int)) + + parameters := eventhub.Model{ + Properties: &eventhub.Properties{ + PartitionCount: &partitionCount, + MessageRetentionInDays: &messageRetention, + }, + } + + if _, ok := d.GetOk("capture_description"); ok { + parameters.Properties.CaptureDescription = expandEventHubCaptureDescription(d) + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil { + return err + } + + read, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + return err + } + + if read.ID == nil { + return fmt.Errorf("Cannot read EventHub %s (resource group %s) ID", name, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmEventHubDedicatedRead(d, meta) +} + +func resourceArmEventHubDedicatedRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.EventHubsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["eventhubs"] + resp, err := client.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on Azure EventHub %q (resource group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + + if props := resp.Properties; props != nil { + d.Set("partition_count", props.PartitionCount) + d.Set("message_retention", props.MessageRetentionInDays) + d.Set("partition_ids", props.PartitionIds) + + captureDescription := flattenEventHubCaptureDescription(props.CaptureDescription) + if err := d.Set("capture_description", captureDescription); err != nil { + return err + } + } + + return nil +} + +func resourceArmEventHubDedicatedDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.EventHubsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + name := id.Path["eventhubs"] + resp, err := client.Delete(ctx, resourceGroup, namespaceName, name) + + if err != nil { + if utils.ResponseWasNotFound(resp) { + return nil + } + + return fmt.Errorf("Error issuing delete request for EventHub %q (resource group %q): %+v", name, resourceGroup, err) + } + + return nil +} + +func ValidateEventHubDedicatedPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { + value := v.(int) + + if !(1024 >= value && value >= 1) { + errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32 for standard hubs and 1024 for Event Hubs Clusters")) + } + + return warnings, errors +} + +func ValidateEventHubDedicatedMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { + value := v.(int) + + if !(90 >= value && value >= 1) { + errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7 for standard hubs and 90 for Event Hubs Clusters")) + } + + return warnings, errors +} + +func ValidateEventHubDedicatedArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + requiredComponents := []string{ + "{Namespace}", + "{EventHub}", + "{PartitionId}", + "{Year}", + "{Month}", + "{Day}", + "{Hour}", + "{Minute}", + "{Second}", + } + + for _, component := range requiredComponents { + if !strings.Contains(value, component) { + errors = append(errors, fmt.Errorf("%s needs to contain %q", k, component)) + } + } + + return warnings, errors +} + +func expandEventHubDedicatedCaptureDescription(d *schema.ResourceData) *eventhub.CaptureDescription { + inputs := d.Get("capture_description").([]interface{}) + input := inputs[0].(map[string]interface{}) + + enabled := input["enabled"].(bool) + encoding := input["encoding"].(string) + intervalInSeconds := input["interval_in_seconds"].(int) + sizeLimitInBytes := input["size_limit_in_bytes"].(int) + skipEmptyArchives := input["skip_empty_archives"].(bool) + + captureDescription := eventhub.CaptureDescription{ + Enabled: utils.Bool(enabled), + Encoding: eventhub.EncodingCaptureDescription(encoding), + IntervalInSeconds: utils.Int32(int32(intervalInSeconds)), + SizeLimitInBytes: utils.Int32(int32(sizeLimitInBytes)), + SkipEmptyArchives: utils.Bool(skipEmptyArchives), + } + + if v, ok := input["destination"]; ok { + destinations := v.([]interface{}) + if len(destinations) > 0 { + destination := destinations[0].(map[string]interface{}) + + destinationName := destination["name"].(string) + archiveNameFormat := destination["archive_name_format"].(string) + blobContainerName := destination["blob_container_name"].(string) + storageAccountId := destination["storage_account_id"].(string) + + captureDescription.Destination = &eventhub.Destination{ + Name: utils.String(destinationName), + DestinationProperties: &eventhub.DestinationProperties{ + ArchiveNameFormat: utils.String(archiveNameFormat), + BlobContainer: utils.String(blobContainerName), + StorageAccountResourceID: utils.String(storageAccountId), + }, + } + } + } + + return &captureDescription +} + +func flattenEventHubDedicatedCaptureDescription(description *eventhub.CaptureDescription) []interface{} { + results := make([]interface{}, 0) + + if description != nil { + output := make(map[string]interface{}) + + if enabled := description.Enabled; enabled != nil { + output["enabled"] = *enabled + } + + if skipEmptyArchives := description.SkipEmptyArchives; skipEmptyArchives != nil { + output["skip_empty_archives"] = *skipEmptyArchives + } + + output["encoding"] = string(description.Encoding) + + if interval := description.IntervalInSeconds; interval != nil { + output["interval_in_seconds"] = *interval + } + + if size := description.SizeLimitInBytes; size != nil { + output["size_limit_in_bytes"] = *size + } + + if destination := description.Destination; destination != nil { + destinationOutput := make(map[string]interface{}) + + if name := destination.Name; name != nil { + destinationOutput["name"] = *name + } + + if props := destination.DestinationProperties; props != nil { + if archiveNameFormat := props.ArchiveNameFormat; archiveNameFormat != nil { + destinationOutput["archive_name_format"] = *archiveNameFormat + } + if blobContainerName := props.BlobContainer; blobContainerName != nil { + destinationOutput["blob_container_name"] = *blobContainerName + } + if storageAccountId := props.StorageAccountResourceID; storageAccountId != nil { + destinationOutput["storage_account_id"] = *storageAccountId + } + } + + output["destination"] = []interface{}{destinationOutput} + } + + results = append(results, output) + } + + return results +} diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go new file mode 100644 index 000000000000..9bb2fd573aa4 --- /dev/null +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -0,0 +1,508 @@ +package eventhub + +import ( + "context" + "fmt" + "log" + "strconv" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "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/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +// Default Authorization Rule/Policy created by Azure, used to populate the +// default connection strings and keys +var eventHubNamespaceDedicatedDefaultAuthorizationRule = "RootManageSharedAccessKey" +var eventHubNamespaceDedicatedResourceName = "azurerm_eventhub_namespace" + +func resourceArmeventHubNamespaceDedicated() *schema.Resource { + return &schema.Resource{ + Create: resourceArmeventHubNamespaceDedicatedCreateUpdate, + Read: resourceArmeventHubNamespaceDedicatedRead, + Update: resourceArmeventHubNamespaceDedicatedCreateUpdate, + Delete: resourceArmeventHubNamespaceDedicatedDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), + }, + + "cluster_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "location": azure.SchemaLocation(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "sku": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validation.StringInSlice([]string{ + string(eventhub.Basic), + string(eventhub.Standard), + }, true), + }, + + "capacity": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + ValidateFunc: validation.IntBetween(1, 20), + }, + + "auto_inflate_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "maximum_throughput_units": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validation.IntBetween(0, 20), + }, + + "network_rulesets": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Computed: true, + ConfigMode: schema.SchemaConfigModeAttr, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + + "default_action": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(eventhub.Allow), + string(eventhub.Deny), + }, false), + }, + + // 128 limit per https://docs.microsoft.com/azure/event-hubs/event-hubs-quotas + "virtual_network_rule": { + Type: schema.TypeList, + Optional: true, + MaxItems: 128, + ConfigMode: schema.SchemaConfigModeAttr, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + + // the API returns the subnet ID's resource group name in lowercase + // https://github.com/Azure/azure-sdk-for-go/issues/5855 + "subnet_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + DiffSuppressFunc: suppress.CaseDifference, + }, + + "ignore_missing_virtual_network_service_endpoint": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + }, + + // 128 limit per https://docs.microsoft.com/azure/event-hubs/event-hubs-quotas + "ip_rule": { + Type: schema.TypeList, + Optional: true, + MaxItems: 128, + ConfigMode: schema.SchemaConfigModeAttr, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "ip_mask": { + Type: schema.TypeString, + Required: true, + }, + + "action": { + Type: schema.TypeString, + Optional: true, + Default: string(eventhub.NetworkRuleIPActionAllow), + ValidateFunc: validation.StringInSlice([]string{ + string(eventhub.NetworkRuleIPActionAllow), + }, false), + }, + }, + }, + }, + }, + }, + }, + + "default_primary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_secondary_connection_string_alias": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_primary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "default_secondary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.NamespacesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + log.Printf("[INFO] preparing arguments for AzureRM EventHub Namespace creation.") + + name := d.Get("name").(string) + clusterID := d.Get("cluster_id").(string) + resGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing EventHub Namespace %q (Resource Group %q): %s", name, resGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_eventhub_namespace", *existing.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + sku := d.Get("sku").(string) + capacity := int32(d.Get("capacity").(int)) + t := d.Get("tags").(map[string]interface{}) + autoInflateEnabled := d.Get("auto_inflate_enabled").(bool) + + parameters := eventhub.EHNamespace{ + Location: &location, + Sku: &eventhub.Sku{ + Name: eventhub.SkuName(sku), + Tier: eventhub.SkuTier(sku), + Capacity: &capacity, + }, + EHNamespaceProperties: &eventhub.EHNamespaceProperties{ + IsAutoInflateEnabled: utils.Bool(autoInflateEnabled), + ClusterArmID: &clusterID, + }, + Tags: tags.Expand(t), + } + + if v, ok := d.GetOk("maximum_throughput_units"); ok { + parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(int32(v.(int))) + } + + future, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) + if err != nil { + return err + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error creating eventhub namespace: %+v", err) + } + + read, err := client.Get(ctx, resGroup, name) + if err != nil { + return err + } + + if read.ID == nil { + return fmt.Errorf("Cannot read EventHub Namespace %q (resource group %q) ID", name, resGroup) + } + + d.SetId(*read.ID) + + ruleSets, hasRuleSets := d.GetOk("network_rulesets") + if hasRuleSets { + rulesets := eventhub.NetworkRuleSet{ + NetworkRuleSetProperties: expandeventHubNamespaceDedicatedNetworkRuleset(ruleSets.([]interface{})), + } + + // cannot use network rulesets with the basic SKU + if parameters.Sku.Name != eventhub.Basic { + if _, err := client.CreateOrUpdateNetworkRuleSet(ctx, resGroup, name, rulesets); err != nil { + return fmt.Errorf("Error setting network ruleset properties for EventHub Namespace %q (resource group %q): %v", name, resGroup, err) + } + } else { + // so if the user has specified the non default rule sets throw a validation error + if rulesets.DefaultAction != eventhub.Deny || + (rulesets.IPRules != nil && len(*rulesets.IPRules) > 0) || + (rulesets.VirtualNetworkRules != nil && len(*rulesets.VirtualNetworkRules) > 0) { + return fmt.Errorf("network_rulesets cannot be used when the SKU is basic") + } + } + } + + return resourceArmeventHubNamespaceDedicatedRead(d, meta) +} + +func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.NamespacesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["namespaces"] + + resp, err := client.Get(ctx, resGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on EventHub Namespace %q: %+v", name, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if sku := resp.Sku; sku != nil { + d.Set("sku", string(sku.Name)) + d.Set("capacity", sku.Capacity) + } + + if props := resp.EHNamespaceProperties; props != nil { + d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled) + d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) + d.Set("cluster_id", props.ClusterArmID) + } + + ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) + if err != nil { + return fmt.Errorf("Error making Read request on EventHub Namespace %q Network Ruleset: %+v", name, err) + } + + if err := d.Set("network_rulesets", flatteneventHubNamespaceDedicatedNetworkRuleset(ruleset)); err != nil { + return fmt.Errorf("Error setting `network_ruleset` for Evenhub Namespace %s: %v", name, err) + } + + keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDedicatedDefaultAuthorizationRule) + if err != nil { + log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q: %+v", name, err) + } else { + d.Set("default_primary_connection_string_alias", keys.AliasPrimaryConnectionString) + d.Set("default_secondary_connection_string_alias", keys.AliasSecondaryConnectionString) + d.Set("default_primary_connection_string", keys.PrimaryConnectionString) + d.Set("default_secondary_connection_string", keys.SecondaryConnectionString) + d.Set("default_primary_key", keys.PrimaryKey) + d.Set("default_secondary_key", keys.SecondaryKey) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.NamespacesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resGroup := id.ResourceGroup + name := id.Path["namespaces"] + + future, err := client.Delete(ctx, resGroup, name) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error issuing delete request of EventHub Namespace %q (Resource Group %q): %+v", name, resGroup, err) + } + + return waitForeventHubNamespaceDedicatedToBeDeleted(ctx, client, resGroup, name, d) +} + +func waitForeventHubNamespaceDedicatedToBeDeleted(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string, d *schema.ResourceData) error { + // we can't use the Waiter here since the API returns a 200 once it's deleted which is considered a polling status code.. + log.Printf("[DEBUG] Waiting for EventHub Namespace (%q in Resource Group %q) to be deleted", name, resourceGroup) + stateConf := &resource.StateChangeConf{ + Pending: []string{"200"}, + Target: []string{"404"}, + Refresh: eventHubNamespaceDedicatedStateStatusCodeRefreshFunc(ctx, client, resourceGroup, name), + Timeout: d.Timeout(schema.TimeoutDelete), + } + + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Error waiting for EventHub NameSpace (%q in Resource Group %q) to be deleted: %+v", name, resourceGroup, err) + } + + return nil +} + +func eventHubNamespaceDedicatedStateStatusCodeRefreshFunc(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + res, err := client.Get(ctx, resourceGroup, name) + + log.Printf("Retrieving EventHub Namespace %q (Resource Group %q) returned Status %d", resourceGroup, name, res.StatusCode) + + if err != nil { + if utils.ResponseWasNotFound(res.Response) { + return res, strconv.Itoa(res.StatusCode), nil + } + return nil, "", fmt.Errorf("Error polling for the status of the EventHub Namespace %q (RG: %q): %+v", name, resourceGroup, err) + } + + return res, strconv.Itoa(res.StatusCode), nil + } +} + +func expandeventHubNamespaceDedicatedNetworkRuleset(input []interface{}) *eventhub.NetworkRuleSetProperties { + if len(input) == 0 { + return nil + } + + block := input[0].(map[string]interface{}) + + ruleset := eventhub.NetworkRuleSetProperties{ + DefaultAction: eventhub.DefaultAction(block["default_action"].(string)), + } + + if v, ok := block["virtual_network_rule"].([]interface{}); ok { + if len(v) > 0 { + var rules []eventhub.NWRuleSetVirtualNetworkRules + for _, r := range v { + rblock := r.(map[string]interface{}) + rules = append(rules, eventhub.NWRuleSetVirtualNetworkRules{ + Subnet: &eventhub.Subnet{ + ID: utils.String(rblock["subnet_id"].(string)), + }, + IgnoreMissingVnetServiceEndpoint: utils.Bool(rblock["ignore_missing_virtual_network_service_endpoint"].(bool)), + }) + } + + ruleset.VirtualNetworkRules = &rules + } + } + + if v, ok := block["ip_rule"].([]interface{}); ok { + if len(v) > 0 { + var rules []eventhub.NWRuleSetIPRules + for _, r := range v { + rblock := r.(map[string]interface{}) + rules = append(rules, eventhub.NWRuleSetIPRules{ + IPMask: utils.String(rblock["ip_mask"].(string)), + Action: eventhub.NetworkRuleIPAction(rblock["action"].(string)), + }) + } + + ruleset.IPRules = &rules + } + } + + return &ruleset +} + +func flatteneventHubNamespaceDedicatedNetworkRuleset(ruleset eventhub.NetworkRuleSet) []interface{} { + if ruleset.NetworkRuleSetProperties == nil { + return nil + } + + vnetBlocks := make([]interface{}, 0) + if vnetRules := ruleset.NetworkRuleSetProperties.VirtualNetworkRules; vnetRules != nil { + for _, vnetRule := range *vnetRules { + block := make(map[string]interface{}) + + if s := vnetRule.Subnet; s != nil { + if v := s.ID; v != nil { + block["subnet_id"] = *v + } + } + + if v := vnetRule.IgnoreMissingVnetServiceEndpoint; v != nil { + block["ignore_missing_virtual_network_service_endpoint"] = *v + } + + vnetBlocks = append(vnetBlocks, block) + } + } + ipBlocks := make([]interface{}, 0) + if ipRules := ruleset.NetworkRuleSetProperties.IPRules; ipRules != nil { + for _, ipRule := range *ipRules { + block := make(map[string]interface{}) + + block["action"] = string(ipRule.Action) + + if v := ipRule.IPMask; v != nil { + block["ip_mask"] = *v + } + + ipBlocks = append(ipBlocks, block) + } + } + + return []interface{}{map[string]interface{}{ + "default_action": string(ruleset.DefaultAction), + "virtual_network_rule": vnetBlocks, + "ip_rule": ipBlocks, + }} +} diff --git a/azurerm/internal/services/eventhub/eventhub_resource.go b/azurerm/internal/services/eventhub/eventhub_resource.go index ce37196ebd03..043c49aaca6c 100644 --- a/azurerm/internal/services/eventhub/eventhub_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_resource.go @@ -273,7 +273,7 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error { func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) - if !(1024 >= value && value >= 1) { + if !(32 >= value && value >= 1) { errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32 for standard hubs and 1024 for Event Hubs Clusters")) } @@ -283,7 +283,7 @@ func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, func ValidateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) - if !(90 >= value && value >= 1) { + if !(7 >= value && value >= 1) { errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7 for standard hubs and 90 for Event Hubs Clusters")) } diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go new file mode 100644 index 000000000000..4814eea8cb04 --- /dev/null +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -0,0 +1,625 @@ +package tests + +import ( + "fmt" + "net/http" + "testing" + + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/eventhub" +) + +func TestAccAzureRMEventHubDedicatedPartitionCount_validation(t *testing.T) { + cases := []struct { + Value int + ErrCount int + }{ + { + Value: 0, + ErrCount: 1, + }, + { + Value: 1, + ErrCount: 0, + }, + { + Value: 2, + ErrCount: 0, + }, + { + Value: 3, + ErrCount: 0, + }, + { + Value: 21, + ErrCount: 0, + }, + { + Value: 32, + ErrCount: 0, + }, + { + Value: 33, + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := eventhub.ValidateEventHubPartitionCount(tc.Value, "azurerm_eventhub") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Azure RM EventHub Partition Count to trigger a validation error") + } + } +} + +func TestAccAzureRMEventHubDedicatedMessageRetentionCount_validation(t *testing.T) { + cases := []struct { + Value int + ErrCount int + }{ + { + Value: 0, + ErrCount: 1, + }, { + Value: 1, + ErrCount: 0, + }, { + Value: 2, + ErrCount: 0, + }, { + Value: 3, + ErrCount: 0, + }, { + Value: 4, + ErrCount: 0, + }, { + Value: 5, + ErrCount: 0, + }, { + Value: 6, + ErrCount: 0, + }, { + Value: 7, + ErrCount: 0, + }, { + Value: 91, + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := eventhub.ValidateEventHubMessageRetentionCount(tc.Value, "azurerm_eventhub") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Azure RM EventHub Message Retention Count to trigger a validation error") + } + } +} + +func TestAccAzureRMEventHubDedicatedArchiveNameFormat_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "", + ErrCount: 9, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 0, + }, + { + Value: "Prod_{Eventub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Month}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}/{Day}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Hour}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Minute}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Second}", + ErrCount: 1, + }, + { + Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}", + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := eventhub.ValidateEventHubArchiveNameFormat(tc.Value, "azurerm_eventhub") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected %q to trigger a validation error", tc.Value) + } + } +} + +func TestAccAzureRMEventHubDedicated_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubDedicated_basicOnePartition(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_basic(data, 1), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "1"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubDedicated_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + ), + }, + { + Config: TestAccAzureRMEventHubDedicated_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_eventhub_dedicated"), + }, + }, + }) +} + +func TestAccAzureRMEventHubDedicated_partitionCountUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "2"), + ), + }, + { + Config: TestAccAzureRMEventHubDedicated_partitionCountUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "10"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubDedicated_standard(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_standard(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubDedicated_captureDescription(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_captureDescription(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.skip_empty_archives", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubDedicated_captureDescriptionDisabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_captureDescription(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), + ), + }, + { + Config: TestAccAzureRMEventHubDedicated_captureDescription(data, false), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "false"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubDedicated_messageRetentionUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubDestroy, + Steps: []resource.TestStep{ + { + Config: TestAccAzureRMEventHubDedicated_standard(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "7"), + ), + }, + { + Config: TestAccAzureRMEventHubDedicated_messageRetentionUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "5"), + ), + }, + }, + }) +} + +func testCheckAzureRMEventHubDestroy(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.EventHubsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_eventhub_dedicated" { + continue + } + + name := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, namespaceName, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("EventHub still exists:\n%#v", resp.Properties) + } + } + + return nil +} + +func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.EventHubsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Event Hub: %s", name) + } + + resp, err := conn.Get(ctx, resourceGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Bad: Get on eventHubClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Event Hub %q (namespace %q / resource group: %q) does not exist", name, namespaceName, resourceGroup) + } + + return nil + } +} + +func TestAccAzureRMEventHubDedicated_basic(data acceptance.TestData, partitionCount int) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%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_dedicated" "test" { + name = "acctesteventhubnamespace-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} + +resource "azurerm_eventhub_dedicated" "test" { + name = "acctesteventhub-%d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = %d + message_retention = 1 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, partitionCount) +} + +func TestAccAzureRMEventHubDedicated_requiresImport(data acceptance.TestData) string { + template := TestAccAzureRMEventHubDedicated_basic(data, 2) + return fmt.Sprintf(` +%s + +resource "azurerm_eventhub_dedicated" "import" { + name = azurerm_eventhub.test.name + namespace_name = azurerm_eventhub.test.namespace_name + resource_group_name = azurerm_eventhub.test.resource_group_name + partition_count = azurerm_eventhub.test.partition_count + message_retention = azurerm_eventhub.test.message_retention +} +`, template) +} + +func TestAccAzureRMEventHubDedicated_partitionCountUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%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_dedicated" "test" { + name = "acctesteventhubnamespace-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} + +resource "azurerm_eventhub_dedicated" "test" { + name = "acctesteventhub-%d" + namespace_name = azurerm_eventhub_namespace_dedicated.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 10 + message_retention = 1 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func TestAccAzureRMEventHubDedicated_standard(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%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_dedicated" "test" { + name = "acctest-EHN%d" + clsuter_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + } + +resource "azurerm_eventhub_dedicated" "test" { + name = "acctest-EH-%d" + namespace_name = azurerm_eventhub_namespace_dedicated.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 7 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func TestAccAzureRMEventHubDedicated_captureDescription(data acceptance.TestData, enabled bool) string { + enabledString := strconv.FormatBool(enabled) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%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_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_container" "test" { + name = "acctest" + storage_account_name = azurerm_storage_account.test.name + container_access_type = "private" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctest-EHN%d" + clsuter_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} + +resource "azurerm_eventhub_dedicated" "test" { + name = "acctest-EH%d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 7 + + capture_description { + enabled = %s + encoding = "Avro" + interval_in_seconds = 60 + size_limit_in_bytes = 10485760 + skip_empty_archives = true + + destination { + name = "EventHubArchive.AzureBlockBlob" + archive_name_format = "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}" + blob_container_name = azurerm_storage_container.test.name + storage_account_id = azurerm_storage_account.test.id + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, enabledString) +} + +func TestAccAzureRMEventHubDedicated_messageRetentionUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%d" + location = "%s" +} + +resource "azurerm_eventhub_dedicated_namespace" "test" { + name = "acctest-EHN-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} + +resource "azurerm_eventhub_dedicated" "test" { + name = "acctest-EH-%d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 5 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go index 6e0d2704a45f..fc3b76b2e0e0 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_resource_test.go @@ -44,7 +44,7 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) { ErrCount: 0, }, { - Value: 1025, + Value: 33, ErrCount: 1, }, } @@ -88,7 +88,7 @@ func TestAccAzureRMEventHubMessageRetentionCount_validation(t *testing.T) { Value: 7, ErrCount: 0, }, { - Value: 91, + Value: 8, ErrCount: 1, }, } From 44934a3a54afac96b91aebfac1732d50db4d83f1 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 15:53:07 +0200 Subject: [PATCH 05/48] Fix tests --- .../tests/eventhub_dedicated_resource_test.go | 134 +++++++++--------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go index 4814eea8cb04..38389a8adf38 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -44,7 +44,7 @@ func TestAccAzureRMEventHubDedicatedPartitionCount_validation(t *testing.T) { ErrCount: 0, }, { - Value: 33, + Value: 1025, ErrCount: 1, }, } @@ -176,12 +176,12 @@ func TestAccAzureRMEventHubDedicated_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Config: testAccAzureRMEventHubDedicated_basic(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), ), }, data.ImportStep(), @@ -195,12 +195,12 @@ func TestAccAzureRMEventHubDedicated_basicOnePartition(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_basic(data, 1), + Config: testAccAzureRMEventHubDedicated_basic(data, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "1"), ), }, @@ -215,16 +215,16 @@ func TestAccAzureRMEventHubDedicated_requiresImport(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Config: testAccAzureRMEventHubDedicated_basic(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), ), }, { - Config: TestAccAzureRMEventHubDedicated_requiresImport(data), + Config: testAccAzureRMEventHubDedicated_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_eventhub_dedicated"), }, }, @@ -237,19 +237,19 @@ func TestAccAzureRMEventHubDedicated_partitionCountUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_basic(data, 2), + Config: testAccAzureRMEventHubDedicated_basic(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "2"), ), }, { - Config: TestAccAzureRMEventHubDedicated_partitionCountUpdate(data), + Config: testAccAzureRMEventHubDedicated_partitionCountUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "10"), ), }, @@ -263,12 +263,12 @@ func TestAccAzureRMEventHubDedicated_standard(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_standard(data), + Config: testAccAzureRMEventHubDedicated_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), ), }, data.ImportStep(), @@ -282,12 +282,12 @@ func TestAccAzureRMEventHubDedicated_captureDescription(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_captureDescription(data, true), + Config: testAccAzureRMEventHubDedicated_captureDescription(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.skip_empty_archives", "true"), ), @@ -303,19 +303,19 @@ func TestAccAzureRMEventHubDedicated_captureDescriptionDisabled(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_captureDescription(data, true), + Config: testAccAzureRMEventHubDedicated_captureDescription(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), ), }, { - Config: TestAccAzureRMEventHubDedicated_captureDescription(data, false), + Config: testAccAzureRMEventHubDedicated_captureDescription(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "false"), ), }, @@ -329,19 +329,19 @@ func TestAccAzureRMEventHubDedicated_messageRetentionUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMEventHubDestroy, + CheckDestroy: testCheckAzureRMEventHubDedicatedDestroy, Steps: []resource.TestStep{ { - Config: TestAccAzureRMEventHubDedicated_standard(data), + Config: testAccAzureRMEventHubDedicated_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "7"), ), }, { - Config: TestAccAzureRMEventHubDedicated_messageRetentionUpdate(data), + Config: testAccAzureRMEventHubDedicated_messageRetentionUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(data.ResourceName), + testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "5"), ), }, @@ -349,7 +349,7 @@ func TestAccAzureRMEventHubDedicated_messageRetentionUpdate(t *testing.T) { }) } -func testCheckAzureRMEventHubDestroy(s *terraform.State) error { +func testCheckAzureRMEventHubDedicatedDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.EventHubsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -376,7 +376,7 @@ func testCheckAzureRMEventHubDestroy(s *terraform.State) error { return nil } -func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMEventHubDedicatedExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.EventHubsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -407,7 +407,7 @@ func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc } } -func TestAccAzureRMEventHubDedicated_basic(data acceptance.TestData, partitionCount int) string { +func testAccAzureRMEventHubDedicated_basic(data acceptance.TestData, partitionCount int) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -419,10 +419,10 @@ resource "azurerm_resource_group" "test" { } 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" + 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_dedicated" "test" { @@ -440,11 +440,11 @@ resource "azurerm_eventhub_dedicated" "test" { partition_count = %d message_retention = 1 } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, partitionCount) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, partitionCount) } -func TestAccAzureRMEventHubDedicated_requiresImport(data acceptance.TestData) string { - template := TestAccAzureRMEventHubDedicated_basic(data, 2) +func testAccAzureRMEventHubDedicated_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventHubDedicated_basic(data, 2) return fmt.Sprintf(` %s @@ -458,7 +458,7 @@ resource "azurerm_eventhub_dedicated" "import" { `, template) } -func TestAccAzureRMEventHubDedicated_partitionCountUpdate(data acceptance.TestData) string { +func testAccAzureRMEventHubDedicated_partitionCountUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -470,10 +470,10 @@ resource "azurerm_resource_group" "test" { } 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" + 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_dedicated" "test" { @@ -491,10 +491,10 @@ resource "azurerm_eventhub_dedicated" "test" { partition_count = 10 message_retention = 1 } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func TestAccAzureRMEventHubDedicated_standard(data acceptance.TestData) string { +func testAccAzureRMEventHubDedicated_standard(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -506,19 +506,19 @@ resource "azurerm_resource_group" "test" { } 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" + 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_dedicated" "test" { - name = "acctest-EHN%d" - clsuter_id = azurerm_eventhub_cluster.test.id - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Standard" - } + name = "acctest-EHN%d" + clsuter_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} resource "azurerm_eventhub_dedicated" "test" { name = "acctest-EH-%d" @@ -527,10 +527,10 @@ resource "azurerm_eventhub_dedicated" "test" { partition_count = 2 message_retention = 7 } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func TestAccAzureRMEventHubDedicated_captureDescription(data acceptance.TestData, enabled bool) string { +func testAccAzureRMEventHubDedicated_captureDescription(data acceptance.TestData, enabled bool) string { enabledString := strconv.FormatBool(enabled) return fmt.Sprintf(` provider "azurerm" { @@ -543,10 +543,10 @@ resource "azurerm_resource_group" "test" { } 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" + name = "acctesteventhubclusTER-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" } resource "azurerm_storage_account" "test" { @@ -593,10 +593,10 @@ resource "azurerm_eventhub_dedicated" "test" { } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, enabledString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, enabledString) } -func TestAccAzureRMEventHubDedicated_messageRetentionUpdate(data acceptance.TestData) string { +func testAccAzureRMEventHubDedicated_messageRetentionUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} From 9680d019d92ccbb8cf898b284fe1fb3bfe713ffc Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 16:07:59 +0200 Subject: [PATCH 06/48] Revert error messages to what they should be --- .../internal/services/eventhub/eventhub_dedicated_resource.go | 4 ++-- azurerm/internal/services/eventhub/eventhub_resource.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index e5bb701cc49b..6ae670322722 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -274,7 +274,7 @@ func ValidateEventHubDedicatedPartitionCount(v interface{}, _ string) (warnings value := v.(int) if !(1024 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32 for standard hubs and 1024 for Event Hubs Clusters")) + errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 1024")) } return warnings, errors @@ -284,7 +284,7 @@ func ValidateEventHubDedicatedMessageRetentionCount(v interface{}, _ string) (wa value := v.(int) if !(90 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7 for standard hubs and 90 for Event Hubs Clusters")) + errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 90")) } return warnings, errors diff --git a/azurerm/internal/services/eventhub/eventhub_resource.go b/azurerm/internal/services/eventhub/eventhub_resource.go index 043c49aaca6c..99412de2b860 100644 --- a/azurerm/internal/services/eventhub/eventhub_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_resource.go @@ -274,7 +274,7 @@ func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, value := v.(int) if !(32 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32 for standard hubs and 1024 for Event Hubs Clusters")) + errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 1 and 32")) } return warnings, errors @@ -284,7 +284,7 @@ func ValidateEventHubMessageRetentionCount(v interface{}, _ string) (warnings [] value := v.(int) if !(7 >= value && value >= 1) { - errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7 for standard hubs and 90 for Event Hubs Clusters")) + errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7")) } return warnings, errors From 50dd95a7492c09f4208355cb25735c687e30debf Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 16:37:15 +0200 Subject: [PATCH 07/48] Add tests --- ...nthub_namespace_dedicated_resource_test.go | 895 ++++++++++++++++++ 1 file changed, 895 insertions(+) create mode 100644 azurerm/internal/services/eventhub/tests/eventhub_namespace_dedicated_resource_test.go diff --git a/azurerm/internal/services/eventhub/tests/eventhub_namespace_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_namespace_dedicated_resource_test.go new file mode 100644 index 000000000000..40660366e8a8 --- /dev/null +++ b/azurerm/internal/services/eventhub/tests/eventhub_namespace_dedicated_resource_test.go @@ -0,0 +1,895 @@ +package tests + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMEventHubNamespaceDedicated_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_eventhub_namespace_dedicated"), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_standard(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_standard(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_networkrule_iprule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_networkrule_iprule(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_networkrule_vnet(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_networkrule_vnet(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_networkruleVnetIpRule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_networkruleVnetIpRule(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rulesets.0.virtual_network_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rulesets.0.ip_rule.#", "2"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_readDefaultKeys(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_key", regexp.MustCompile(".+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_key", regexp.MustCompile(".+")), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_withAliasConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + // `default_primary_connection_string_alias` and `default_secondary_connection_string_alias` are still `nil` in `azurerm_eventhub_namespace_dedicated` after created `azurerm_eventhub_namespace_dedicated` successfully since `azurerm_eventhub_namespace_dedicated_disaster_recovery_config` hasn't been created. + // So these two properties should be checked in the second run. + Config: testAccAzureRMEventHubNamespaceDedicated_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_withAliasConnectionString(data), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_connection_string_alias", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_connection_string_alias", regexp.MustCompile("Endpoint=.+")), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnits(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnits(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_NonStandardCasing(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicatedNonStandardCasing(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists("azurerm_eventhub_namespace_dedicated.test"), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicatedNonStandardCasing(data), + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_BasicWithTagsUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_basicWithTagsUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_BasicWithCapacity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_capacity(data, 20), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "20"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_BasicWithCapacityUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_capacity(data, 20), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "20"), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_capacity(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_BasicWithSkuUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_standard(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnitsUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnits(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "20"), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnitsUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "1"), + ), + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceDedicated_autoInfalteDisabledWithAutoInflateUnits(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_dedicated", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDedicatedDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceDedicated_autoInfalteDisabledWithAutoInflateUnits(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceDedicatedExists(data.ResourceName), + ), + }, + }, + }) +} + +func testCheckAzureRMEventHubNamespaceDedicatedDestroy(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.NamespacesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_eventhub_namespace_dedicated" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return err + } + } + } + + return nil +} + +func testCheckAzureRMEventHubNamespaceDedicatedExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Eventhub.NamespacesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + namespaceName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Event Hub Namespace: %s", namespaceName) + } + + resp, err := conn.Get(ctx, resourceGroup, namespaceName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Event Hub Namespace %q (resource group: %q) does not exist", namespaceName, resourceGroup) + } + + return fmt.Errorf("Bad: Get on EventHubNamespaceDedicatedsClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMEventHubNamespaceDedicated_basic(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_withAliasConnectionString(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-ehn-%[1]d" + location = "%[2]s" +} + +resource "azurerm_resource_group" "test2" { + name = "acctestRG2-ehn-%[1]d" + location = "%[3]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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%[1]d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_dedicated" "test2" { + name = "acctestEventHubNamespaceDedicated2-%[1]d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_dedicated_disaster_recovery_config" "test" { + name = "acctest-EHN-DRC-%[1]d" + resource_group_name = azurerm_resource_group.test.name + cluster_id = azurerm_eventhub_cluster.test.id + namespace_name = azurerm_eventhub_namespace_dedicated.test.name + partner_namespace_id = azurerm_eventhub_namespace_dedicated.test2.id +} +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventHubNamespaceDedicated_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_eventhub_namespace_dedicated" "import" { + name = azurerm_eventhub_namespace_dedicated.test.name + location = azurerm_eventhub_namespace_dedicated.test.location + resource_group_name = azurerm_eventhub_namespace_dedicated.test.resource_group_name + sku = azurerm_eventhub_namespace_dedicated.test.sku + cluster_id = azurerm_eventhub_namespace_dedicated.test.cluster_id +} +`, template) +} + +func testAccAzureRMEventHubNamespaceDedicated_standard(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = "2" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_networkrule_iprule(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = "2" + + network_rulesets { + default_action = "Deny" + ip_rule { + ip_mask = "10.0.0.0/16" + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_networkrule_vnet(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%[1]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_eventhub_cluster" "test" { + name = "acctesteventhubclusTER-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" +} + +resource "azurerm_eventhub_namespace_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%[1]d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = "2" + + network_rulesets { + default_action = "Deny" + virtual_network_rule { + subnet_id = azurerm_subnet.test.id + + ignore_missing_virtual_network_service_endpoint = true + } + } +} +`, data.RandomInteger, data.Locations.Primary) +} + +func testAccAzureRMEventHubNamespaceDedicated_networkruleVnetIpRule(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn1-%[1]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "acctsub1-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" + service_endpoints = ["Microsoft.EventHub"] +} + +resource "azurerm_virtual_network" "test2" { + name = "acctvn2-%[1]d" + address_space = ["10.1.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test2" { + name = "acctsub2-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test2.name + address_prefix = "10.1.1.0/24" + service_endpoints = ["Microsoft.EventHub"] +} + +resource "azurerm_eventhub_cluster" "test" { + name = "acctesteventhubclusTER-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" +} + +resource "azurerm_eventhub_namespace_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%[1]d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = "2" + + network_rulesets { + default_action = "Deny" + + virtual_network_rule { + subnet_id = azurerm_subnet.test.id + } + + virtual_network_rule { + subnet_id = azurerm_subnet.test2.id + } + + ip_rule { + ip_mask = "10.0.1.0/24" + } + + ip_rule { + ip_mask = "10.1.1.0/24" + } + } +} +`, data.RandomInteger, data.Locations.Primary) +} + +func testAccAzureRMEventHubNamespaceDedicatedNonStandardCasing(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "basic" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnits(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + 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 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_basicWithTagsUpdate(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" + + tags = { + environment = "Production" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_capacity(data acceptance.TestData, capacity int) 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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" + capacity = %d +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, capacity) +} + +func testAccAzureRMEventHubNamespaceDedicated_maximumThroughputUnitsUpdate(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = 1 + auto_inflate_enabled = true + maximum_throughput_units = 1 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMEventHubNamespaceDedicated_autoInfalteDisabledWithAutoInflateUnits(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_dedicated" "test" { + name = "acctestEventHubNamespaceDedicated-%d" + cluster_id = azurerm_eventhub_cluster.test.id + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" + capacity = 1 + auto_inflate_enabled = false + maximum_throughput_units = 0 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} From b8d104143b75fdbe30c1013c34d87ae3aaf00ce5 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 16:42:57 +0200 Subject: [PATCH 08/48] Fix typos, add registration --- .../services/eventhub/eventhub_dedicated_resource.go | 2 +- .../eventhub/eventhub_namespace_dedicated_resource.go | 2 +- azurerm/internal/services/eventhub/registration.go | 5 ++++- website/docs/r/blueprint_assignment.html.markdown | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index 6ae670322722..3e63b1d5f909 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -20,7 +20,7 @@ import ( var eventHubDedicatedResourceName = "azurerm_eventhub_dedicated" -func resourceArmEventHubDedicatedDedicated() *schema.Resource { +func resourceArmEventHubDedicated() *schema.Resource { return &schema.Resource{ Create: resourceArmEventHubDedicatedCreateUpdate, Read: resourceArmEventHubDedicatedRead, diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 9bb2fd573aa4..f633ee6e360d 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -27,7 +27,7 @@ import ( var eventHubNamespaceDedicatedDefaultAuthorizationRule = "RootManageSharedAccessKey" var eventHubNamespaceDedicatedResourceName = "azurerm_eventhub_namespace" -func resourceArmeventHubNamespaceDedicated() *schema.Resource { +func resourceArmEventHubNamespaceDedicated() *schema.Resource { return &schema.Resource{ Create: resourceArmeventHubNamespaceDedicatedCreateUpdate, Read: resourceArmeventHubNamespaceDedicatedRead, diff --git a/azurerm/internal/services/eventhub/registration.go b/azurerm/internal/services/eventhub/registration.go index 9992df41ec4e..97c71eb5277a 100644 --- a/azurerm/internal/services/eventhub/registration.go +++ b/azurerm/internal/services/eventhub/registration.go @@ -38,5 +38,8 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), - "azurerm_eventhub": resourceArmEventHub()} + "azurerm_eventhub": resourceArmEventHub(), + "azurerm_eventhub_namespace_dedicated": resourceArmEventHubNamespaceDedicated(), + "azurerm_eventhub_dedicated": resourceArmEventHubDedicated(), + } } diff --git a/website/docs/r/blueprint_assignment.html.markdown b/website/docs/r/blueprint_assignment.html.markdown index f2046a0c73ef..0055a87146c5 100644 --- a/website/docs/r/blueprint_assignment.html.markdown +++ b/website/docs/r/blueprint_assignment.html.markdown @@ -162,4 +162,4 @@ Azure Blueprint Assignments can be imported using the `resource id`, e.g. ```shell terraform import azurerm_blueprint_assignment.example "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint" -``` \ No newline at end of file +``` From 2401a4933432d5936af9d595d216af373e3f2024 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 17:40:34 +0200 Subject: [PATCH 09/48] More typoes, set locks for both normal and dedicated hubs and namespaces --- .../eventhub/eventhub_authorization_rule_resource.go | 6 ++++++ .../services/eventhub/eventhub_dedicated_resource.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index 7a6d09b4050f..9e1d28e74d34 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -95,6 +95,12 @@ func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, me locks.ByName(namespaceName, eventHubNamespaceResourceName) defer locks.UnlockByName(namespaceName, eventHubNamespaceResourceName) + locks.ByName(eventHubName, eventHubDedicatedResourceName) + defer locks.UnlockByName(eventHubName, eventHubDedicatedResourceName) + + locks.ByName(namespaceName, eventHubNamespaceDedicatedResourceName) + defer locks.UnlockByName(namespaceName, eventHubNamespaceDedicatedResourceName) + parameters := eventhub.AuthorizationRule{ Name: &name, AuthorizationRuleProperties: &eventhub.AuthorizationRuleProperties{ diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index 3e63b1d5f909..48e7fe2404a8 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -184,7 +184,7 @@ func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta inter } if _, ok := d.GetOk("capture_description"); ok { - parameters.Properties.CaptureDescription = expandEventHubCaptureDescription(d) + parameters.Properties.CaptureDescription = expandEventHubDedicatedCaptureDescription(d) } if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil { From d049c1cb30aa97c668ed2e56e97ca553b1ab2b45 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 18:24:51 +0200 Subject: [PATCH 10/48] Fix last linter error --- .../internal/services/eventhub/eventhub_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index 48e7fe2404a8..7746747bf824 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -236,7 +236,7 @@ func resourceArmEventHubDedicatedRead(d *schema.ResourceData, meta interface{}) d.Set("message_retention", props.MessageRetentionInDays) d.Set("partition_ids", props.PartitionIds) - captureDescription := flattenEventHubCaptureDescription(props.CaptureDescription) + captureDescription := flattenEventHubDedicatedCaptureDescription(props.CaptureDescription) if err := d.Set("capture_description", captureDescription); err != nil { return err } From 1b2f13939bfa832c465af46189bbfc9dc4c3ad0f Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 22:05:20 +0200 Subject: [PATCH 11/48] Added documentation --- website/azurerm.erb | 12 +- website/docs/r/eventhub_cluster.html.markdown | 4 +- .../docs/r/eventhub_dedicated.html.markdown | 121 ++++++++++++++++ ...eventhub_namespace_dedicated.html.markdown | 134 ++++++++++++++++++ 4 files changed, 267 insertions(+), 4 deletions(-) create mode 100644 website/docs/r/eventhub_dedicated.html.markdown create mode 100644 website/docs/r/eventhub_namespace_dedicated.html.markdown diff --git a/website/azurerm.erb b/website/azurerm.erb index f4a86ad256e5..8f863aa4bded 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -532,7 +532,7 @@
  • azurerm_servicebus_namespace_authorization_rule
  • - +
  • azurerm_servicebus_topic_authorization_rule
  • @@ -1891,7 +1891,7 @@
  • azurerm_eventgrid_domain
  • - +
  • azurerm_eventgrid_domain_topic
  • @@ -1908,6 +1908,10 @@ azurerm_eventhub +
  • + azurerm_eventhub_dedicated +
  • +
  • azurerm_eventhub_authorization_rule
  • @@ -1928,6 +1932,10 @@ azurerm_eventhub_namespace +
  • + azurerm_eventhub_namespace_dedicated +
  • +
  • azurerm_eventhub_namespace_authorization_rule
  • diff --git a/website/docs/r/eventhub_cluster.html.markdown b/website/docs/r/eventhub_cluster.html.markdown index 3152be8fd788..b06f61ceff65 100644 --- a/website/docs/r/eventhub_cluster.html.markdown +++ b/website/docs/r/eventhub_cluster.html.markdown @@ -19,8 +19,8 @@ resource "azurerm_resource_group" "example" { location = "West US 2" } -resource "azurerm_eventhub_cluster" "test" { - name = "acctesteventhubcluster-%d" +resource "azurerm_eventhub_cluster" "example" { + name = "eventhubclusterexample" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location sku_name = "Dedicated_1" diff --git a/website/docs/r/eventhub_dedicated.html.markdown b/website/docs/r/eventhub_dedicated.html.markdown new file mode 100644 index 000000000000..eed132fd0fd8 --- /dev/null +++ b/website/docs/r/eventhub_dedicated.html.markdown @@ -0,0 +1,121 @@ +--- +subcategory: "Messaging" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_eventhub_dedicated" +description: |- + Manages a Event Hubs as a nested resource within an Event Hubs namespace on an Event Hubs Cluster. +--- + +# azurerm_eventhub_cluster + +Manages a Event Hubs as a nested resource within an Event Hubs namespace on an Event Hubs Cluster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "resourceGroup1" + location = "West US" +} + +resource "azurerm_eventhub_cluster" "example" { + name = "eventhubclusterexample" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" +} + + +resource "azurerm_eventhub_namespace_dedicated" "example" { + name = "acceptanceTestEventHubNamespace" + cluster_id = azurerm_eventhub_cluster.example.id + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "Standard" + capacity = 1 + + tags = { + environment = "Production" + } +} + +resource "azurerm_eventhub" "example" { + name = "acceptanceTestEventHub" + namespace_name = azurerm_eventhub_namespace.example.name + resource_group_name = azurerm_resource_group.example.name + partition_count = 2 + message_retention = 1 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the EventHub Namespace resource. Changing this forces a new resource to be created. + +* `namespace_name` - (Required) Specifies the name of the EventHub Namespace. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the EventHub's parent Namespace exists. Changing this forces a new resource to be created. + +* `partition_count` - (Required) Specifies the current number of shards on the Event Hub. Needs to be between 1 and 1024. 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 90 days; or 1 day when using a Basic SKU for the parent EventHub Namespace. + +* `capture_description` - (Optional) A `capture_description` block as defined below. + +--- + +A `capture_description` block supports the following: + +* `enabled` - (Required) Specifies if the Capture Description is Enabled. + +* `encoding` - (Required) Specifies the Encoding used for the Capture Description. Possible values are `Avro` and `AvroDeflate`. + +* `interval_in_seconds` - (Optional) Specifies the time interval in seconds at which the capture will happen. Values can be between `60` and `900` seconds. Defaults to `300` seconds. + +* `size_limit_in_bytes` - (Optional) Specifies the amount of data built up in your EventHub before a Capture Operation occurs. Value should be between `10485760` and `524288000` bytes. Defaults to `314572800` bytes. + +* `skip_empty_archives` - (Optional) Specifies if empty files should not be emitted if no events occur during the Capture time window. Defaults to `false`. + +* `destination` - (Required) A `destination` block as defined below. + +A `destination` block supports the following: + +* `name` - (Required) The Name of the Destination where the capture should take place. At this time the only supported value is `EventHubArchive.AzureBlockBlob`. + +-> At this time it's only possible to Capture EventHub messages to Blob Storage. There's [a Feature Request for the Azure SDK to add support for Capturing messages to Azure Data Lake here](https://github.com/Azure/azure-rest-api-specs/issues/2255). + +* `archive_name_format` - The Blob naming convention for archiving. e.g. `{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}`. Here all the parameters (Namespace,EventHub .. etc) are mandatory irrespective of order + +* `blob_container_name` - (Required) The name of the Container within the Blob Storage Account where messages should be archived. + +* `storage_account_id` - (Required) The ID of the Blob Storage Account where messages should be archived. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the EventHub. + +* `partition_ids` - The identifiers for partitions created for Event Hubs. + + +## Timeouts + + + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the EventHub. +* `update` - (Defaults to 30 minutes) Used when updating the EventHub. +* `read` - (Defaults to 5 minutes) Used when retrieving the EventHub. +* `delete` - (Defaults to 30 minutes) Used when deleting the EventHub. + +## Import + +EventHubs can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_eventhub.eventhub1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/eventhubs/eventhub1 +``` diff --git a/website/docs/r/eventhub_namespace_dedicated.html.markdown b/website/docs/r/eventhub_namespace_dedicated.html.markdown new file mode 100644 index 000000000000..6646c5961ab6 --- /dev/null +++ b/website/docs/r/eventhub_namespace_dedicated.html.markdown @@ -0,0 +1,134 @@ +--- +subcategory: "Messaging" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_eventhub_namespace_dedicated" +description: |- + Manages an EventHub Namespace on a dedicated Event Hubs Cluster. +--- + +# azurerm_eventhub_namespace_dedicated + +Manages an EventHub Namespace on a dedicated Event Hubs Cluster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_eventhub_cluster" "example" { + name = "eventhubclusterexample" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku_name = "Dedicated_1" +} + +resource "azurerm_eventhub_namespace_dedicated" "example" { + name = "example-namespace" + cluster_id = azurerm_eventhub_cluster.example.id + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "Standard" + capacity = 2 + + tags = { + environment = "Production" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `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. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +* `cluster_id` - (Required) Specifies ID of an Event Hubs Cluster on which the namespace should be created. Changing this forces a new resource to be created. + +* `sku` - (Required) Defines which tier to use. Valid options are `Basic` and `Standard`. + +* `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. + +* `network_rulesets` - (Optional) A `network_rulesets` block as defined below. + +--- + +A `network_rulesets` block supports the following: + +* `default_action` - (Required) The default action to take when a rule is not matched. Possible values are `Allow` and `Deny`. Defaults to `Deny`. + +* `virtual_network_rule` - (Optional) One or more `virtual_network_rule` blocks as defined below. + +* `ip_rule` - (Optional) One or more `ip_rule` blocks as defined below. + +--- + +A `virtual_network_rule` block supports the following: + +* `subnet_id` - (Required) The id of the subnet to match on. + +* `ignore_missing_virtual_network_service_endpoint` - (Optional) Are missing virtual network service endpoints ignored? Defaults to `false`. + +--- + +A `ip_rule` block supports the following: + +* `ip_mask` - (Required) The ip mask to match on. + +* `action` - (Optional) The action to take when the rule is matched. Possible values are `Allow`. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The EventHub Namespace ID. + +The following attributes are exported only if there is an authorization rule named +`RootManageSharedAccessKey` which is created automatically by Azure. + +* `default_primary_connection_string` - The primary connection string for the authorization + rule `RootManageSharedAccessKey`. + +* `default_primary_connection_string_alias` - The alias of the primary connection string for the authorization + rule `RootManageSharedAccessKey`, which is generated when disaster recovery is enabled. + +* `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. + +* `default_secondary_connection_string` - The secondary connection string for the + authorization rule `RootManageSharedAccessKey`. + +* `default_secondary_connection_string_alias` - The alias of the secondary connection string for the + authorization rule `RootManageSharedAccessKey`, which is generated when disaster recovery is enabled. + +* `default_secondary_key` - The secondary access key for the authorization rule `RootManageSharedAccessKey`. + +## Timeouts + + + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the EventHub Namespace. +* `update` - (Defaults to 30 minutes) Used when updating the EventHub Namespace. +* `read` - (Defaults to 5 minutes) Used when retrieving the EventHub Namespace. +* `delete` - (Defaults to 30 minutes) Used when deleting the EventHub Namespace. + +## Import + +EventHub Namespaces can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_eventhub_namespace.namespace1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1 +``` From 6b42455c584c79a5b66fff5c2692c20c9e25dbf5 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 22:21:14 +0200 Subject: [PATCH 12/48] Update CHANGELOG --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f6a76da1d1..8d0323018bb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ ## 2.16.0 (Unreleased) -ENHANCEMENTS +FEATURES: +* **New Resource:** `azurerm_eventhub_dedicated` [GH-7347] +* **New Resource:** `azurerm_eventhub_namespace_dedicated` [GH-7347] + +ENHANCEMENTS * `azurerm_kusto_cluster` - Support for `identity` [GH-7367] -BUG FIXES: +BUG FIXES: * `azurerm_role_definition` - terraform import now sets scope to prevent a force recreate [GH-7424] @@ -56,7 +60,7 @@ UPGRADE NOTES: * `azurerm_kubernetes_cluster` - the Azure Policy add-on now only supports `v2` (as per the Azure API) ([#7233](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7233)) -DEPENDENCIES: +DEPENDENCIES: * `containerservice` - updating to `2020-03-01` ([#7233](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7233)) * `policy` - updating to `2019-09-01` ([#7211](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7211)) From 5689261f1a63c5784a98cf19fbea9eca4a8b29bf Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 22 Jun 2020 22:46:21 +0200 Subject: [PATCH 13/48] Sigh, more typoes --- website/docs/r/eventhub_dedicated.html.markdown | 4 ++-- website/docs/r/eventhub_namespace_dedicated.html.markdown | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/eventhub_dedicated.html.markdown b/website/docs/r/eventhub_dedicated.html.markdown index eed132fd0fd8..77399ed36511 100644 --- a/website/docs/r/eventhub_dedicated.html.markdown +++ b/website/docs/r/eventhub_dedicated.html.markdown @@ -6,7 +6,7 @@ description: |- Manages a Event Hubs as a nested resource within an Event Hubs namespace on an Event Hubs Cluster. --- -# azurerm_eventhub_cluster +# azurerm_eventhub_dedicated Manages a Event Hubs as a nested resource within an Event Hubs namespace on an Event Hubs Cluster. @@ -117,5 +117,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d EventHubs can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_eventhub.eventhub1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/eventhubs/eventhub1 +terraform import azurerm_eventhub_dedicated.eventhub1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/eventhubs/eventhub1 ``` diff --git a/website/docs/r/eventhub_namespace_dedicated.html.markdown b/website/docs/r/eventhub_namespace_dedicated.html.markdown index 6646c5961ab6..4685fea78d12 100644 --- a/website/docs/r/eventhub_namespace_dedicated.html.markdown +++ b/website/docs/r/eventhub_namespace_dedicated.html.markdown @@ -130,5 +130,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d EventHub Namespaces can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_eventhub_namespace.namespace1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1 +terraform import azurerm_eventhub_namespace_dedicated.namespace1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1 ``` From 2d0372e8e5bfbb6b66079db1d5cd8974f6374da0 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 12:59:31 +0200 Subject: [PATCH 14/48] Update website/docs/r/eventhub_dedicated.html.markdown Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- website/docs/r/eventhub_dedicated.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/eventhub_dedicated.html.markdown b/website/docs/r/eventhub_dedicated.html.markdown index 77399ed36511..ecc274507aee 100644 --- a/website/docs/r/eventhub_dedicated.html.markdown +++ b/website/docs/r/eventhub_dedicated.html.markdown @@ -39,9 +39,9 @@ resource "azurerm_eventhub_namespace_dedicated" "example" { } } -resource "azurerm_eventhub" "example" { +resource "azurerm_eventhub_dedicated" "example" { name = "acceptanceTestEventHub" - namespace_name = azurerm_eventhub_namespace.example.name + namespace_name = azurerm_eventhub_namespace_dedicated.example.name resource_group_name = azurerm_resource_group.example.name partition_count = 2 message_retention = 1 From ec54ba704f2c7fd66ad0357a3ec468f2f554236c Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 12:59:48 +0200 Subject: [PATCH 15/48] Update website/docs/r/eventhub_dedicated.html.markdown Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- website/docs/r/eventhub_dedicated.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/r/eventhub_dedicated.html.markdown b/website/docs/r/eventhub_dedicated.html.markdown index ecc274507aee..46e38e9af932 100644 --- a/website/docs/r/eventhub_dedicated.html.markdown +++ b/website/docs/r/eventhub_dedicated.html.markdown @@ -103,8 +103,6 @@ The following attributes are exported: ## Timeouts - - The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: * `create` - (Defaults to 30 minutes) Used when creating the EventHub. From a626c8376a9b7e1478217dd1d26fe488806dbc33 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:00:02 +0200 Subject: [PATCH 16/48] Update azurerm/internal/services/eventhub/eventhub_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../internal/services/eventhub/eventhub_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index 7746747bf824..84683226dba2 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -160,7 +160,7 @@ func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta inter namespaceName := d.Get("namespace_name").(string) resourceGroup := d.Get("resource_group_name").(string) - if features.ShouldResourcesBeImported() && d.IsNewResource() { + if d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, namespaceName, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { From b65f3c0a55b56df18b29085eca5fd0af0989cd99 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:10:46 +0200 Subject: [PATCH 17/48] Update website/docs/r/eventhub_dedicated.html.markdown Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- website/docs/r/eventhub_dedicated.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/eventhub_dedicated.html.markdown b/website/docs/r/eventhub_dedicated.html.markdown index 46e38e9af932..93425a4e16d7 100644 --- a/website/docs/r/eventhub_dedicated.html.markdown +++ b/website/docs/r/eventhub_dedicated.html.markdown @@ -60,7 +60,7 @@ The following arguments are supported: * `partition_count` - (Required) Specifies the current number of shards on the Event Hub. Needs to be between 1 and 1024. 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 90 days; or 1 day when using a Basic SKU for the parent EventHub Namespace. +* `message_retention` - (Required) Specifies the number of days to retain the events for this Event Hub. Needs to be between `1` and `90`. Only a value of `1` is allowed when using a Basic SKU for the parent EventHub Namespace. * `capture_description` - (Optional) A `capture_description` block as defined below. From 0b18f1e95ba81d5c88e3a3fcfaf5c2b165bd171a Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:11:02 +0200 Subject: [PATCH 18/48] Update website/docs/r/eventhub_namespace_dedicated.html.markdown Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- website/docs/r/eventhub_namespace_dedicated.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/website/docs/r/eventhub_namespace_dedicated.html.markdown b/website/docs/r/eventhub_namespace_dedicated.html.markdown index 4685fea78d12..e40d2b276741 100644 --- a/website/docs/r/eventhub_namespace_dedicated.html.markdown +++ b/website/docs/r/eventhub_namespace_dedicated.html.markdown @@ -116,8 +116,6 @@ The following attributes are exported only if there is an authorization rule nam ## Timeouts - - The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: * `create` - (Defaults to 30 minutes) Used when creating the EventHub Namespace. From 25f72f5588bf3014a104035a091c7467efabcd2a Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:18:30 +0200 Subject: [PATCH 19/48] Revert "Update CHANGELOG" This reverts commit 6b42455c584c79a5b66fff5c2692c20c9e25dbf5. --- CHANGELOG.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d0323018bb0..77f6a76da1d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,10 @@ ## 2.16.0 (Unreleased) -FEATURES: -* **New Resource:** `azurerm_eventhub_dedicated` [GH-7347] -* **New Resource:** `azurerm_eventhub_namespace_dedicated` [GH-7347] - -ENHANCEMENTS +ENHANCEMENTS * `azurerm_kusto_cluster` - Support for `identity` [GH-7367] -BUG FIXES: +BUG FIXES: * `azurerm_role_definition` - terraform import now sets scope to prevent a force recreate [GH-7424] @@ -60,7 +56,7 @@ UPGRADE NOTES: * `azurerm_kubernetes_cluster` - the Azure Policy add-on now only supports `v2` (as per the Azure API) ([#7233](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7233)) -DEPENDENCIES: +DEPENDENCIES: * `containerservice` - updating to `2020-03-01` ([#7233](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7233)) * `policy` - updating to `2019-09-01` ([#7211](https://github.com/terraform-providers/terraform-provider-azurerm/issues/7211)) From 1a6cdfe6904e2949f42a6cb5a7338dd5db99bfc6 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:19:07 +0200 Subject: [PATCH 20/48] Address review feedback --- .../eventhub/eventhub_dedicated_resource.go | 124 +----------------- .../tests/eventhub_dedicated_resource_test.go | 4 +- 2 files changed, 4 insertions(+), 124 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index 84683226dba2..f7030d7b2cfb 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -3,7 +3,6 @@ package eventhub import ( "fmt" "log" - "strings" "time" "github.com/Azure/azure-sdk-for-go/services/preview/eventhub/mgmt/2018-01-01-preview/eventhub" @@ -13,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "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/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -184,7 +182,7 @@ func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta inter } if _, ok := d.GetOk("capture_description"); ok { - parameters.Properties.CaptureDescription = expandEventHubDedicatedCaptureDescription(d) + parameters.Properties.CaptureDescription = expandEventHubCaptureDescription(d) } if _, err := client.CreateOrUpdate(ctx, resourceGroup, namespaceName, name, parameters); err != nil { @@ -236,7 +234,7 @@ func resourceArmEventHubDedicatedRead(d *schema.ResourceData, meta interface{}) d.Set("message_retention", props.MessageRetentionInDays) d.Set("partition_ids", props.PartitionIds) - captureDescription := flattenEventHubDedicatedCaptureDescription(props.CaptureDescription) + captureDescription := flattenEventHubCaptureDescription(props.CaptureDescription) if err := d.Set("capture_description", captureDescription); err != nil { return err } @@ -289,121 +287,3 @@ func ValidateEventHubDedicatedMessageRetentionCount(v interface{}, _ string) (wa return warnings, errors } - -func ValidateEventHubDedicatedArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) { - value := v.(string) - - requiredComponents := []string{ - "{Namespace}", - "{EventHub}", - "{PartitionId}", - "{Year}", - "{Month}", - "{Day}", - "{Hour}", - "{Minute}", - "{Second}", - } - - for _, component := range requiredComponents { - if !strings.Contains(value, component) { - errors = append(errors, fmt.Errorf("%s needs to contain %q", k, component)) - } - } - - return warnings, errors -} - -func expandEventHubDedicatedCaptureDescription(d *schema.ResourceData) *eventhub.CaptureDescription { - inputs := d.Get("capture_description").([]interface{}) - input := inputs[0].(map[string]interface{}) - - enabled := input["enabled"].(bool) - encoding := input["encoding"].(string) - intervalInSeconds := input["interval_in_seconds"].(int) - sizeLimitInBytes := input["size_limit_in_bytes"].(int) - skipEmptyArchives := input["skip_empty_archives"].(bool) - - captureDescription := eventhub.CaptureDescription{ - Enabled: utils.Bool(enabled), - Encoding: eventhub.EncodingCaptureDescription(encoding), - IntervalInSeconds: utils.Int32(int32(intervalInSeconds)), - SizeLimitInBytes: utils.Int32(int32(sizeLimitInBytes)), - SkipEmptyArchives: utils.Bool(skipEmptyArchives), - } - - if v, ok := input["destination"]; ok { - destinations := v.([]interface{}) - if len(destinations) > 0 { - destination := destinations[0].(map[string]interface{}) - - destinationName := destination["name"].(string) - archiveNameFormat := destination["archive_name_format"].(string) - blobContainerName := destination["blob_container_name"].(string) - storageAccountId := destination["storage_account_id"].(string) - - captureDescription.Destination = &eventhub.Destination{ - Name: utils.String(destinationName), - DestinationProperties: &eventhub.DestinationProperties{ - ArchiveNameFormat: utils.String(archiveNameFormat), - BlobContainer: utils.String(blobContainerName), - StorageAccountResourceID: utils.String(storageAccountId), - }, - } - } - } - - return &captureDescription -} - -func flattenEventHubDedicatedCaptureDescription(description *eventhub.CaptureDescription) []interface{} { - results := make([]interface{}, 0) - - if description != nil { - output := make(map[string]interface{}) - - if enabled := description.Enabled; enabled != nil { - output["enabled"] = *enabled - } - - if skipEmptyArchives := description.SkipEmptyArchives; skipEmptyArchives != nil { - output["skip_empty_archives"] = *skipEmptyArchives - } - - output["encoding"] = string(description.Encoding) - - if interval := description.IntervalInSeconds; interval != nil { - output["interval_in_seconds"] = *interval - } - - if size := description.SizeLimitInBytes; size != nil { - output["size_limit_in_bytes"] = *size - } - - if destination := description.Destination; destination != nil { - destinationOutput := make(map[string]interface{}) - - if name := destination.Name; name != nil { - destinationOutput["name"] = *name - } - - if props := destination.DestinationProperties; props != nil { - if archiveNameFormat := props.ArchiveNameFormat; archiveNameFormat != nil { - destinationOutput["archive_name_format"] = *archiveNameFormat - } - if blobContainerName := props.BlobContainer; blobContainerName != nil { - destinationOutput["blob_container_name"] = *blobContainerName - } - if storageAccountId := props.StorageAccountResourceID; storageAccountId != nil { - destinationOutput["storage_account_id"] = *storageAccountId - } - } - - output["destination"] = []interface{}{destinationOutput} - } - - results = append(results, output) - } - - return results -} diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go index 38389a8adf38..517c5fc46848 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -524,8 +524,8 @@ resource "azurerm_eventhub_dedicated" "test" { name = "acctest-EH-%d" namespace_name = azurerm_eventhub_namespace_dedicated.test.name resource_group_name = azurerm_resource_group.test.name - partition_count = 2 - message_retention = 7 + partition_count = 50 + message_retention = 50 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From 14c3576ebf400445c9c7f21354166d54d6820709 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:20:56 +0200 Subject: [PATCH 21/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index f633ee6e360d..f11045295a64 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -25,7 +25,7 @@ import ( // Default Authorization Rule/Policy created by Azure, used to populate the // default connection strings and keys var eventHubNamespaceDedicatedDefaultAuthorizationRule = "RootManageSharedAccessKey" -var eventHubNamespaceDedicatedResourceName = "azurerm_eventhub_namespace" +var eventHubNamespaceDedicatedResourceName = "azurerm_eventhub_namespace_dedicated" func resourceArmEventHubNamespaceDedicated() *schema.Resource { return &schema.Resource{ From 5c15c31be249ecbe7317b415efffcffce7bd1d1f Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:31:34 +0200 Subject: [PATCH 22/48] Update azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../eventhub/tests/eventhub_dedicated_resource_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go index 517c5fc46848..82b22f70a7e3 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -449,11 +449,11 @@ func testAccAzureRMEventHubDedicated_requiresImport(data acceptance.TestData) st %s resource "azurerm_eventhub_dedicated" "import" { - name = azurerm_eventhub.test.name - namespace_name = azurerm_eventhub.test.namespace_name - resource_group_name = azurerm_eventhub.test.resource_group_name - partition_count = azurerm_eventhub.test.partition_count - message_retention = azurerm_eventhub.test.message_retention + name = azurerm_eventhub_dedicated.test.name + namespace_name = azurerm_eventhub_dedicated.test.namespace_name + resource_group_name = azurerm_eventhub_dedicated.test.resource_group_name + partition_count = azurerm_eventhub_dedicated.test.partition_count + message_retention = azurerm_eventhub_dedicated.test.message_retention } `, template) } From f6230297493a976dcefce7ca64d3626602885019 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:35:42 +0200 Subject: [PATCH 23/48] Update azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/tests/eventhub_dedicated_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go index 82b22f70a7e3..46e88191cfb6 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -247,7 +247,7 @@ func TestAccAzureRMEventHubDedicated_partitionCountUpdate(t *testing.T) { ), }, { - Config: testAccAzureRMEventHubDedicated_partitionCountUpdate(data), + Config: testAccAzureRMEventHubDedicated_basic(data, 10), Check: resource.ComposeTestCheckFunc( testCheckAzureRMEventHubDedicatedExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "10"), From 9d12d6d98d689ac6d8efb2730083c4c49769d29d Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 24 Jun 2020 13:41:52 +0200 Subject: [PATCH 24/48] Address feedback batch 2 --- .../eventhub_namespace_dedicated_resource.go | 102 +--------------- .../services/eventhub/registration.go | 4 +- .../tests/eventhub_dedicated_resource_test.go | 115 +----------------- website/azurerm.erb | 14 +-- 4 files changed, 20 insertions(+), 215 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index f11045295a64..c4d2803ae667 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -24,7 +24,6 @@ import ( // Default Authorization Rule/Policy created by Azure, used to populate the // default connection strings and keys -var eventHubNamespaceDedicatedDefaultAuthorizationRule = "RootManageSharedAccessKey" var eventHubNamespaceDedicatedResourceName = "azurerm_eventhub_namespace_dedicated" func resourceArmEventHubNamespaceDedicated() *schema.Resource { @@ -276,7 +275,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m ruleSets, hasRuleSets := d.GetOk("network_rulesets") if hasRuleSets { rulesets := eventhub.NetworkRuleSet{ - NetworkRuleSetProperties: expandeventHubNamespaceDedicatedNetworkRuleset(ruleSets.([]interface{})), + NetworkRuleSetProperties: expandEventHubNamespaceNetworkRuleset(ruleSets.([]interface{})), } // cannot use network rulesets with the basic SKU @@ -340,11 +339,11 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error making Read request on EventHub Namespace %q Network Ruleset: %+v", name, err) } - if err := d.Set("network_rulesets", flatteneventHubNamespaceDedicatedNetworkRuleset(ruleset)); err != nil { + if err := d.Set("network_rulesets", flattenEventHubNamespaceNetworkRuleset(ruleset)); err != nil { return fmt.Errorf("Error setting `network_ruleset` for Evenhub Namespace %s: %v", name, err) } - keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDedicatedDefaultAuthorizationRule) + keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDefaultAuthorizationRule) if err != nil { log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q: %+v", name, err) } else { @@ -403,106 +402,15 @@ func eventHubNamespaceDedicatedStateStatusCodeRefreshFunc(ctx context.Context, c return func() (interface{}, string, error) { res, err := client.Get(ctx, resourceGroup, name) - log.Printf("Retrieving EventHub Namespace %q (Resource Group %q) returned Status %d", resourceGroup, name, res.StatusCode) + log.Printf("Retrieving Dedicated EventHub Namespace %q (RG %q, ClusterID %q) returned Status %d", name, resourceGroup, *res.ClusterArmID, res.StatusCode) if err != nil { if utils.ResponseWasNotFound(res.Response) { return res, strconv.Itoa(res.StatusCode), nil } - return nil, "", fmt.Errorf("Error polling for the status of the EventHub Namespace %q (RG: %q): %+v", name, resourceGroup, err) + return nil, "", fmt.Errorf("Error polling for the status of the Dedicated EventHub Namespace %q (RG: %q, ClusterID: %q): %+v", name, resourceGroup, *res.ClusterArmID, err) } return res, strconv.Itoa(res.StatusCode), nil } } - -func expandeventHubNamespaceDedicatedNetworkRuleset(input []interface{}) *eventhub.NetworkRuleSetProperties { - if len(input) == 0 { - return nil - } - - block := input[0].(map[string]interface{}) - - ruleset := eventhub.NetworkRuleSetProperties{ - DefaultAction: eventhub.DefaultAction(block["default_action"].(string)), - } - - if v, ok := block["virtual_network_rule"].([]interface{}); ok { - if len(v) > 0 { - var rules []eventhub.NWRuleSetVirtualNetworkRules - for _, r := range v { - rblock := r.(map[string]interface{}) - rules = append(rules, eventhub.NWRuleSetVirtualNetworkRules{ - Subnet: &eventhub.Subnet{ - ID: utils.String(rblock["subnet_id"].(string)), - }, - IgnoreMissingVnetServiceEndpoint: utils.Bool(rblock["ignore_missing_virtual_network_service_endpoint"].(bool)), - }) - } - - ruleset.VirtualNetworkRules = &rules - } - } - - if v, ok := block["ip_rule"].([]interface{}); ok { - if len(v) > 0 { - var rules []eventhub.NWRuleSetIPRules - for _, r := range v { - rblock := r.(map[string]interface{}) - rules = append(rules, eventhub.NWRuleSetIPRules{ - IPMask: utils.String(rblock["ip_mask"].(string)), - Action: eventhub.NetworkRuleIPAction(rblock["action"].(string)), - }) - } - - ruleset.IPRules = &rules - } - } - - return &ruleset -} - -func flatteneventHubNamespaceDedicatedNetworkRuleset(ruleset eventhub.NetworkRuleSet) []interface{} { - if ruleset.NetworkRuleSetProperties == nil { - return nil - } - - vnetBlocks := make([]interface{}, 0) - if vnetRules := ruleset.NetworkRuleSetProperties.VirtualNetworkRules; vnetRules != nil { - for _, vnetRule := range *vnetRules { - block := make(map[string]interface{}) - - if s := vnetRule.Subnet; s != nil { - if v := s.ID; v != nil { - block["subnet_id"] = *v - } - } - - if v := vnetRule.IgnoreMissingVnetServiceEndpoint; v != nil { - block["ignore_missing_virtual_network_service_endpoint"] = *v - } - - vnetBlocks = append(vnetBlocks, block) - } - } - ipBlocks := make([]interface{}, 0) - if ipRules := ruleset.NetworkRuleSetProperties.IPRules; ipRules != nil { - for _, ipRule := range *ipRules { - block := make(map[string]interface{}) - - block["action"] = string(ipRule.Action) - - if v := ipRule.IPMask; v != nil { - block["ip_mask"] = *v - } - - ipBlocks = append(ipBlocks, block) - } - } - - return []interface{}{map[string]interface{}{ - "default_action": string(ruleset.DefaultAction), - "virtual_network_rule": vnetBlocks, - "ip_rule": ipBlocks, - }} -} diff --git a/azurerm/internal/services/eventhub/registration.go b/azurerm/internal/services/eventhub/registration.go index 97c71eb5277a..c183eb11c3a0 100644 --- a/azurerm/internal/services/eventhub/registration.go +++ b/azurerm/internal/services/eventhub/registration.go @@ -35,11 +35,11 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), "azurerm_eventhub_cluster": resourceArmEventHubCluster(), "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_eventhub_dedicated": resourceArmEventHubDedicated(), "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), + "azurerm_eventhub_namespace_dedicated": resourceArmEventHubNamespaceDedicated(), "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), "azurerm_eventhub": resourceArmEventHub(), - "azurerm_eventhub_namespace_dedicated": resourceArmEventHubNamespaceDedicated(), - "azurerm_eventhub_dedicated": resourceArmEventHubDedicated(), } } diff --git a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go index 46e88191cfb6..1f78d9dea905 100644 --- a/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go +++ b/azurerm/internal/services/eventhub/tests/eventhub_dedicated_resource_test.go @@ -40,7 +40,7 @@ func TestAccAzureRMEventHubDedicatedPartitionCount_validation(t *testing.T) { ErrCount: 0, }, { - Value: 32, + Value: 1024, ErrCount: 0, }, { @@ -50,7 +50,7 @@ func TestAccAzureRMEventHubDedicatedPartitionCount_validation(t *testing.T) { } for _, tc := range cases { - _, errors := eventhub.ValidateEventHubPartitionCount(tc.Value, "azurerm_eventhub") + _, errors := eventhub.ValidateEventHubDedicatedPartitionCount(tc.Value, "azurerm_eventhub") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM EventHub Partition Count to trigger a validation error") @@ -85,7 +85,7 @@ func TestAccAzureRMEventHubDedicatedMessageRetentionCount_validation(t *testing. Value: 6, ErrCount: 0, }, { - Value: 7, + Value: 90, ErrCount: 0, }, { Value: 91, @@ -94,7 +94,7 @@ func TestAccAzureRMEventHubDedicatedMessageRetentionCount_validation(t *testing. } for _, tc := range cases { - _, errors := eventhub.ValidateEventHubMessageRetentionCount(tc.Value, "azurerm_eventhub") + _, errors := eventhub.ValidateEventHubDedicatedMessageRetentionCount(tc.Value, "azurerm_eventhub") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM EventHub Message Retention Count to trigger a validation error") @@ -102,74 +102,6 @@ func TestAccAzureRMEventHubDedicatedMessageRetentionCount_validation(t *testing. } } -func TestAccAzureRMEventHubDedicatedArchiveNameFormat_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "", - ErrCount: 9, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 0, - }, - { - Value: "Prod_{Eventub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Month}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}/{Day}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Hour}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Minute}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Second}", - ErrCount: 1, - }, - { - Value: "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := eventhub.ValidateEventHubArchiveNameFormat(tc.Value, "azurerm_eventhub") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected %q to trigger a validation error", tc.Value) - } - } -} - func TestAccAzureRMEventHubDedicated_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventhub_dedicated", "test") @@ -390,6 +322,7 @@ func testCheckAzureRMEventHubDedicatedExists(resourceName string) resource.TestC name := rs.Primary.Attributes["name"] namespaceName := rs.Primary.Attributes["namespace_name"] resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + clusterID := rs.Primary.Attributes["cluster_id"] if !hasResourceGroup { return fmt.Errorf("Bad: no resource group found in state for Event Hub: %s", name) } @@ -400,7 +333,7 @@ func testCheckAzureRMEventHubDedicatedExists(resourceName string) resource.TestC } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Event Hub %q (namespace %q / resource group: %q) does not exist", name, namespaceName, resourceGroup) + return fmt.Errorf("Bad: Event Hub %q (namespace %q / resource group: %q / clusterID: %q) does not exist", name, namespaceName, resourceGroup, clusterID) } return nil @@ -458,42 +391,6 @@ resource "azurerm_eventhub_dedicated" "import" { `, template) } -func testAccAzureRMEventHubDedicated_partitionCountUpdate(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-eventhub-%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_dedicated" "test" { - name = "acctesteventhubnamespace-%d" - cluster_id = azurerm_eventhub_cluster.test.id - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - sku = "Basic" -} - -resource "azurerm_eventhub_dedicated" "test" { - name = "acctesteventhub-%d" - namespace_name = azurerm_eventhub_namespace_dedicated.test.name - resource_group_name = azurerm_resource_group.test.name - partition_count = 10 - message_retention = 1 -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - func testAccAzureRMEventHubDedicated_standard(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/azurerm.erb b/website/azurerm.erb index 8f863aa4bded..7df36e187e37 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -1909,27 +1909,27 @@
  • - azurerm_eventhub_dedicated + azurerm_eventhub_authorization_rule
  • - azurerm_eventhub_authorization_rule + azurerm_eventhub_cluster
  • - azurerm_eventhub_namespace_disaster_recovery_config + azurerm_eventhub_consumer_group
  • - azurerm_eventhub_cluster + azurerm_eventhub_dedicated
  • - azurerm_eventhub_consumer_group + azurerm_eventhub_namespace
  • - azurerm_eventhub_namespace + azurerm_eventhub_namespace_authorization_rule
  • @@ -1937,7 +1937,7 @@
  • - azurerm_eventhub_namespace_authorization_rule + azurerm_eventhub_namespace_disaster_recovery_config
  • From dbce63e9c3dfade870f27e95542cd9422e056549 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:38:56 +0200 Subject: [PATCH 25/48] Update azurerm/internal/services/eventhub/eventhub_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../internal/services/eventhub/eventhub_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go index f7030d7b2cfb..6bc21ff99967 100644 --- a/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_dedicated_resource.go @@ -162,7 +162,7 @@ func resourceArmEventHubDedicatedCreateUpdate(d *schema.ResourceData, meta inter existing, err := client.Get(ctx, resourceGroup, namespaceName, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing EventHub %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err) + return fmt.Errorf("Error checking for presence of existing Dedicated EventHub %q (Namespace %q / Resource Group %q): %s", name, namespaceName, resourceGroup, err) } } From 8917af5def21d9f9bda13d4521d6a23cfc49b218 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:39:07 +0200 Subject: [PATCH 26/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index c4d2803ae667..d3d85c59e33d 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -215,7 +215,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m clusterID := d.Get("cluster_id").(string) resGroup := d.Get("resource_group_name").(string) - if features.ShouldResourcesBeImported() && d.IsNewResource() { + if d.IsNewResource() { existing, err := client.Get(ctx, resGroup, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { From 5452ca4d71746b7c3a6e1a55e62c590f6dc6649a Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:39:17 +0200 Subject: [PATCH 27/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index d3d85c59e33d..42ed28b35b52 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -219,7 +219,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m existing, err := client.Get(ctx, resGroup, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing EventHub Namespace %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("Error checking for presence of existing EventHub Namespace %q (Resource Group %q): %s", name, resourceGroup, err) } } From 0005649b1040a624257a9c850ab0c66e4b964ce7 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:39:29 +0200 Subject: [PATCH 28/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 42ed28b35b52..aeb021ab4738 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -336,7 +336,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) if err != nil { - return fmt.Errorf("Error making Read request on EventHub Namespace %q Network Ruleset: %+v", name, err) + return fmt.Errorf("Error making Read request on Dedicated EventHub Namespace %q Network Ruleset: %+v", name, err) } if err := d.Set("network_rulesets", flattenEventHubNamespaceNetworkRuleset(ruleset)); err != nil { From 953dbfae83e061d57aff69f27a3cfeaaf9f3f851 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:39:42 +0200 Subject: [PATCH 29/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index aeb021ab4738..5dcd1582ac53 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -345,7 +345,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDefaultAuthorizationRule) if err != nil { - log.Printf("[WARN] Unable to List default keys for EventHub Namespace %q: %+v", name, err) + log.Printf("[WARN] Unable to List default keys for Dedicated EventHub Namespace %q: %+v", name, err) } else { d.Set("default_primary_connection_string_alias", keys.AliasPrimaryConnectionString) d.Set("default_secondary_connection_string_alias", keys.AliasSecondaryConnectionString) From 8d3c2cf7c4be7f56ee5b47cb28b99e7026266260 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:39:51 +0200 Subject: [PATCH 30/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 5dcd1582ac53..b69f24f0d238 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -392,7 +392,7 @@ func waitForeventHubNamespaceDedicatedToBeDeleted(ctx context.Context, client *e } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for EventHub NameSpace (%q in Resource Group %q) to be deleted: %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for Dedicated EventHub NameSpace (%q in Resource Group %q) to be deleted: %+v", name, resourceGroup, err) } return nil From 6dbe1e9ece0556a2da1821748a876d2d861bd597 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:40:30 +0200 Subject: [PATCH 31/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index b69f24f0d238..13c380488598 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -383,7 +383,7 @@ func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta in func waitForeventHubNamespaceDedicatedToBeDeleted(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string, d *schema.ResourceData) error { // we can't use the Waiter here since the API returns a 200 once it's deleted which is considered a polling status code.. - log.Printf("[DEBUG] Waiting for EventHub Namespace (%q in Resource Group %q) to be deleted", name, resourceGroup) + log.Printf("[DEBUG] Waiting for Dedicated EventHub Namespace (%q in Resource Group %q) to be deleted", name, resourceGroup) stateConf := &resource.StateChangeConf{ Pending: []string{"200"}, Target: []string{"404"}, From a662eb40b4aeb9863f128615946b25860d307604 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:40:38 +0200 Subject: [PATCH 32/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 13c380488598..d8a985f590f2 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -340,7 +340,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte } if err := d.Set("network_rulesets", flattenEventHubNamespaceNetworkRuleset(ruleset)); err != nil { - return fmt.Errorf("Error setting `network_ruleset` for Evenhub Namespace %s: %v", name, err) + return fmt.Errorf("Error setting `network_ruleset` for Dedicated Eventhub Namespace %s: %v", name, err) } keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDefaultAuthorizationRule) From 4a3a4e0ddcc21107765cce1ee9a62cf2ab330cd5 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:40:53 +0200 Subject: [PATCH 33/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index d8a985f590f2..d57165b13555 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -213,7 +213,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m name := d.Get("name").(string) clusterID := d.Get("cluster_id").(string) - resGroup := d.Get("resource_group_name").(string) + resourceGroup := d.Get("resource_group_name").(string) if d.IsNewResource() { existing, err := client.Get(ctx, resGroup, name) From 7cc7328b9c1b4be3445671e99ee09dfb8fdb980c Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:41:04 +0200 Subject: [PATCH 34/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index d57165b13555..b89e1987ec94 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -252,7 +252,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m parameters.EHNamespaceProperties.MaximumThroughputUnits = utils.Int32(int32(v.(int))) } - future, err := client.CreateOrUpdate(ctx, resGroup, name, parameters) + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) if err != nil { return err } From 202b88676087e33e62c7984b14fc909800b2239a Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:41:19 +0200 Subject: [PATCH 35/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index b89e1987ec94..6bc477cb06b6 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -267,7 +267,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m } if read.ID == nil { - return fmt.Errorf("Cannot read EventHub Namespace %q (resource group %q) ID", name, resGroup) + return fmt.Errorf("Cannot read EventHub Namespace %q (resource group %q) ID", name, resourceGroup) } d.SetId(*read.ID) From 3953e9bf9092561f16fc545b3cc601785b32b3b3 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:41:31 +0200 Subject: [PATCH 36/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 6bc477cb06b6..5c90ebcd62da 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -280,7 +280,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m // cannot use network rulesets with the basic SKU if parameters.Sku.Name != eventhub.Basic { - if _, err := client.CreateOrUpdateNetworkRuleSet(ctx, resGroup, name, rulesets); err != nil { + if _, err := client.CreateOrUpdateNetworkRuleSet(ctx, resourceGroup, name, rulesets); err != nil { return fmt.Errorf("Error setting network ruleset properties for EventHub Namespace %q (resource group %q): %v", name, resGroup, err) } } else { From 33597bf030f4f6ffb0898b5b7a9c7e12f43af058 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:41:56 +0200 Subject: [PATCH 37/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 5c90ebcd62da..6294318728d8 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -261,7 +261,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m return fmt.Errorf("Error creating eventhub namespace: %+v", err) } - read, err := client.Get(ctx, resGroup, name) + read, err := client.Get(ctx, resourceGroup, name) if err != nil { return err } From 1c33705226d187891557e3db21cfe137f98cf278 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:42:07 +0200 Subject: [PATCH 38/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 6294318728d8..c50578f3b389 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -305,7 +305,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte if err != nil { return err } - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup name := id.Path["namespaces"] resp, err := client.Get(ctx, resGroup, name) From ca31414791ea446a63faf111d5016e283c0fc467 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:42:21 +0200 Subject: [PATCH 39/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index c50578f3b389..db6c54e13c82 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -308,7 +308,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte resourceGroup := id.ResourceGroup name := id.Path["namespaces"] - resp, err := client.Get(ctx, resGroup, name) + resp, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") From 0d8452ae4da9d4976596cdcd5d4adbe70e8f7e75 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:42:33 +0200 Subject: [PATCH 40/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index db6c54e13c82..d0f10573ced9 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -318,7 +318,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte } d.Set("name", resp.Name) - d.Set("resource_group_name", resGroup) + d.Set("resource_group_name", resourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } From 2f51ac673ab31e85ad14cba0bbcf23556dc12dac Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:42:48 +0200 Subject: [PATCH 41/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index d0f10573ced9..6b8cd4248e00 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -258,7 +258,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating eventhub namespace: %+v", err) + return fmt.Errorf("Error creating dedicated eventhub namespace: %+v", err) } read, err := client.Get(ctx, resourceGroup, name) From baff0ed835851d1df56434eb9b31c262a64cdff4 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:43:01 +0200 Subject: [PATCH 42/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 6b8cd4248e00..6a3debd52c3f 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -334,7 +334,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte d.Set("cluster_id", props.ClusterArmID) } - ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) + ruleset, err := client.GetNetworkRuleSet(ctx, resourceGroup, name) if err != nil { return fmt.Errorf("Error making Read request on Dedicated EventHub Namespace %q Network Ruleset: %+v", name, err) } From 084159324e51db67139260e0c7475a80f6c24732 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:43:13 +0200 Subject: [PATCH 43/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 6a3debd52c3f..c635917afd75 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -343,7 +343,7 @@ func resourceArmeventHubNamespaceDedicatedRead(d *schema.ResourceData, meta inte return fmt.Errorf("Error setting `network_ruleset` for Dedicated Eventhub Namespace %s: %v", name, err) } - keys, err := client.ListKeys(ctx, resGroup, name, eventHubNamespaceDefaultAuthorizationRule) + keys, err := client.ListKeys(ctx, resourceGroup, name, eventHubNamespaceDefaultAuthorizationRule) if err != nil { log.Printf("[WARN] Unable to List default keys for Dedicated EventHub Namespace %q: %+v", name, err) } else { From cca93427773a031acd9cea883388a83751b28afe Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:43:24 +0200 Subject: [PATCH 44/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index c635917afd75..196403e6c01c 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -367,7 +367,7 @@ func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta in if err != nil { return err } - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup name := id.Path["namespaces"] future, err := client.Delete(ctx, resGroup, name) From e3ab34b0766b781f7d58d9207139777d69e55056 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:43:36 +0200 Subject: [PATCH 45/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 196403e6c01c..ca47aa5ea85a 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -370,7 +370,7 @@ func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta in resourceGroup := id.ResourceGroup name := id.Path["namespaces"] - future, err := client.Delete(ctx, resGroup, name) + future, err := client.Delete(ctx, resourceGroup, name) if err != nil { if response.WasNotFound(future.Response()) { return nil From 32c188be112d41314a7f142db0dc20aa0323d94b Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:43:48 +0200 Subject: [PATCH 46/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index ca47aa5ea85a..4b97a2056118 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -375,7 +375,7 @@ func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta in if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error issuing delete request of EventHub Namespace %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("Error issuing delete request of EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) } return waitForeventHubNamespaceDedicatedToBeDeleted(ctx, client, resGroup, name, d) From 8d3bd89d06b983bf6b1a0c2da981852d49653270 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Sat, 27 Jun 2020 10:44:00 +0200 Subject: [PATCH 47/48] Update azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go Co-authored-by: Steve <11830746+jackofallops@users.noreply.github.com> --- .../services/eventhub/eventhub_namespace_dedicated_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index 4b97a2056118..f4e64171d4d1 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -378,7 +378,7 @@ func resourceArmeventHubNamespaceDedicatedDelete(d *schema.ResourceData, meta in return fmt.Errorf("Error issuing delete request of EventHub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err) } - return waitForeventHubNamespaceDedicatedToBeDeleted(ctx, client, resGroup, name, d) + return waitForeventHubNamespaceDedicatedToBeDeleted(ctx, client, resourceGroup, name, d) } func waitForeventHubNamespaceDedicatedToBeDeleted(ctx context.Context, client *eventhub.NamespacesClient, resourceGroup, name string, d *schema.ResourceData) error { From b4b2a984c404eb67dd2f77b5cfcd26af70ab5dbd Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Mon, 29 Jun 2020 10:34:26 +0200 Subject: [PATCH 48/48] Address feedback batch 3 --- .../eventhub/eventhub_authorization_rule_resource.go | 6 ++++++ .../eventhub_namespace_authorization_rule_resource.go | 3 +++ .../eventhub/eventhub_namespace_dedicated_resource.go | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go index 9e1d28e74d34..21b208f36d25 100644 --- a/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_authorization_rule_resource.go @@ -203,6 +203,12 @@ func resourceArmEventHubAuthorizationRuleDelete(d *schema.ResourceData, meta int locks.ByName(namespaceName, eventHubNamespaceResourceName) defer locks.UnlockByName(namespaceName, eventHubNamespaceResourceName) + locks.ByName(eventHubName, eventHubDedicatedResourceName) + defer locks.UnlockByName(eventHubName, eventHubDedicatedResourceName) + + locks.ByName(namespaceName, eventHubNamespaceDedicatedResourceName) + defer locks.UnlockByName(namespaceName, eventHubNamespaceDedicatedResourceName) + if resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name); err != nil { if !utils.ResponseWasNotFound(resp) { return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Authorization Rule '%s': %+v", name, err) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go index 03b4d22a16ad..c4b8454f4bfa 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_authorization_rule_resource.go @@ -174,6 +174,9 @@ func resourceArmEventHubNamespaceAuthorizationRuleDelete(d *schema.ResourceData, return err } + locks.ByName(id.NamespaceName, eventHubNamespaceDedicatedResourceName) + defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceDedicatedResourceName) + locks.ByName(id.NamespaceName, eventHubNamespaceResourceName) defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceResourceName) diff --git a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go index f4e64171d4d1..5d3b071fbf04 100644 --- a/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go +++ b/azurerm/internal/services/eventhub/eventhub_namespace_dedicated_resource.go @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "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/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -216,7 +215,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m resourceGroup := d.Get("resource_group_name").(string) if d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, name) + existing, err := client.Get(ctx, resourceGroup, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("Error checking for presence of existing EventHub Namespace %q (Resource Group %q): %s", name, resourceGroup, err) @@ -281,7 +280,7 @@ func resourceArmeventHubNamespaceDedicatedCreateUpdate(d *schema.ResourceData, m // cannot use network rulesets with the basic SKU if parameters.Sku.Name != eventhub.Basic { if _, err := client.CreateOrUpdateNetworkRuleSet(ctx, resourceGroup, name, rulesets); err != nil { - return fmt.Errorf("Error setting network ruleset properties for EventHub Namespace %q (resource group %q): %v", name, resGroup, err) + return fmt.Errorf("Error setting network ruleset properties for EventHub Namespace %q (resource group %q): %v", name, resourceGroup, err) } } else { // so if the user has specified the non default rule sets throw a validation error