Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_admin added to grafana_user. #157

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions grafana/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func ResourceUser() *schema.Resource {
Required: true,
Sensitive: true,
},
"is_admin": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand All @@ -53,6 +58,12 @@ func CreateUser(d *schema.ResourceData, meta interface{}) error {
if err != nil {
return err
}
if d.HasChange("is_admin") {
err = client.UpdateUserPermissions(id, d.Get("is_admin").(bool))
if err != nil {
return err
}
}
d.SetId(strconv.FormatInt(id, 10))
return ReadUser(d, meta)
}
Expand All @@ -70,6 +81,7 @@ func ReadUser(d *schema.ResourceData, meta interface{}) error {
d.Set("email", user.Email)
d.Set("name", user.Name)
d.Set("login", user.Login)
d.Set("is_admin", user.IsAdmin)
return nil
}

Expand All @@ -95,6 +107,12 @@ func UpdateUser(d *schema.ResourceData, meta interface{}) error {
return err
}
}
if d.HasChange("is_admin") {
err = client.UpdateUserPermissions(id, d.Get("is_admin").(bool))
if err != nil {
return err
}
}
return ReadUser(d, meta)
}

Expand Down
5 changes: 5 additions & 0 deletions grafana/resource_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func TestAccUser_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"grafana_user.test", "password", "zyx987",
),
resource.TestCheckResourceAttr(
"grafana_user.test", "is_admin", "true",
),
),
},
},
Expand Down Expand Up @@ -103,6 +106,7 @@ resource "grafana_user" "test" {
name = "Terraform Test"
login = "tt"
password = "abc123"
is_admin = false
}
`

Expand All @@ -112,5 +116,6 @@ resource "grafana_user" "test" {
name = "Terraform Test Update"
login = "ttu"
password = "zyx987"
is_admin = true
}
`
2 changes: 2 additions & 0 deletions website/docs/r/user.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "grafana_user" "staff" {
name = "Staff Name"
login = "staff"
password = "my-password"
is_admin = false
}
```

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

## Attributes Reference

Expand Down