Skip to content

grafana_folder can be moved to a different parent folder #2278

@patst

Description

@patst

Feature Request

Hey there,

we have a lot of existing Grafana Folders and want to move them to a new parent by setting the parent_folder_uid attribute.

Unfortunately, this will recreate the folders because forceNew: true is set on the grafana_folder.parent_folder_uid attribute.

I would like to change that and add instead this code to the UpdateFolder method

	if d.HasChange("parent_folder_uid") {
		parentUID, ok := d.GetOk("parent_folder_uid")
		if !ok {
			// If the parent folder UID is not set, we can just clear it
			folder.ParentUID = ""
		} else {
			err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
				parentFolder, err := GetFolderByIDorUID(client.Folders, parentUID.(string))
				if err != nil {
					return retry.RetryableError(err)
				}
				folder.ParentUID = parentFolder.UID
				return nil
			})

			if err != nil {
				return diag.Errorf("failed to find parent folder '%s': %s", parentUID, err)
			}
		}
		body := models.MoveFolderCommand{
			ParentUID: folder.ParentUID,
		}
		if _, err := client.Folders.MoveFolder(folder.UID, &body); err != nil {
			return diag.FromErr(err)
		}
	}

local tests looked promising and moving to a new subfolder, moving back to root and setting an invalid UID lead to the expected results.

I will create a Pull Request with the changes and hopefully you agree this is a good feature ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions