Skip to content

Commit 7ab97a4

Browse files
Merge pull request #157 from AlirezaKm/master
is_admin added to grafana_user.
2 parents 31f2f7e + 93dbbf4 commit 7ab97a4

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

grafana/resource_user.go

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func ResourceUser() *schema.Resource {
3737
Required: true,
3838
Sensitive: true,
3939
},
40+
"is_admin": {
41+
Type: schema.TypeBool,
42+
Optional: true,
43+
Default: false,
44+
},
4045
},
4146
}
4247
}
@@ -53,6 +58,12 @@ func CreateUser(d *schema.ResourceData, meta interface{}) error {
5358
if err != nil {
5459
return err
5560
}
61+
if d.HasChange("is_admin") {
62+
err = client.UpdateUserPermissions(id, d.Get("is_admin").(bool))
63+
if err != nil {
64+
return err
65+
}
66+
}
5667
d.SetId(strconv.FormatInt(id, 10))
5768
return ReadUser(d, meta)
5869
}
@@ -70,6 +81,7 @@ func ReadUser(d *schema.ResourceData, meta interface{}) error {
7081
d.Set("email", user.Email)
7182
d.Set("name", user.Name)
7283
d.Set("login", user.Login)
84+
d.Set("is_admin", user.IsAdmin)
7385
return nil
7486
}
7587

@@ -95,6 +107,12 @@ func UpdateUser(d *schema.ResourceData, meta interface{}) error {
95107
return err
96108
}
97109
}
110+
if d.HasChange("is_admin") {
111+
err = client.UpdateUserPermissions(id, d.Get("is_admin").(bool))
112+
if err != nil {
113+
return err
114+
}
115+
}
98116
return ReadUser(d, meta)
99117
}
100118

grafana/resource_user_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func TestAccUser_basic(t *testing.T) {
5656
resource.TestCheckResourceAttr(
5757
"grafana_user.test", "password", "zyx987",
5858
),
59+
resource.TestCheckResourceAttr(
60+
"grafana_user.test", "is_admin", "true",
61+
),
5962
),
6063
},
6164
},
@@ -103,6 +106,7 @@ resource "grafana_user" "test" {
103106
name = "Terraform Test"
104107
login = "tt"
105108
password = "abc123"
109+
is_admin = false
106110
}
107111
`
108112

@@ -112,5 +116,6 @@ resource "grafana_user" "test" {
112116
name = "Terraform Test Update"
113117
login = "ttu"
114118
password = "zyx987"
119+
is_admin = true
115120
}
116121
`

website/docs/r/user.html.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ resource "grafana_user" "staff" {
2222
name = "Staff Name"
2323
login = "staff"
2424
password = "my-password"
25+
is_admin = false
2526
}
2627
```
2728

@@ -33,6 +34,7 @@ The following arguments are supported:
3334
* `name` - (Optional) The display name for the Grafana user.
3435
* `login` - (Optional) The username for the Grafana user.
3536
* `password` - (Optional) The password for the Grafana user.
37+
* `is_admin` - (Optional, default if `false`) The admin privileges for the Grafana user.
3638

3739
## Attributes Reference
3840

0 commit comments

Comments
 (0)