Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_servicebus_namespace_disaster_recovery_config: support alias_authorization_rule_id #18729

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -50,6 +51,12 @@ func dataSourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource {
AtLeastOneOf: []string{"namespace_id", "resource_group_name", "namespace_name"},
},

"alias_authorization_rule_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"partner_namespace_id": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -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("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)
}
authRuleId = *ruleId
}

keys, err := client.ListKeys(ctx, authRuleId)
if err != nil {
log.Printf("[WARN] listing default keys for %s: %+v", id, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,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"
)
Expand Down Expand Up @@ -59,6 +60,12 @@ func resourceServiceBusNamespaceDisasterRecoveryConfig() *pluginsdk.Resource {
ValidateFunc: azure.ValidateResourceIDOrEmpty,
},

"alias_authorization_rule_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"primary_connection_string_alias": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -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("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)
}
authRuleId = *ruleId
}

keys, err := client.ListKeys(ctx, authRuleId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand All @@ -115,13 +118,15 @@ func TestAccServiceBusTopic_update(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("enable_batched_operations").HasValue("true"),
check.That(data.ResourceName).Key("enable_express").HasValue("true"),
),
},
data.ImportStep(),
})
}

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |-

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

Expand All @@ -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
alias_authorization_rule_id = azurerm_servicebus_namespace_authorization_rule.example.id
}

```
Expand All @@ -54,6 +64,8 @@ The following arguments are supported:

* `partner_namespace_id` - (Required) The ID of the Service Bus Namespace to replicate to.

* `alias_authorization_rule_id` - (Optional) The Shared access policies used to access the connection string for the alias. Defaults to `RootManageSharedAccessKey`.

## Attributes Reference

The following attributes are exported:
Expand All @@ -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`.

Expand Down