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

Add zone redundancy for service bus namespace #4432

Merged
merged 2 commits into from
Sep 26, 2019
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
14 changes: 12 additions & 2 deletions azurerm/data_source_servicebus_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ func dataSourceArmServiceBusNamespace() *schema.Resource {
Sensitive: true,
},

"zone_redundant": {
Type: schema.TypeBool,
Computed: true,
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).ServiceBus.NamespacesClient
client := meta.(*ArmClient).ServiceBus.NamespacesClientPreview
clientStable := meta.(*ArmClient).ServiceBus.NamespacesClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
Expand All @@ -93,7 +99,11 @@ func dataSourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface
d.Set("capacity", sku.Capacity)
}

keys, err := client.ListKeys(ctx, resourceGroup, name, serviceBusNamespaceDefaultAuthorizationRule)
if properties := resp.SBNamespaceProperties; properties != nil {
d.Set("zone_redundant", properties.ZoneRedundant)
}

keys, err := clientStable.ListKeys(ctx, resourceGroup, name, serviceBusNamespaceDefaultAuthorizationRule)
if err != nil {
log.Printf("[WARN] Unable to List default keys for Namespace %q (Resource Group %q): %+v", name, resourceGroup, err)
} else {
Expand Down
6 changes: 6 additions & 0 deletions azurerm/internal/services/servicebus/client.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package servicebus

import (
servicebusPreview "github.com/Azure/azure-sdk-for-go/services/preview/servicebus/mgmt/2018-01-01-preview/servicebus"
"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
QueuesClient *servicebus.QueuesClient
NamespacesClient *servicebus.NamespacesClient
NamespacesClientPreview *servicebusPreview.NamespacesClient
TopicsClient *servicebus.TopicsClient
SubscriptionsClient *servicebus.SubscriptionsClient
SubscriptionRulesClient *servicebus.RulesClient
Expand All @@ -21,6 +23,9 @@ func BuildClient(o *common.ClientOptions) *Client {
NamespacesClient := servicebus.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer)

NamespacesClientPreview := servicebusPreview.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&NamespacesClientPreview.Client, o.ResourceManagerAuthorizer)

TopicsClient := servicebus.NewTopicsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&TopicsClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -33,6 +38,7 @@ func BuildClient(o *common.ClientOptions) *Client {
return &Client{
QueuesClient: &QueuesClient,
NamespacesClient: &NamespacesClient,
NamespacesClientPreview: &NamespacesClientPreview,
TopicsClient: &TopicsClient,
SubscriptionsClient: &SubscriptionsClient,
SubscriptionRulesClient: &SubscriptionRulesClient,
Expand Down
28 changes: 23 additions & 5 deletions azurerm/resource_arm_servicebus_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"

"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
"github.com/Azure/azure-sdk-for-go/services/preview/servicebus/mgmt/2018-01-01-preview/servicebus"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
Expand Down Expand Up @@ -96,13 +96,19 @@ func resourceArmServiceBusNamespace() *schema.Resource {
Sensitive: true,
},

"zone_redundant": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"tags": tags.Schema(),
},
}
}

func resourceArmServiceBusNamespaceCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).ServiceBus.NamespacesClient
client := meta.(*ArmClient).ServiceBus.NamespacesClientPreview
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for AzureRM ServiceBus Namespace creation.")
Expand Down Expand Up @@ -145,6 +151,13 @@ func resourceArmServiceBusNamespaceCreateUpdate(d *schema.ResourceData, meta int
parameters.Sku.Capacity = utils.Int32(int32(capacity.(int)))
}

if zoneRedundant, ok := d.GetOkExists("zone_redundant"); ok {
properties := servicebus.SBNamespaceProperties{
ZoneRedundant: utils.Bool(zoneRedundant.(bool)),
}
parameters.SBNamespaceProperties = &properties
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters)
if err != nil {
return err
Expand All @@ -169,7 +182,8 @@ func resourceArmServiceBusNamespaceCreateUpdate(d *schema.ResourceData, meta int
}

func resourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).ServiceBus.NamespacesClient
client := meta.(*ArmClient).ServiceBus.NamespacesClientPreview
clientStable := meta.(*ArmClient).ServiceBus.NamespacesClient
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
Expand Down Expand Up @@ -199,7 +213,11 @@ func resourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface{}
d.Set("capacity", sku.Capacity)
}

keys, err := client.ListKeys(ctx, resourceGroup, name, serviceBusNamespaceDefaultAuthorizationRule)
if properties := resp.SBNamespaceProperties; properties != nil {
d.Set("zone_redundant", properties.ZoneRedundant)
}

keys, err := clientStable.ListKeys(ctx, resourceGroup, name, serviceBusNamespaceDefaultAuthorizationRule)
if err != nil {
log.Printf("[WARN] Unable to List default keys for Namespace %q (Resource Group %q): %+v", name, resourceGroup, err)
} else {
Expand All @@ -213,7 +231,7 @@ func resourceArmServiceBusNamespaceRead(d *schema.ResourceData, meta interface{}
}

func resourceArmServiceBusNamespaceDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).ServiceBus.NamespacesClient
client := meta.(*ArmClient).ServiceBus.NamespacesClientPreview
ctx := meta.(*ArmClient).StopContext

id, err := azure.ParseAzureResourceID(d.Id())
Expand Down
48 changes: 46 additions & 2 deletions azurerm/resource_arm_servicebus_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,34 @@ func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) {
})
}

func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) {
resourceName := "azurerm_servicebus_namespace.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMServiceBusNamespace_zoneRedundant(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusNamespaceExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "zone_redundant", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMServiceBusNamespaceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).ServiceBus.NamespacesClient
client := testAccProvider.Meta().(*ArmClient).ServiceBus.NamespacesClientPreview
ctx := testAccProvider.Meta().(*ArmClient).StopContext

for _, rs := range s.RootModule().Resources {
Expand Down Expand Up @@ -221,7 +247,7 @@ func testCheckAzureRMServiceBusNamespaceExists(resourceName string) resource.Tes
return fmt.Errorf("Bad: no resource group found in state for Service Bus Namespace: %s", namespaceName)
}

client := testAccProvider.Meta().(*ArmClient).ServiceBus.NamespacesClient
client := testAccProvider.Meta().(*ArmClient).ServiceBus.NamespacesClientPreview
ctx := testAccProvider.Meta().(*ArmClient).StopContext

resp, err := client.Get(ctx, resourceGroup, namespaceName)
Expand Down Expand Up @@ -332,3 +358,21 @@ resource "azurerm_servicebus_namespace" "test" {
}
`, rInt, location, rInt)
}

func testAccAzureRMServiceBusNamespace_zoneRedundant(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_servicebus_namespace" "test" {
name = "acctestservicebusnamespace-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
sku = "Premium"
capacity = 1
zone_redundant = true
}
`, rInt, location, rInt)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading