Skip to content

Commit cebd643

Browse files
Implement grafana_data_source_permission_item (#1470)
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 45b68d5 commit cebd643

File tree

8 files changed

+579
-2
lines changed

8 files changed

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

0 commit comments

Comments
 (0)