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

Terraform removes uid from config_json before create dashboard on Grafana #121

Closed
ghost opened this issue Oct 7, 2020 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Oct 7, 2020

Terraform Version

➜  terraform -v
Terraform v0.13.4

Affected Resource(s)

  • grafana_dashboard

Terraform Configuration Files

my_dashboard.tpl

➜  tail -5 my_dashboard.tpl
    "timezone":"browser",
    "title":"my dashboard",
    "uid":"JOUdHGZZz",
    "version":1
}

grafana.tf

data "template_file" "dashboard" {
  template = file("${path.module}/templates/my_dashboard.tpl")
  vars = {
    DATASOURCE = var.grafana_datasource
  }
}

resource "grafana_dashboard" "main" {
  folder      = "my_folder"
  config_json = data.template_file.dashboard.rendered
  depends_on  = [data.template_file.dashboard]
}

Debug Output

NA

Panic Output

NA

Expected Behavior

Have the same uid (JOUdHGZZz) on Grafana, so URL should be:
https://abc.company.com/d/JOUdHGZZz/my-dashboard

Actual Behavior

Grafana shows different uid, the dashboard URL is:
https://abc.company.com/d/dlhHPsFGk/my-dashboard

From Grafana documentation "If the dashboard in the json file contains an uid, Grafana will force insert/update on that uid". So, this mean that somehow Terraform is not sending the uid that I add on tpl (json).

From terraform-provider-grafana (here) I see that on function prepareDashboardModel both, id and uid, are being removed from json before sending this data to Grafana. This justifies why Grafana is creating new uid..

func prepareDashboardModel(configJSON string) map[string]interface{} {
	configMap := map[string]interface{}{}
	err := json.Unmarshal([]byte(configJSON), &configMap)
	if err != nil {
		// The validate function should've taken care of this.
		panic(fmt.Errorf("Invalid JSON got into prepare func"))
	}

	delete(configMap, "id")
	// Only exists in 5.0+
	delete(configMap, "uid")
	configMap["version"] = 0

	return configMap
}

Is there any reason why uid is being removed?

uid is being used for Grafana to build the URL.. any other alternatives?

Steps to Reproduce

Send uid on json

Important Factoids

NA

References

NA

@chelomontilla
Copy link

chelomontilla commented Oct 20, 2020

I'm facing same issue also, it's something basic, I can't link one dashboard with another because of this.

@Arola1982
Copy link
Contributor

Same issue...

@trotttrotttrott
Copy link
Member

Resolved in #217

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

No branches or pull requests

3 participants