From cf0b9b4e215e008aecd7c2a902747fd8417da7d0 Mon Sep 17 00:00:00 2001 From: rvasikarla Date: Thu, 30 Apr 2026 20:45:51 -0500 Subject: [PATCH] Fix role name case sensitivity causing state mismatch on Splunk Cloud Splunk server lowercases role names on creation. When a role is created with uppercase characters, subsequent reads fail to find the role because the comparison uses exact case matching against the lowercased server-side name. Fix: - Add StateFunc to lowercase the name attribute in state - Use strings.EqualFold for case-insensitive name matching in read - Store lowercased role name as the resource ID Fixes #87 --- splunk/resource_splunk_authorization_roles.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/splunk/resource_splunk_authorization_roles.go b/splunk/resource_splunk_authorization_roles.go index 9bf939fa..eb574f51 100644 --- a/splunk/resource_splunk_authorization_roles.go +++ b/splunk/resource_splunk_authorization_roles.go @@ -4,11 +4,12 @@ import ( "encoding/json" "errors" "fmt" - "github.com/splunk/terraform-provider-splunk/client/models" "net/http" "regexp" + "strings" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/splunk/terraform-provider-splunk/client/models" ) func authorizationRoles() *schema.Resource { @@ -19,6 +20,9 @@ func authorizationRoles() *schema.Resource { Required: true, ForceNew: true, Description: "Required. The name of the user role to create.", + StateFunc: func(val interface{}) string { + return strings.ToLower(val.(string)) + }, }, "capabilities": { Type: schema.TypeSet, @@ -154,7 +158,8 @@ func authorizationRolesCreate(d *schema.ResourceData, meta interface{}) error { return err } - d.SetId(name) + // Splunk server lowercases role names, so we store the lowercased version + d.SetId(strings.ToLower(name)) return authorizationRolesRead(d, meta) } @@ -321,7 +326,7 @@ func getAuthorizationRolesByName(name string, httpResponse *http.Response) (Auth _ = json.NewDecoder(httpResponse.Body).Decode(&response) re := regexp.MustCompile(`(.*)`) for _, entry := range response.Entry { - if name == re.FindStringSubmatch(entry.Name)[1] { + if strings.EqualFold(name, re.FindStringSubmatch(entry.Name)[1]) { return &entry, nil } }