Skip to content

Commit

Permalink
Merge pull request #132 from zombispormedio/Allow-import-folders
Browse files Browse the repository at this point in the history
Add folder resource import
  • Loading branch information
trotttrotttrott authored Oct 27, 2020
2 parents 12ac5cc + d37a1ba commit 6fca1d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ website/vendor
# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/

terraform-provider-grafana
4 changes: 4 additions & 0 deletions grafana/resource_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func ResourceFolder() *schema.Resource {
Create: CreateFolder,
Delete: DeleteFolder,
Read: ReadFolder,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

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

d.SetId(strconv.FormatInt(folder.ID, 10))
d.Set("title", folder.Title)
d.Set("uid", folder.UID)

return nil
}
Expand Down
5 changes: 5 additions & 0 deletions grafana/resource_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func TestAccFolder_basic(t *testing.T) {
),
),
},
{
ResourceName: "grafana_folder.test_folder",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
7 changes: 6 additions & 1 deletion website/docs/r/folder.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ The resource exports the following attributes:

## Import

Folders cannot be imported.
Existing folders can be imported using the folder "id" which can be
obtained from Grafana database or inspecting requests in folder (e.g. `https://grafana.mydomain.com/f/abcdef-gh/folder-title`)

```
$ terraform import grafana_folder.folder_name {folder_id}
```

0 comments on commit 6fca1d6

Please sign in to comment.