From 195cafdfbf60541e0b1bb53d8c91c7a767afedcd Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Thu, 13 Oct 2022 10:34:02 +0800 Subject: [PATCH 1/5] fix dr connection string --- ...ce_disaster_recovery_config_data_source.go | 18 ++++++++++++- ...space_disaster_recovery_config_resource.go | 17 +++++++++++- .../servicebus_topic_resource_test.go | 8 ++++++ ...ace_disaster_recovery_config.html.markdown | 27 ++++++++++++++----- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go index 5313321e3263..817fd182fc72 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicebus/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -50,6 +51,12 @@ func dataSourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource { AtLeastOneOf: []string{"namespace_id", "resource_group_name", "namespace_name"}, }, + "auth_rule_id_of_the_alias": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "partner_namespace_id": { Type: pluginsdk.TypeString, Computed: true, @@ -124,7 +131,16 @@ func dataSourceServiceBusNamespaceDisasterRecoveryConfigRead(d *pluginsdk.Resour d.SetId(id.ID()) - authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, d.Get("name").(string)) + // the auth rule cannot be retrieved by dr config name, the shared access policy should either be specified by user or using the default one which is `RootManageSharedAccessKey` + authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, serviceBusNamespaceDefaultAuthorizationRule) + if input := d.Get("auth_rule_id_of_the_alias").(string); input != "" { + ruleId, err := disasterrecoveryconfigs.ParseAuthorizationRuleID(input) + if err != nil { + return fmt.Errorf("parsing primary namespace auth rule id error: %+v", err) + } + authRuleId = *ruleId + } + keys, err := client.ListKeys(ctx, authRuleId) if err != nil { log.Printf("[WARN] listing default keys for %s: %+v", id, err) diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go index 2593ce4314f3..1cad4a180880 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go @@ -3,6 +3,7 @@ package servicebus import ( "context" "fmt" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "log" "net/http" "strconv" @@ -59,6 +60,12 @@ func resourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource { ValidateFunc: azure.ValidateResourceIDOrEmpty, }, + "auth_rule_id_of_the_alias": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "primary_connection_string_alias": { Type: pluginsdk.TypeString, Computed: true, @@ -198,7 +205,15 @@ func resourceServiceBusNamespaceDisasterRecoveryConfigRead(d *pluginsdk.Resource } } - authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, id.Alias) + // the auth rule cannot be retrieved by dr config name, the shared access policy should either be specified by user or using the default one which is `RootManageSharedAccessKey` + authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, serviceBusNamespaceDefaultAuthorizationRule) + if input := d.Get("auth_rule_id_of_the_alias").(string); input != "" { + ruleId, err := disasterrecoveryconfigs.ParseAuthorizationRuleID(input) + if err != nil { + return fmt.Errorf("parsing primary namespace auth rule id error: %+v", err) + } + authRuleId = *ruleId + } keys, err := client.ListKeys(ctx, authRuleId) diff --git a/internal/services/servicebus/servicebus_topic_resource_test.go b/internal/services/servicebus/servicebus_topic_resource_test.go index 5d4b548dceff..b55f1fedb137 100644 --- a/internal/services/servicebus/servicebus_topic_resource_test.go +++ b/internal/services/servicebus/servicebus_topic_resource_test.go @@ -89,18 +89,21 @@ func TestAccServiceBusTopic_basicDisableEnable(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.basicDisabled(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), }) } @@ -115,6 +118,7 @@ func TestAccServiceBusTopic_update(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.update(data), Check: acceptance.ComposeTestCheckFunc( @@ -122,6 +126,7 @@ func TestAccServiceBusTopic_update(t *testing.T) { check.That(data.ResourceName).Key("enable_express").HasValue("true"), ), }, + data.ImportStep(), }) } @@ -136,6 +141,7 @@ func TestAccServiceBusTopic_enablePartitioningStandard(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.enablePartitioningStandard(data), Check: acceptance.ComposeTestCheckFunc( @@ -174,6 +180,7 @@ func TestAccServiceBusTopic_enablePartitioningPremium(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.enablePartitioningPremium(data), Check: acceptance.ComposeTestCheckFunc( @@ -196,6 +203,7 @@ func TestAccServiceBusTopic_enableDuplicateDetection(t *testing.T) { check.That(data.ResourceName).ExistsInAzure(r), ), }, + data.ImportStep(), { Config: r.enableDuplicateDetection(data), Check: acceptance.ComposeTestCheckFunc( diff --git a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown index 30f561825eda..30f596e39f76 100644 --- a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown +++ b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown @@ -3,14 +3,14 @@ subcategory: "Messaging" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_servicebus_namespace_disaster_recovery_config" description: |- - Manages a Disaster Recovery Config for a Service Bus Namespace. +Manages a Disaster Recovery Config for a Service Bus Namespace. --- # azurerm_servicebus_namespace_disaster_recovery_config Manages a Disaster Recovery Config for a Service Bus Namespace. -~> **NOTE:** Disaster Recovery Config is a Premium SKU only capability. +~> **NOTE:** Disaster Recovery Config is a Premium SKU only capability. ## Example Usage @@ -36,10 +36,20 @@ resource "azurerm_servicebus_namespace" "secondary" { capacity = "1" } +resource "azurerm_servicebus_namespace_authorization_rule" "example" { + name = "examplerule" + namespace_id = azurerm_servicebus_namespace.example.id + + listen = true + send = true + manage = false +} + resource "azurerm_servicebus_namespace_disaster_recovery_config" "example" { - name = "servicebus-alias-name" - primary_namespace_id = azurerm_servicebus_namespace.primary.id - partner_namespace_id = azurerm_servicebus_namespace.secondary.id + name = "servicebus-alias-name" + primary_namespace_id = azurerm_servicebus_namespace.primary.id + partner_namespace_id = azurerm_servicebus_namespace.secondary.id + auth_rule_id_of_the_alias = azurerm_servicebus_namespace_authorization_rule.example.id } ``` @@ -54,6 +64,8 @@ The following arguments are supported: * `partner_namespace_id` - (Required) The ID of the Service Bus Namespace to replicate to. +* `auth_rule_id_of_the_alias` - (Optional) The Shared access policies used to access the connection string for the alias. Defaults to `RootManageSharedAccessKey`. + ## Attributes Reference The following attributes are exported: @@ -62,7 +74,7 @@ The following attributes are exported: * `primary_connection_string_alias` - The alias Primary Connection String for the ServiceBus Namespace. -* `secondary_connection_string_alias` - The alias Secondary Connection String for the ServiceBus Namespace +* `secondary_connection_string_alias` - The alias Secondary Connection String for the ServiceBus Namespace * `default_primary_key` - The primary access key for the authorization rule `RootManageSharedAccessKey`. @@ -70,7 +82,8 @@ The following attributes are exported: ## Timeouts -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: +The `timeouts` block allows you to +specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: * `create` - (Defaults to 30 minutes) Used when creating the Service Bus Namespace Disaster Recovery Config. * `update` - (Defaults to 30 minutes) Used when updating the Service Bus Namespace Disaster Recovery Config. From cffd8a77cd104f23b59bd842ca72b93077d978ac Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Thu, 13 Oct 2022 10:37:06 +0800 Subject: [PATCH 2/5] update fmt --- ...rvicebus_namespace_disaster_recovery_config.html.markdown | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown index 30f596e39f76..499745bb0d2e 100644 --- a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown +++ b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown @@ -3,7 +3,7 @@ subcategory: "Messaging" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_servicebus_namespace_disaster_recovery_config" description: |- -Manages a Disaster Recovery Config for a Service Bus Namespace. + Manages a Disaster Recovery Config for a Service Bus Namespace. --- # azurerm_servicebus_namespace_disaster_recovery_config @@ -82,8 +82,7 @@ The following attributes are exported: ## Timeouts -The `timeouts` block allows you to -specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: * `create` - (Defaults to 30 minutes) Used when creating the Service Bus Namespace Disaster Recovery Config. * `update` - (Defaults to 30 minutes) Used when updating the Service Bus Namespace Disaster Recovery Config. From bf356592ea162c76ae151a4b0c02df4b954c53a2 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Thu, 13 Oct 2022 13:09:44 +0800 Subject: [PATCH 3/5] sorts imports --- .../servicebus_namespace_disaster_recovery_config_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go index 1cad4a180880..6b74d40e0565 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go @@ -3,7 +3,6 @@ package servicebus import ( "context" "fmt" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "log" "net/http" "strconv" @@ -16,6 +15,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" ) From b09f23b1d60d1b90551afac005bf37bf587a327a Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 14 Oct 2022 10:48:04 +0800 Subject: [PATCH 4/5] rename property --- ...rvicebus_namespace_disaster_recovery_config_data_source.go | 4 ++-- .../servicebus_namespace_disaster_recovery_config_resource.go | 4 ++-- ...ervicebus_namespace_disaster_recovery_config.html.markdown | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go index 817fd182fc72..27bee139b02f 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_data_source.go @@ -51,7 +51,7 @@ func dataSourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource { AtLeastOneOf: []string{"namespace_id", "resource_group_name", "namespace_name"}, }, - "auth_rule_id_of_the_alias": { + "alias_authorization_rule_id": { Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringIsNotEmpty, @@ -133,7 +133,7 @@ func dataSourceServiceBusNamespaceDisasterRecoveryConfigRead(d *pluginsdk.Resour // the auth rule cannot be retrieved by dr config name, the shared access policy should either be specified by user or using the default one which is `RootManageSharedAccessKey` authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, serviceBusNamespaceDefaultAuthorizationRule) - if input := d.Get("auth_rule_id_of_the_alias").(string); input != "" { + if input := d.Get("alias_authorization_rule_id").(string); input != "" { ruleId, err := disasterrecoveryconfigs.ParseAuthorizationRuleID(input) if err != nil { return fmt.Errorf("parsing primary namespace auth rule id error: %+v", err) diff --git a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go index 6b74d40e0565..55e4c8c5d654 100644 --- a/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go +++ b/internal/services/servicebus/servicebus_namespace_disaster_recovery_config_resource.go @@ -60,7 +60,7 @@ func resourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource { ValidateFunc: azure.ValidateResourceIDOrEmpty, }, - "auth_rule_id_of_the_alias": { + "alias_authorization_rule_id": { Type: pluginsdk.TypeString, Optional: true, ValidateFunc: validation.StringIsNotEmpty, @@ -207,7 +207,7 @@ func resourceServiceBusNamespaceDisasterRecoveryConfigRead(d *pluginsdk.Resource // the auth rule cannot be retrieved by dr config name, the shared access policy should either be specified by user or using the default one which is `RootManageSharedAccessKey` authRuleId := disasterrecoveryconfigs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroupName, id.NamespaceName, serviceBusNamespaceDefaultAuthorizationRule) - if input := d.Get("auth_rule_id_of_the_alias").(string); input != "" { + if input := d.Get("alias_authorization_rule_id").(string); input != "" { ruleId, err := disasterrecoveryconfigs.ParseAuthorizationRuleID(input) if err != nil { return fmt.Errorf("parsing primary namespace auth rule id error: %+v", err) diff --git a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown index 499745bb0d2e..d05faad9e7fe 100644 --- a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown +++ b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown @@ -49,7 +49,7 @@ resource "azurerm_servicebus_namespace_disaster_recovery_config" "example" { name = "servicebus-alias-name" primary_namespace_id = azurerm_servicebus_namespace.primary.id partner_namespace_id = azurerm_servicebus_namespace.secondary.id - auth_rule_id_of_the_alias = azurerm_servicebus_namespace_authorization_rule.example.id + alias_authorization_rule_id = azurerm_servicebus_namespace_authorization_rule.example.id } ``` @@ -64,7 +64,7 @@ The following arguments are supported: * `partner_namespace_id` - (Required) The ID of the Service Bus Namespace to replicate to. -* `auth_rule_id_of_the_alias` - (Optional) The Shared access policies used to access the connection string for the alias. Defaults to `RootManageSharedAccessKey`. +* `alias_authorization_rule_id` - (Optional) The Shared access policies used to access the connection string for the alias. Defaults to `RootManageSharedAccessKey`. ## Attributes Reference From 5975ae9466711c82095dc03851c99eebcde8801a Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 14 Oct 2022 10:55:13 +0800 Subject: [PATCH 5/5] update fmt --- ...vicebus_namespace_disaster_recovery_config.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown index d05faad9e7fe..d18b57ac17e0 100644 --- a/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown +++ b/website/docs/r/servicebus_namespace_disaster_recovery_config.html.markdown @@ -46,9 +46,9 @@ resource "azurerm_servicebus_namespace_authorization_rule" "example" { } resource "azurerm_servicebus_namespace_disaster_recovery_config" "example" { - name = "servicebus-alias-name" - primary_namespace_id = azurerm_servicebus_namespace.primary.id - partner_namespace_id = azurerm_servicebus_namespace.secondary.id + name = "servicebus-alias-name" + primary_namespace_id = azurerm_servicebus_namespace.primary.id + partner_namespace_id = azurerm_servicebus_namespace.secondary.id alias_authorization_rule_id = azurerm_servicebus_namespace_authorization_rule.example.id }