From 9f242a0354c8cac5e9e96ef3df488e6b946ea6af Mon Sep 17 00:00:00 2001 From: Pratik Jagrut Date: Thu, 5 Sep 2024 21:09:38 +0530 Subject: [PATCH] [SURE-8832] fix: add check for external rules while updating roleTemplate (#1389) Signed-off-by: Pratik Jagrut (cherry picked from commit 4d338b6579ff7b67e3627bbfe47d08548bd77172) --- rancher2/resource_rancher2_role_template.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rancher2/resource_rancher2_role_template.go b/rancher2/resource_rancher2_role_template.go index 68318ac5..9b1a73a4 100644 --- a/rancher2/resource_rancher2_role_template.go +++ b/rancher2/resource_rancher2_role_template.go @@ -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" ) @@ -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"] {