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

provider/azurerm: azurerm_network_security_group now polls for State succeeded #7307

Merged
merged 1 commit into from
Jun 24, 2016
Merged
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
26 changes: 26 additions & 0 deletions builtin/providers/azurerm/resource_arm_network_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package azurerm
import (
"bytes"
"fmt"
"log"
"net/http"
"time"

"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -157,6 +160,18 @@ func resourceArmNetworkSecurityGroupCreate(d *schema.ResourceData, meta interfac
return fmt.Errorf("Cannot read Virtual Network %s (resource group %s) ID", name, resGroup)
}

log.Printf("[DEBUG] Waiting for NSG (%s) to become available", d.Get("name"))
stateConf := &resource.StateChangeConf{
Pending: []string{"Updating", "Creating"},
Target: []string{"Succeeded"},
Refresh: networkSecurityGroupStateRefreshFunc(client, resGroup, name),
Timeout: 30 * time.Minute,
MinTimeout: 15 * time.Second,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for NSG (%s) to become available: %s", d.Get("name"), err)
}

d.SetId(*read.ID)

return resourceArmNetworkSecurityGroupRead(d, meta)
Expand Down Expand Up @@ -282,3 +297,14 @@ func expandAzureRmSecurityRules(d *schema.ResourceData) ([]network.SecurityRule,

return rules, nil
}

func networkSecurityGroupStateRefreshFunc(client *ArmClient, resourceGroupName string, sgName string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.secGroupClient.Get(resourceGroupName, sgName, "")
if err != nil {
return nil, "", fmt.Errorf("Error issuing read request in networkSecurityGroupStateRefreshFunc to Azure ARM for NSG '%s' (RG: '%s'): %s", sgName, resourceGroupName, err)
}

return res, *res.Properties.ProvisioningState, nil
}
}