Skip to content

Commit

Permalink
[SURE-8832] fix: add check for external rules while updating roleTemp…
Browse files Browse the repository at this point in the history
…late

- Modified the roleTemplate update logic to include a check for external rules.
- Added a condition to ensure external rules are only updated when the `external` flag is set.
- Set `externalRules` to `nil` if the `external` flag is not set.

Signed-off-by: Pratik Jagrut <[email protected]>
  • Loading branch information
pratikjagrut committed Sep 5, 2024
1 parent 7e6b059 commit a68b9c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rancher2/resource_rancher2_role_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package rancher2

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

Expand Down Expand Up @@ -110,7 +111,14 @@ func resourceRancher2RoleTemplateUpdate(d *schema.ResourceData, meta interface{}
"rules": expandPolicyRules(d.Get("rules").([]interface{})),
"annotations": toMapString(d.Get("annotations").(map[string]interface{})),
"labels": toMapString(d.Get("labels").(map[string]interface{})),
"externalRules": expandPolicyRules(d.Get("external_rules").([]interface{})),
}

if update["external"].(bool) {
if v, ok := d.Get("external_rules").([]interface{}); ok && len(v) > 0 {
update["externalRules"] = expandPolicyRules(v)
}
} else {
update["externalRules"] = nil
}

switch update["context"] {
Expand Down

0 comments on commit a68b9c6

Please sign in to comment.