Fix race conditions on firewall state transition
This commit is contained in:
parent
d6733fb379
commit
1c981d6f30
|
@ -37,7 +37,6 @@ func resourceFWFirewallV2() *schema.Resource {
|
||||||
"policy_id": &schema.Schema{
|
"policy_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
|
||||||
},
|
},
|
||||||
"admin_state_up": &schema.Schema{
|
"admin_state_up": &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
|
@ -89,16 +88,10 @@ func resourceFirewallCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
MinTimeout: 2 * time.Second,
|
MinTimeout: 2 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(firewall.ID)
|
|
||||||
|
|
||||||
d.Set("name", firewall.Name)
|
|
||||||
d.Set("description", firewall.Description)
|
|
||||||
d.Set("policy_id", firewall.PolicyID)
|
|
||||||
d.Set("admin_state_up", firewall.AdminStateUp)
|
|
||||||
d.Set("tenant_id", firewall.TenantID)
|
|
||||||
|
|
||||||
_, err = stateConf.WaitForState()
|
_, err = stateConf.WaitForState()
|
||||||
|
|
||||||
|
d.SetId(firewall.ID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +122,7 @@ func resourceFirewallRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
d.Set("description", firewall.Description)
|
d.Set("description", firewall.Description)
|
||||||
d.Set("policy_id", firewall.PolicyID)
|
d.Set("policy_id", firewall.PolicyID)
|
||||||
d.Set("admin_state_up", firewall.AdminStateUp)
|
d.Set("admin_state_up", firewall.AdminStateUp)
|
||||||
|
d.Set("tenant_id", firewall.TenantID)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -155,14 +149,15 @@ func resourceFirewallUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
opts.PolicyID = d.Get("policy_id").(string)
|
opts.PolicyID = d.Get("policy_id").(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Updating firewall with id %s: %#v", d.Id(), opts)
|
if d.HasChange("admin_state_up") {
|
||||||
|
adminStateUp := d.Get("admin_state_up").(bool)
|
||||||
if err := firewalls.Update(networkingClient, d.Id(), opts).Err; err != nil {
|
opts.AdminStateUp = &adminStateUp
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Updating firewall with id %s: %#v", d.Id(), opts)
|
||||||
|
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf := &resource.StateChangeConf{
|
||||||
Pending: []string{"PENDING_CREATE"},
|
Pending: []string{"PENDING_CREATE", "PENDING_UPDATE"},
|
||||||
Target: "ACTIVE",
|
Target: "ACTIVE",
|
||||||
Refresh: WaitForFirewallActive(networkingClient, d.Id()),
|
Refresh: WaitForFirewallActive(networkingClient, d.Id()),
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
|
@ -172,7 +167,7 @@ func resourceFirewallUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
_, err = stateConf.WaitForState()
|
_, err = stateConf.WaitForState()
|
||||||
|
|
||||||
return err
|
return firewalls.Update(networkingClient, d.Id(), opts).Err
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceFirewallDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceFirewallDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
@ -184,13 +179,24 @@ func resourceFirewallDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stateConf := &resource.StateChangeConf{
|
||||||
|
Pending: []string{"PENDING_CREATE", "PENDING_UPDATE"},
|
||||||
|
Target: "ACTIVE",
|
||||||
|
Refresh: WaitForFirewallActive(networkingClient, d.Id()),
|
||||||
|
Timeout: 30 * time.Second,
|
||||||
|
Delay: 0,
|
||||||
|
MinTimeout: 2 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = stateConf.WaitForState()
|
||||||
|
|
||||||
err = firewalls.Delete(networkingClient, d.Id()).Err
|
err = firewalls.Delete(networkingClient, d.Id()).Err
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stateConf := &resource.StateChangeConf{
|
stateConf = &resource.StateChangeConf{
|
||||||
Pending: []string{"DELETING"},
|
Pending: []string{"DELETING"},
|
||||||
Target: "DELETED",
|
Target: "DELETED",
|
||||||
Refresh: WaitForFirewallDeletion(networkingClient, d.Id()),
|
Refresh: WaitForFirewallDeletion(networkingClient, d.Id()),
|
||||||
|
|
|
@ -127,18 +127,6 @@ resource "openstack_fw_policy_v2" "accept_test_policy_1" {
|
||||||
`
|
`
|
||||||
|
|
||||||
const testFirewallConfigUpdated = `
|
const testFirewallConfigUpdated = `
|
||||||
resource "openstack_fw_firewall_v2" "accept_test" {
|
|
||||||
name = "accept_test"
|
|
||||||
description = "terraform acceptance test"
|
|
||||||
policy_id = "${openstack_fw_policy_v2.accept_test_policy_1.id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "openstack_fw_policy_v2" "accept_test_policy_1" {
|
|
||||||
name = "policy-1"
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
const testFirewallConfigForceNew = `
|
|
||||||
resource "openstack_fw_firewall_v2" "accept_test" {
|
resource "openstack_fw_firewall_v2" "accept_test" {
|
||||||
name = "accept_test"
|
name = "accept_test"
|
||||||
description = "terraform acceptance test"
|
description = "terraform acceptance test"
|
||||||
|
|
Loading…
Reference in New Issue