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

ServiceBus Namespace: polling for the deletion #1908

Merged
merged 2 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/resource_arm_servicebus_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package azurerm
import (
"fmt"
"log"
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
"regexp"
)

// Default Authorization Rule/Policy created by Azure, used to populate the
Expand Down Expand Up @@ -212,10 +213,19 @@ func resourceArmServiceBusNamespaceDelete(d *schema.ResourceData, meta interface
resourceGroup := id.ResourceGroup
name := id.Path["namespaces"]

_, err = client.Delete(ctx, resourceGroup, name)
deleteFuture, err := client.Delete(ctx, resourceGroup, name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we call this future to match the rest of the codebase?

if err != nil {
return err
}

err = deleteFuture.WaitForCompletionRef(ctx, client.Client)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines could be combines as such:

if err := deleteFuture.WaitForCompletionRef(ctx, client.Client); err != nil {

if response.WasNotFound(deleteFuture.Response()) {
return nil
}

return fmt.Errorf("Error deleting Service Bus %q: %+v", name, err)
}

return nil
}
36 changes: 36 additions & 0 deletions azurerm/resource_arm_servicebus_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) {
})
}

func TestAccAzureRMServiceBusNamespace_premium(t *testing.T) {
resourceName := "azurerm_servicebus_namespace.test"
ri := acctest.RandInt()
config := testAccAzureRMServiceBusNamespace_premium(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceBusNamespaceExists(resourceName),
),
},
},
})
}

func testCheckAzureRMServiceBusNamespaceDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).serviceBusNamespacesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
Expand Down Expand Up @@ -221,3 +241,19 @@ resource "azurerm_servicebus_namespace" "test" {
}
`, rInt, location, rInt)
}

func testAccAzureRMServiceBusNamespace_premium(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we align these assignments?

location = "%s"
}
resource "azurerm_servicebus_namespace" "test" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And add a space here between the resources

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