Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions splunk/resource_splunk_authorization_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
}
Expand Down