Unassociate firewall rule from policy before delete

This commit is contained in:
Guillaume Giamarchi 2015-02-18 01:01:46 +01:00 committed by Jon Perritt
parent 54174dcc05
commit ed31588b84
1 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/policies"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/fwaas/rules"
)
@ -208,5 +209,18 @@ func resourceFirewallRuleDelete(d *schema.ResourceData, meta interface{}) error
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
rule, err := rules.Get(networkingClient, d.Id()).Extract()
if err != nil {
return err
}
if rule.PolicyID != "" {
err := policies.RemoveRule(networkingClient, rule.PolicyID, rule.ID)
if err != nil {
return err
}
}
return rules.Delete(networkingClient, d.Id()).Err
}