Skip to content

Commit

Permalink
Fix crash related to empty block in lb_vs resource
Browse files Browse the repository at this point in the history
Empty block can be configured when no required attributes are
defined in the block. In this case nil protection is required,
since empty block is presented as nil rather than empty map in the
schema structure.

Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Nov 6, 2024
1 parent 75e799f commit 5f755b8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nsxt/resource_nsxt_policy_lb_virtual_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,10 @@ func getPolicyLbRuleVariablePersistenceLearnActionSchema() *schema.Schema {
func getPolicyClientSSLBindingFromSchema(d *schema.ResourceData) *model.LBClientSslProfileBinding {
bindings := d.Get("client_ssl").([]interface{})
for _, binding := range bindings {
if binding == nil {
// empty clause
continue
}
// maximum count is one
data := binding.(map[string]interface{})
chainDepth := int64(data["certificate_chain_depth"].(int))
Expand Down Expand Up @@ -958,6 +962,10 @@ func setPolicyClientSSLBindingInSchema(d *schema.ResourceData, binding *model.LB
func getPolicyServerSSLBindingFromSchema(d *schema.ResourceData) *model.LBServerSslProfileBinding {
bindings := d.Get("server_ssl").([]interface{})
for _, binding := range bindings {
if binding == nil {
// empty clause
continue
}
// maximum count is one
data := binding.(map[string]interface{})
chainDepth := int64(data["certificate_chain_depth"].(int))
Expand Down Expand Up @@ -1402,6 +1410,10 @@ func getPolicyLbRulesFromSchema(d *schema.ResourceData) []model.LBRule {
rules := d.Get("rule").([]interface{})

for _, rule := range rules {
if rule == nil {
// empty clause
continue
}
ruleData := rule.(map[string]interface{})

displayName := ruleData["display_name"].(string)
Expand All @@ -1412,6 +1424,10 @@ func getPolicyLbRulesFromSchema(d *schema.ResourceData) []model.LBRule {

ruleActions := ruleData["action"]
for _, ruleAction := range ruleActions.([]interface{}) {
if ruleAction == nil {
// empty clause
continue
}

ruleAction := ruleAction.(map[string]interface{})

Expand Down Expand Up @@ -1474,6 +1490,10 @@ func getPolicyLbRulesFromSchema(d *schema.ResourceData) []model.LBRule {

ruleConditions := ruleData["condition"]
for _, ruleCondition := range ruleConditions.([]interface{}) {
if ruleCondition == nil {
// empty clause
continue
}

ruleCondition := ruleCondition.(map[string]interface{})

Expand Down

0 comments on commit 5f755b8

Please sign in to comment.