From 95ec9a9fbfad0f3cfe80737183f336bfa89854f8 Mon Sep 17 00:00:00 2001 From: Brett Mack Date: Mon, 2 Nov 2015 19:09:24 +0000 Subject: [PATCH] Refresh firewall rules after each failure before trying to append new rules --- .../vcd/resource_vcd_firewall_rules.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/builtin/providers/vcd/resource_vcd_firewall_rules.go b/builtin/providers/vcd/resource_vcd_firewall_rules.go index e025b143f..3581f1179 100644 --- a/builtin/providers/vcd/resource_vcd_firewall_rules.go +++ b/builtin/providers/vcd/resource_vcd_firewall_rules.go @@ -89,14 +89,19 @@ func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) er defer vcd_client.Mutex.Unlock() 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 { - 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 { return fmt.Errorf("Error completing tasks: %#v", err) }