Merge pull request #7307 from hashicorp/arm-nsg-polling

provider/azurerm: `azurerm_network_security_group` now polls for State succeeded
This commit is contained in:
James Nugent 2016-06-24 14:29:47 +03:00 committed by GitHub
commit 790307aa7a
1 changed files with 26 additions and 0 deletions

View File

@ -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"
)
@ -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)
@ -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
}
}