Skip to content

Commit

Permalink
Polling for the Notification Hub Namespace ourselves since the Future…
Browse files Browse the repository at this point in the history
…'s broken

```
$ acctests azurerm TestAccAzureRMNotificationHubNamespace_importFree
=== RUN   TestAccAzureRMNotificationHubNamespace_importFree
--- PASS: TestAccAzureRMNotificationHubNamespace_importFree (129.94s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	129.989s
```
  • Loading branch information
tombuildsstuff committed Jul 18, 2018
1 parent 3914a28 commit 59ca5de
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions azurerm/resource_arm_notification_hub_namespace.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package azurerm

import (
"context"
"fmt"
"log"

"time"

"strconv"

"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs"
"github.com/hashicorp/terraform/helper/resource"
"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 @@ -179,6 +185,19 @@ func resourceArmNotificationHubNamespaceDelete(d *schema.ResourceData, meta inte
}
}

// the future returned from the Delete method is broken 50% of the time - let's poll ourselves for now
// TODO: BUG
log.Printf("[DEBUG] Waiting for Notification Hub Namespace %q (Resource Group %q) to be deleted", name, resourceGroup)
stateConf := &resource.StateChangeConf{
Pending: []string{"404"},
Target: []string{"200"},
Refresh: notificationHubNamespaceStateRefreshFunc(ctx, client, resourceGroup, name),
Timeout: 10 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Notification Hub %q (Resource Group %q) to be deleted: %s", name, resourceGroup, err)
}

err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error waiting for the deletion of Notification Hub Namespace %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand Down Expand Up @@ -209,3 +228,14 @@ func flattenNotificationHubNamespacesSku(input *notificationhubs.Sku) []interfac
outputs = append(outputs, output)
return outputs
}

func notificationHubNamespaceStateRefreshFunc(ctx context.Context, client notificationhubs.NamespacesClient, resourceGroupName string, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, resourceGroupName, name)
if err != nil {
return nil, "", fmt.Errorf("Error retrieving Notification Hub Namespace %q (Resource Group %q): %s", name, resourceGroupName, err)
}

return res, strconv.Itoa(res.StatusCode), nil
}
}

0 comments on commit 59ca5de

Please sign in to comment.