Skip to content

Commit c244dab

Browse files
Role Datasource: Find hidden roles (#1552)
* Role Datasource: Find hidden roles Closes #1508 After testing and looking at the role listing params, this seems to me like this is probably the bug Let's close out the issue with this and we'll see if it's re-opened later :) * go generate
1 parent 59c82ca commit c244dab

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

docs/data-sources/role.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ resource "grafana_role" "test" {
2323
uid = "test-ds-role-uid"
2424
version = 1
2525
global = true
26+
hidden = false
2627
2728
permissions {
2829
action = "org.users:add"

examples/data-sources/grafana_role/data-source.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ resource "grafana_role" "test" {
44
uid = "test-ds-role-uid"
55
version = 1
66
global = true
7+
hidden = false
78

89
permissions {
910
action = "org.users:add"

internal/resources/grafana/data_source_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func datasourceRole() *schema.Resource {
3131

3232
func dataSourceRoleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
3333
client, orgID := OAPIClientFromNewOrgResource(meta, d)
34-
resp, err := client.AccessControl.ListRoles(access_control.NewListRolesParams(), nil)
34+
resp, err := client.AccessControl.ListRoles(access_control.NewListRolesParams().WithIncludeHidden(common.Ref(true)), nil)
3535
if err != nil {
3636
return diag.FromErr(err)
3737
}
Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package grafana_test
22

33
import (
4+
"strconv"
45
"testing"
56

67
"github.com/grafana/grafana-openapi-client-go/models"
@@ -12,30 +13,41 @@ func TestAccDatasourceRole_basic(t *testing.T) {
1213
testutils.CheckEnterpriseTestsEnabled(t, ">=9.0.0")
1314

1415
var role models.RoleDTO
15-
checks := []resource.TestCheckFunc{
16-
roleCheckExists.exists("grafana_role.test", &role),
17-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "name", "test-role"),
18-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "description", "test-role description"),
19-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "uid", "test-ds-role-uid"),
20-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "version", "1"),
21-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "global", "true"),
22-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.#", "3"),
23-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.0.action", "org.users:add"),
24-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.0.scope", "users:*"),
25-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.1.action", "org.users:read"),
26-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.1.scope", "users:*"),
27-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.2.action", "org.users:write"),
28-
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.2.scope", "users:*"),
29-
}
16+
for _, hidden := range []bool{false, true} {
17+
formatted := strconv.FormatBool(hidden)
18+
t.Run("hidden="+formatted, func(t *testing.T) {
19+
config := testutils.TestAccExample(t, "data-sources/grafana_role/data-source.tf")
20+
if hidden {
21+
config = testutils.TestAccExampleWithReplace(t, "data-sources/grafana_role/data-source.tf", map[string]string{
22+
`hidden = false`: `hidden = true`,
23+
})
24+
}
3025

31-
resource.ParallelTest(t, resource.TestCase{
32-
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
33-
CheckDestroy: roleCheckExists.destroyed(&role, nil),
34-
Steps: []resource.TestStep{
35-
{
36-
Config: testutils.TestAccExample(t, "data-sources/grafana_role/data-source.tf"),
37-
Check: resource.ComposeTestCheckFunc(checks...),
38-
},
39-
},
40-
})
26+
resource.ParallelTest(t, resource.TestCase{
27+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
28+
CheckDestroy: roleCheckExists.destroyed(&role, nil),
29+
Steps: []resource.TestStep{
30+
{
31+
Config: config,
32+
Check: resource.ComposeTestCheckFunc(
33+
roleCheckExists.exists("grafana_role.test", &role),
34+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "name", "test-role"),
35+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "description", "test-role description"),
36+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "uid", "test-ds-role-uid"),
37+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "version", "1"),
38+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "global", "true"),
39+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "hidden", formatted),
40+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.#", "3"),
41+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.0.action", "org.users:add"),
42+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.0.scope", "users:*"),
43+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.1.action", "org.users:read"),
44+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.1.scope", "users:*"),
45+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.2.action", "org.users:write"),
46+
resource.TestCheckResourceAttr("data.grafana_role.from_name", "permissions.2.scope", "users:*"),
47+
),
48+
},
49+
},
50+
})
51+
})
52+
}
4153
}

0 commit comments

Comments
 (0)