Skip to content

Commit 4aefece

Browse files
Implement grafana_data_source_permission_item
Part of #1000 Built on top of #1465 Lots of common code between these two PRs but I'll make a lot of it common in a future PR. There is still the dashboards and service account permissions to implement
1 parent 8f37a84 commit 4aefece

File tree

8 files changed

+585
-2
lines changed

8 files changed

+585
-2
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_data_source_permission_item Resource - terraform-provider-grafana"
4+
subcategory: "Grafana Enterprise"
5+
description: |-
6+
Manages a single permission item for a datasource. Conflicts with the "grafanadatasourcepermission" resource which manages the entire set of permissions for a datasource.
7+
* Official documentation https://grafana.com/docs/grafana/latest/administration/roles-and-permissions/access-control/
8+
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/httpapi/datasource_permissions/)
9+
---
10+
11+
# grafana_data_source_permission_item (Resource)
12+
13+
Manages a single permission item for a datasource. Conflicts with the "grafana_data_source_permission" resource which manages the entire set of permissions for a datasource.
14+
* [Official documentation](https://grafana.com/docs/grafana/latest/administration/roles-and-permissions/access-control/)
15+
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/datasource_permissions/)
16+
17+
## Example Usage
18+
19+
```terraform
20+
resource "grafana_team" "team" {
21+
name = "Team Name"
22+
}
23+
24+
resource "grafana_data_source" "foo" {
25+
type = "cloudwatch"
26+
name = "cw-example"
27+
28+
json_data_encoded = jsonencode({
29+
defaultRegion = "us-east-1"
30+
authType = "keys"
31+
})
32+
33+
secure_json_data_encoded = jsonencode({
34+
accessKey = "123"
35+
secretKey = "456"
36+
})
37+
}
38+
39+
resource "grafana_user" "user" {
40+
name = "test-ds-permissions"
41+
42+
login = "test-ds-permissions"
43+
password = "hunter2"
44+
}
45+
46+
resource "grafana_service_account" "sa" {
47+
name = "test-ds-permissions"
48+
role = "Viewer"
49+
}
50+
51+
resource "grafana_data_source_permission_item" "team" {
52+
datasource_uid = grafana_data_source.foo.uid
53+
team = grafana_team.team.id
54+
permission = "Edit"
55+
}
56+
57+
resource "grafana_data_source_permission_item" "user" {
58+
datasource_uid = grafana_data_source.foo.uid
59+
user = grafana_user.user.id
60+
permission = "Edit"
61+
}
62+
63+
resource "grafana_data_source_permission_item" "role" {
64+
datasource_uid = grafana_data_source.foo.uid
65+
built_in_role = "Viewer"
66+
permission = "Query"
67+
}
68+
69+
resource "grafana_data_source_permission_item" "service_account" {
70+
datasource_uid = grafana_data_source.foo.uid
71+
service_account = grafana_service_account.sa.id
72+
permission = "Query"
73+
}
74+
```
75+
76+
<!-- schema generated by tfplugindocs -->
77+
## Schema
78+
79+
### Required
80+
81+
- `datasource_uid` (String) The UID of the datasource.
82+
- `permission` (String) the permission to be assigned
83+
84+
### Optional
85+
86+
- `org_id` (String) The Organization ID. If not set, the Org ID defined in the provider block will be used.
87+
- `role` (String) the role onto which the permission is to be assigned
88+
- `team` (String) the team onto which the permission is to be assigned
89+
- `user` (String) the user or service account onto which the permission is to be assigned
90+
91+
### Read-Only
92+
93+
- `id` (String) The ID of this resource.
94+
95+
## Import
96+
97+
Import is supported using the following syntax:
98+
99+
```shell
100+
terraform import grafana_data_source_permission_item.name "{{ datasourceUID }}:{{ type (role, team, or user) }}:{{ identifier }}"
101+
terraform import grafana_data_source_permission_item.name "{{ orgID }}:{{ datasourceUID }}:{{ type (role, team, or user) }}:{{ identifier }}"
102+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
terraform import grafana_data_source_permission_item.name "{{ datasourceUID }}:{{ type (role, team, or user) }}:{{ identifier }}"
2+
terraform import grafana_data_source_permission_item.name "{{ orgID }}:{{ datasourceUID }}:{{ type (role, team, or user) }}:{{ identifier }}"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
resource "grafana_team" "team" {
2+
name = "Team Name"
3+
}
4+
5+
resource "grafana_data_source" "foo" {
6+
type = "cloudwatch"
7+
name = "cw-example"
8+
9+
json_data_encoded = jsonencode({
10+
defaultRegion = "us-east-1"
11+
authType = "keys"
12+
})
13+
14+
secure_json_data_encoded = jsonencode({
15+
accessKey = "123"
16+
secretKey = "456"
17+
})
18+
}
19+
20+
resource "grafana_user" "user" {
21+
name = "test-ds-permissions"
22+
23+
login = "test-ds-permissions"
24+
password = "hunter2"
25+
}
26+
27+
resource "grafana_service_account" "sa" {
28+
name = "test-ds-permissions"
29+
role = "Viewer"
30+
}
31+
32+
resource "grafana_data_source_permission_item" "team" {
33+
datasource_uid = grafana_data_source.foo.uid
34+
team = grafana_team.team.id
35+
permission = "Edit"
36+
}
37+
38+
resource "grafana_data_source_permission_item" "user" {
39+
datasource_uid = grafana_data_source.foo.uid
40+
user = grafana_user.user.id
41+
permission = "Edit"
42+
}
43+
44+
resource "grafana_data_source_permission_item" "role" {
45+
datasource_uid = grafana_data_source.foo.uid
46+
built_in_role = "Viewer"
47+
permission = "Query"
48+
}
49+
50+
resource "grafana_data_source_permission_item" "service_account" {
51+
datasource_uid = grafana_data_source.foo.uid
52+
service_account = grafana_service_account.sa.id
53+
permission = "Query"
54+
}
55+

0 commit comments

Comments
 (0)