-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding validation while setting empty active ranges (#9125)
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
mmv1/templates/terraform/constants/router_nat_validate_action_active_range.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% unless version == 'ga' -%> | ||
// validates if the field action.source_nat_active_ranges is filled when the type is PRIVATE. | ||
natType := d.Get("type").(string) | ||
if natType == "PRIVATE" { | ||
rules := d.Get("rules").(*schema.Set) | ||
for _, rule := range rules.List() { | ||
objRule := rule.(map[string]interface{}) | ||
actions := objRule["action"].([]interface{}) | ||
|
||
containAction := len(actions) != 0 && actions[0] != nil | ||
containActiveRange := true | ||
|
||
if containAction { | ||
action := actions[0].(map[string]interface{}) | ||
sourceNatActiveRanges := action["source_nat_active_ranges"] | ||
if sourceNatActiveRanges != nil { | ||
sourceNatActiveRangesSet := sourceNatActiveRanges.(*schema.Set) | ||
if len(sourceNatActiveRangesSet.List()) == 0 { | ||
containActiveRange = false | ||
} | ||
} | ||
} | ||
|
||
if !containAction || !containActiveRange { | ||
return fmt.Errorf("The rule for PRIVATE nat type must contain an action with source_nat_active_ranges set") | ||
} | ||
} | ||
} | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters