Skip to content

Commit b44779d

Browse files
Add folder resource import
1 parent 12ac5cc commit b44779d

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ website/vendor
2929
# Test exclusions
3030
!command/test-fixtures/**/*.tfstate
3131
!command/test-fixtures/**/.terraform/
32+
33+
terraform-provider-grafana

grafana/resource_folder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func ResourceFolder() *schema.Resource {
1717
Create: CreateFolder,
1818
Delete: DeleteFolder,
1919
Read: ReadFolder,
20+
Importer: &schema.ResourceImporter{
21+
State: schema.ImportStatePassthrough,
22+
},
2023

2124
Schema: map[string]*schema.Schema{
2225
"uid": {
@@ -72,6 +75,7 @@ func ReadFolder(d *schema.ResourceData, meta interface{}) error {
7275

7376
d.SetId(strconv.FormatInt(folder.ID, 10))
7477
d.Set("title", folder.Title)
78+
d.Set("uid", folder.UID)
7579

7680
return nil
7781
}

grafana/resource_folder_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func TestAccFolder_basic(t *testing.T) {
3232
),
3333
),
3434
},
35+
{
36+
ResourceName: "grafana_folder.test_folder",
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
},
3540
},
3641
})
3742
}

website/docs/r/folder.html.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: |-
66
The grafana_folder resource allows a Grafana folder to be created.
77
---
88

9-
# grafana\_folder
9+
# grafana_folder
1010

1111
The folder resource allows a folder to be created on a Grafana server.
1212

@@ -27,18 +27,23 @@ resource "grafana_dashboard" "dashboard_in_folder" {
2727

2828
The following arguments are supported:
2929

30-
* `title` - (Required) The title of the folder.
30+
- `title` - (Required) The title of the folder.
3131

3232
## Attributes Reference
3333

3434
The resource exports the following attributes:
3535

36-
* `id` - The internal id of the folder in Grafana (only guaranteed to be unique
36+
- `id` - The internal id of the folder in Grafana (only guaranteed to be unique
3737
within this Grafana instance). The `id` is used by the `grafana_dashboard` resource
3838
to place a dashboard within a folder.
39-
* `uid` - An external id of the folder in Grafana (stable when folders are migrated
39+
- `uid` - An external id of the folder in Grafana (stable when folders are migrated
4040
between Grafana instances). The `uid` is required by several Grafana Folder APIs.
4141

4242
## Import
4343

44-
Folders cannot be imported.
44+
Existing folders can be imported using the folder "id" which can be
45+
obtained from Grafana database or inspecting requests in folder (e.g. `https://grafana.mydomain.com/f/abcdef-gh/folder-title`)
46+
47+
```
48+
$ terraform import grafana_folder.folder_name {folder_id}
49+
```

0 commit comments

Comments
 (0)