diff --git a/internal/services/eventhub/eventhub_resource.go b/internal/services/eventhub/eventhub_resource.go index 71b2d21b6ab5..9b94ba141f92 100644 --- a/internal/services/eventhub/eventhub_resource.go +++ b/internal/services/eventhub/eventhub_resource.go @@ -10,11 +10,12 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourcegroups" "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs" "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -25,7 +26,7 @@ import ( var eventHubResourceName = "azurerm_eventhub" func resourceEventHub() *pluginsdk.Resource { - return &pluginsdk.Resource{ + r := &pluginsdk.Resource{ Create: resourceEventHubCreate, Read: resourceEventHubRead, Update: resourceEventHubUpdate, @@ -51,15 +52,13 @@ func resourceEventHub() *pluginsdk.Resource { ValidateFunc: validate.ValidateEventHubName(), }, - "namespace_name": { + "namespace_id": { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.ValidateEventHubNamespaceName(), + ValidateFunc: namespaces.ValidateNamespaceID, }, - "resource_group_name": commonschema.ResourceGroupName(), - "partition_count": { Type: pluginsdk.TypeInt, Required: true, @@ -163,6 +162,36 @@ func resourceEventHub() *pluginsdk.Resource { }, }, } + + if !features.FivePointOhBeta() { + r.Schema["namespace_id"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ExactlyOneOf: []string{"namespace_id", "namespace_name"}, + ValidateFunc: namespaces.ValidateNamespaceID, + } + + r.Schema["namespace_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.ValidateEventHubNamespaceName(), + ExactlyOneOf: []string{"namespace_id", "namespace_name"}, + Deprecated: "`namespace_name` has been deprecated in favour of `namespace_id` and will be removed in v5.0 of the AzureRM Provider", + } + + r.Schema["resource_group_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ExactlyOneOf: []string{"namespace_id", "resource_group_name"}, + ValidateFunc: resourcegroups.ValidateName, + Deprecated: "`resource_group_name` has been deprecated in favour of `namespace_id` and will be removed in v5.0 of the AzureRM Provider", + } + } + + return r } func resourceEventHubCreate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -173,7 +202,23 @@ func resourceEventHubCreate(d *pluginsdk.ResourceData, meta interface{}) error { log.Printf("[INFO] preparing arguments for Azure ARM EventHub creation.") - id := eventhubs.NewEventhubID(subscriptionId, d.Get("resource_group_name").(string), d.Get("namespace_name").(string), d.Get("name").(string)) + namespaceName := "" + resourceGroupName := "" + if v := d.Get("namespace_id").(string); v != "" { + namespaceId, err := namespaces.ParseNamespaceID(v) + if err != nil { + return err + } + namespaceName = namespaceId.NamespaceName + resourceGroupName = namespaceId.ResourceGroupName + } + + if !features.FivePointOhBeta() && namespaceName == "" { + namespaceName = d.Get("namespace_name").(string) + resourceGroupName = d.Get("resource_group_name").(string) + } + + id := eventhubs.NewEventhubID(subscriptionId, resourceGroupName, namespaceName, d.Get("name").(string)) if d.IsNewResource() { existing, err := client.Get(ctx, id) @@ -218,7 +263,10 @@ func resourceEventHubUpdate(d *pluginsdk.ResourceData, meta interface{}) error { log.Printf("[INFO] preparing arguments for Azure ARM EventHub update.") - id := eventhubs.NewEventhubID(subscriptionId, d.Get("resource_group_name").(string), d.Get("namespace_name").(string), d.Get("name").(string)) + id, err := eventhubs.ParseEventhubID(d.Id()) + if err != nil { + return err + } if d.HasChange("partition_count") { o, n := d.GetChange("partition_count") @@ -253,7 +301,7 @@ func resourceEventHubUpdate(d *pluginsdk.ResourceData, meta interface{}) error { parameters.Properties.CaptureDescription = expandEventHubCaptureDescription(d) } - if _, err := client.CreateOrUpdate(ctx, id, parameters); err != nil { + if _, err := client.CreateOrUpdate(ctx, *id, parameters); err != nil { return err } @@ -282,8 +330,14 @@ func resourceEventHubRead(d *pluginsdk.ResourceData, meta interface{}) error { } d.Set("name", id.EventhubName) - d.Set("namespace_name", id.NamespaceName) - d.Set("resource_group_name", id.ResourceGroupName) + + if !features.FivePointOhBeta() { + d.Set("namespace_name", id.NamespaceName) + d.Set("resource_group_name", id.ResourceGroupName) + } + + namespaceId := namespaces.NewNamespaceID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName) + d.Set("namespace_id", namespaceId.ID()) if model := resp.Model; model != nil { if props := model.Properties; props != nil { diff --git a/internal/services/eventhub/eventhub_resource_test.go b/internal/services/eventhub/eventhub_resource_test.go index 46c20c94aa7a..c22c3800b462 100644 --- a/internal/services/eventhub/eventhub_resource_test.go +++ b/internal/services/eventhub/eventhub_resource_test.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -360,7 +361,8 @@ func (EventHubResource) Exists(ctx context.Context, clients *clients.Client, sta } func (EventHubResource) basic(data acceptance.TestData, partitionCount int) string { - return fmt.Sprintf(` + if !features.FivePointOhBeta() { + return fmt.Sprintf(` provider "azurerm" { features {} } @@ -384,6 +386,31 @@ resource "azurerm_eventhub" "test" { partition_count = %d message_retention = 1 } +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, partitionCount) + } + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-eventhub-%d" + location = "%s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Basic" +} + +resource "azurerm_eventhub" "test" { + name = "acctesteventhub-%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = %d + message_retention = 1 +} `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, partitionCount) } @@ -393,11 +420,10 @@ func (EventHubResource) requiresImport(data acceptance.TestData) string { %s resource "azurerm_eventhub" "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.test.name + namespace_id = azurerm_eventhub.test.namespace_id + partition_count = azurerm_eventhub.test.partition_count + message_retention = azurerm_eventhub.test.message_retention } `, template) } @@ -421,11 +447,10 @@ resource "azurerm_eventhub_namespace" "test" { } resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" - namespace_name = azurerm_eventhub_namespace.test.name - resource_group_name = azurerm_resource_group.test.name - partition_count = 10 - message_retention = 1 + name = "acctesteventhub-%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = 10 + message_retention = 1 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -449,11 +474,10 @@ resource "azurerm_eventhub_namespace" "test" { } resource "azurerm_eventhub" "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 + name = "acctest-EH-%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = 2 + message_retention = 7 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -492,11 +516,10 @@ resource "azurerm_eventhub_namespace" "test" { } resource "azurerm_eventhub" "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 + name = "acctest-EH%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = 2 + message_retention = 7 capture_description { enabled = %s @@ -535,11 +558,10 @@ resource "azurerm_eventhub_namespace" "test" { } resource "azurerm_eventhub" "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 + name = "acctest-EH-%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = 2 + message_retention = 5 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -563,12 +585,11 @@ resource "azurerm_eventhub_namespace" "test" { } resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" - namespace_name = azurerm_eventhub_namespace.test.name - resource_group_name = azurerm_resource_group.test.name - partition_count = 5 - message_retention = 1 - status = "%s" + name = "acctesteventhub-%d" + namespace_id = azurerm_eventhub_namespace.test.id + partition_count = 5 + message_retention = 1 + status = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, status) } diff --git a/website/docs/5.0-upgrade-guide.html.markdown b/website/docs/5.0-upgrade-guide.html.markdown index 66aef14dd13f..bd8de5a1253a 100644 --- a/website/docs/5.0-upgrade-guide.html.markdown +++ b/website/docs/5.0-upgrade-guide.html.markdown @@ -60,52 +60,57 @@ Please follow the format in the example below for listing breaking changes in re * The `example_property_with_changed_default` property now defaults to `NewDefault`. ``` -### `azurerm_monitor_aad_diagnostic_setting` +### `azurerm_cdn_frontdoor_custom_domain` -* The deprecated `enabled_log.retention_policy` block has been removed. +* The `tls.minimum_tls_version` property no longer accepts `TLS10` as a value. ### `azurerm_cosmosdb_account` * The `minimal_tls_version` property no longer accepts `Tls` or `Tls11` as a value. -### `azurerm_sentinel_alert_rule_fusion` +### `azurerm_eventhub` -* The deprecated `name` property has been removed. +* The deprecated `namespace_name` property has been removed in favour of the `namespace_id` property. +* The deprecated `resource_group_name` property has been removed in favour of the `namespace_id` property. -### `azurerm_storage_account` +### `azurerm_eventhub_namespace` -* The deprecated `queue_properties` block has been removed and superseded by the `azurerm_storage_account_queue_properties` resource. -* The deprecated `static_website` block has been removed and superseded by the `azurerm_storage_account_static_website` resource. +* The `minimum_tls_version` property no longer accepts `1.0` and `1.1` as a value. -### `azurerm_storage_container` +### `azurerm_monitor_aad_diagnostic_setting` -* The deprecated `storage_account_name` property has been removed in favour of the `storage_account_id` property. -* The deprecated `resource_manager_id` property has been removed in favour of the `id` property. - -### `azurerm_storage_share` +* The deprecated `enabled_log.retention_policy` block has been removed. -* The deprecated `storage_account_name` property has been removed in favour of the `storage_account_id` property. -* The deprecated `resource_manager_id` property has been removed in favour of the `id` property. +### `azurerm_mssql_database` -### `azurerm_cdn_frontdoor_custom_domain` +* The properties `weekly_retention`, `monthly_retention` and `yearly_retention` now default to `PT0S`. -* The `tls.minimum_tls_version` property no longer accepts `TLS10` as a value. +### `azurerm_mssql_managed_database` + +* The properties `weekly_retention`, `monthly_retention` and `yearly_retention` now default to `PT0S`. ## `azurerm_network_watcher_flow_log` * The deprecated `network_security_group_id` property has been removed in favour of the `target_resource_id` property. -### `azurerm_mssql_database` +### `azurerm_sentinel_alert_rule_fusion` -* The properties `weekly_retention`, `monthly_retention` and `yearly_retention` now default to `PT0S`. +* The deprecated `name` property has been removed. -### `azurerm_mssql_managed_database` +### `azurerm_storage_account` -* The properties `weekly_retention`, `monthly_retention` and `yearly_retention` now default to `PT0S`. +* The deprecated `queue_properties` block has been removed and superseded by the `azurerm_storage_account_queue_properties` resource. +* The deprecated `static_website` block has been removed and superseded by the `azurerm_storage_account_static_website` resource. -### `azurerm_eventhub_namespace` +### `azurerm_storage_container` -* The `minimum_tls_version` property no longer accepts `1.0` and `1.1` as a value. +* The deprecated `storage_account_name` property has been removed in favour of the `storage_account_id` property. +* The deprecated `resource_manager_id` property has been removed in favour of the `id` property. + +### `azurerm_storage_share` + +* The deprecated `storage_account_name` property has been removed in favour of the `storage_account_id` property. +* The deprecated `resource_manager_id` property has been removed in favour of the `id` property. ## Breaking Changes in Data Sources diff --git a/website/docs/r/eventhub.html.markdown b/website/docs/r/eventhub.html.markdown index 58571f2496ff..abd287e03421 100644 --- a/website/docs/r/eventhub.html.markdown +++ b/website/docs/r/eventhub.html.markdown @@ -31,11 +31,10 @@ resource "azurerm_eventhub_namespace" "example" { } 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 + name = "acceptanceTestEventHub" + namespace_id = azurerm_eventhub_namespace.example.id + partition_count = 2 + message_retention = 1 } ``` @@ -45,9 +44,7 @@ The following arguments are supported: * `name` - (Required) Specifies the name of the EventHub 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. +* `namespace_id` - (Optional) Specifies the ID of the EventHub Namespace. Changing this forces a new resource to be created. * `partition_count` - (Required) Specifies the current number of shards on the Event Hub.