Skip to content

Commit

Permalink
PATCH: Format rules that should be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroden84 committed Aug 3, 2023
1 parent 8aa9fd7 commit 342bb1f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions cloudamqp/resource_cloudamqp_security_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,36 @@ func resourceSecurityFirewallUpdate(d *schema.ResourceData, meta interface{}) er
}

func resourceSecurityFirewallDelete(d *schema.ResourceData, meta interface{}) error {
var (
api = meta.(*api.API)
instanceID = d.Get("instance_id").(int)
sleep = d.Get("sleep").(int)
timeout = d.Get("timeout").(int)
replace = d.Get("replace").(bool)
)

if enableFasterInstanceDestroy == true {
log.Printf("[DEBUG] cloudamqp::resource::security_firewall::delete skip calling backend.")
return nil
}

api := meta.(*api.API)
log.Printf("[DEBUG] cloudamqp::resource::security_firewall::delete instance id: %v", d.Get("instance_id"))
data, err := api.DeleteFirewallSettings(d.Get("instance_id").(int), d.Get("sleep").(int), d.Get("timeout").(int))
d.Set("rules", data)
if replace {
data, err := api.DeleteFirewallSettings(instanceID, sleep, timeout)
d.Set("rules", data)
return err
}

var params []map[string]interface{}
localFirewalls := d.Get("rules").(*schema.Set).List()
log.Printf("[DEBUG] Delete firewall rules: %v", localFirewalls)
for _, k := range localFirewalls {
rule := k.(map[string]interface{})
rule["services"] = []string{}
rule["ports"] = []int{}
params = append(params, rule)
}
log.Printf("[DEBUG] Delete firewall params: %v", params)
err := api.PatchFirewallSettings(instanceID, params, sleep, timeout)
return err
}

Expand Down

0 comments on commit 342bb1f

Please sign in to comment.