Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboard: ForceNew on folder parameter not needed (anymore)? #1105

Closed
wotolom opened this issue Oct 26, 2023 · 0 comments · Fixed by #1110
Closed

dashboard: ForceNew on folder parameter not needed (anymore)? #1105

wotolom opened this issue Oct 26, 2023 · 0 comments · Fixed by #1110

Comments

@wotolom
Copy link

wotolom commented Oct 26, 2023

Terraform Version

  • Terraform: ...
  • Terraform Grafana Provider: 2.3.3
  • Grafana: v10.0.2

Affected Resource(s)

Please list the resources as a list, for example:

  • grafana_dashboard

Issue

Currently the parameter folder of the dashboard resource has the ForceNew: true set:

"folder": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,

For the crossplane provider-grafana this can be annoying as it makes the field folder practically immutable. See this upjet issue discussing how to handle fields with ForceNew: true.

Nonetheless in this case I actually have difficulty to understand why changing folder needs ForceNew: true set.

relevant history check of dashboard resource:

However when testing - with curl or the grafana-api-golang-client - to move a dashboard between 2 folders, I actually did not ran into any problems.

Here my go code used for testing:

package main

import (
	log "log"

	gapi "github.com/grafana/grafana-api-golang-client"
)

func main() {

	// Create a new client
	c, err := gapi.New("<INSERT_GRAFANA_URL>", gapi.Config{
		APIKey: "<INSERT_APIKEY_OR_SERVICEACCOUNTTOKEN>",
	})
	if err != nil {
		log.Fatal(err)
	}

	// create folders
	folder1 := "golang-folder1"
	respFolder1, err := c.NewFolder(folder1, folder1)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("create folder action response: %v", respFolder1)
	folder2 := "golang-folder2"
	respFolder2, err := c.NewFolder(folder2, folder2)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("create folder action response: %v", respFolder2)

	// create dashboard
	dash := "golang-api-test"
	respDash1, err := c.NewDashboard(gapi.Dashboard{
		Overwrite: true, // needed to update
		Model: map[string]interface{}{
			"title":   dash,
			"uid":     dash,
			"version": "1", // seems to be ignored
		},
		FolderUID: folder1,
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("create dashboard action response: %v", respDash1)

	// check dashboard folder location
	resp1, err := c.DashboardByUID(dash)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("check dashboard action response: %v", resp1)

	// "update" dashboard
	respDash2, err := c.NewDashboard(gapi.Dashboard{
		Overwrite: true, // needed to update
		Model: map[string]interface{}{
			"title":   dash,
			"uid":     dash,
			"version": "1", // seems to be ignored
		},
		FolderUID: folder2,
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("update dashboard action response: %v", respDash2) // accepts changes, version will go up

	// check dashboard folder location
	resp2, err := c.DashboardByUID(dash)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("check dashboard action response: %v", resp2)

	// delete folders + dashboard
	log.Print("delete dashboard ...")
	err = c.DeleteDashboardByUID(dash)
	if err != nil {
		log.Fatal(err)
	}
	log.Print("delete folder1 ...")
	err = c.DeleteFolder(folder1) // wants uid not id ...
	if err != nil {
		log.Fatal(err)
	}
	log.Print("delete folder2 ...")
	err = c.DeleteFolder(folder2) // wants uid not id ...
	if err != nil {
		log.Fatal(err)
	}
}

Produced output logs:

2023/10/26 11:27:27 create folder action response: {1994 golang-folder1 golang-folder1 /dashboards/f/golang-folder1/golang-folder1}
2023/10/26 11:27:27 create folder action response: {1995 golang-folder2 golang-folder2 /dashboards/f/golang-folder2/golang-folder2}
2023/10/26 11:27:28 create dashboard action response: &{golang-api-test 1996 golang-api-test success 1}
2023/10/26 11:27:28 check dashboard action response: &{map[id:1996 title:golang-api-test uid:golang-api-test version:1] 1994 {false golang-api-test 1994 golang-folder1 /d/golang-api-test/golang-api-test} false  }
2023/10/26 11:27:28 update dashboard action response: &{golang-api-test 1996 golang-api-test success 2}
2023/10/26 11:27:28 check dashboard action response: &{map[id:1996 title:golang-api-test uid:golang-api-test version:2] 1995 {false golang-api-test 1995 golang-folder2 /d/golang-api-test/golang-api-test} false  }
2023/10/26 11:27:28 delete dashboard ...
2023/10/26 11:27:28 delete folder1 ...
2023/10/26 11:27:28 delete folder2 ...
@wotolom wotolom added the bug label Oct 26, 2023
julienduchesne added a commit that referenced this issue Oct 30, 2023
Closes #1105
Also removed the folder static examples to replace them with code. Too many variables now
julienduchesne added a commit that referenced this issue Oct 31, 2023
Closes #1105
Also removed the folder static examples to replace them with code. Too many variables now
julienduchesne added a commit that referenced this issue Nov 1, 2023
Closes #1105
Also removed the folder static examples to replace them with code. Too many variables now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant