Refresh firewall rules after each failure before trying to append new rules

This commit is contained in:
Brett Mack 2015-11-02 19:09:24 +00:00
parent 965882bfdf
commit 95ec9a9fbf
1 changed files with 11 additions and 6 deletions

View File

@ -89,14 +89,19 @@ func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) er
defer vcd_client.Mutex.Unlock() defer vcd_client.Mutex.Unlock()
edgeGateway, err := vcd_client.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string)) edgeGateway, err := vcd_client.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
firewallRules, _ := expandFirewallRules(d.Get("rule").(*schema.Set).List(), edgeGateway.EdgeGateway)
task, err := edgeGateway.CreateFirewallRules(d.Get("default_action").(string), firewallRules)
if err != nil { if err != nil {
return fmt.Errorf("Error setting firewall rules: %#v", err) return fmt.Errorf("Unable to find edge gateway: %s", err)
} }
err = task.WaitTaskCompletion()
err = retryCall(5, func() error {
edgeGateway.Refresh()
firewallRules, _ := expandFirewallRules(d.Get("rule").(*schema.Set).List(), edgeGateway.EdgeGateway)
task, err := edgeGateway.CreateFirewallRules(d.Get("default_action").(string), firewallRules)
if err != nil {
return fmt.Errorf("Error setting firewall rules: %#v", err)
}
return task.WaitTaskCompletion()
})
if err != nil { if err != nil {
return fmt.Errorf("Error completing tasks: %#v", err) return fmt.Errorf("Error completing tasks: %#v", err)
} }