Skip to content

Commit

Permalink
refactor(vpc): add roll back for updating rules of network ACL (#5201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Jul 15, 2024
1 parent cd233d0 commit 35dcdc5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions huaweicloud/services/vpc/resource_huaweicloud_vpc_network_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,22 @@ func updateRules(client *golangsdk.ServiceClient, d *schema.ResourceData, ruleTy
if len(oldRules.([]interface{})) > 0 {
err := networkAclRemoveRules(client, oldRules.([]interface{}), ruleType, id)
if err != nil {
return err
return fmt.Errorf("error updating rules: %s", err)
}
}

if len(newRules.([]interface{})) > 0 {
err := networkAclInsertRules(client, newRules.([]interface{}), ruleType, id)
if err != nil {
return err
// if failed to insert the new rules, insert the old rules back
if len(oldRules.([]interface{})) > 0 {
rollBackErr := networkAclInsertRules(client, oldRules.([]interface{}), ruleType, id)
if rollBackErr != nil {
return fmt.Errorf("error updating rules: %s, failed to roll back: %s", err, rollBackErr)
}
return fmt.Errorf("error updating rules: %s, it's rolled back", err)
}
return fmt.Errorf("error updating rules: %s", err)
}
}

Expand Down

0 comments on commit 35dcdc5

Please sign in to comment.