flovouin / terraform-provider-metabase Goto Github PK
View Code? Open in Web Editor NEWA Terraform provider for the Metabase service. Also provides a utility to import dashboards and cards as Terraform definitions.
A Terraform provider for the Metabase service. Also provides a utility to import dashboards and cards as Terraform definitions.
Managing the scheduled reports properties on cards and dashboards would be very useful to us.
Metabase has a very useful feature called linked filters, but it seems impossible to use it with this provider. I describe my attempts below:
Let's take a simplest possible dashboard resource with two parameters:
resource "metabase_dashboard" "dashboard" {
name = "๐ Some great dashboard"
description = "๐ก With plenty of actionable stuff."
parameters_json = jsonencode([
{
id = "12345678"
name = "foo"
slug = "foo"
type = "string/="
sectionId = "string"
},
{
id = "23456789"
name = "bar"
slug = "bar"
type = "string/="
sectionId = "string"
},
])
cards_json = jsonencode([])
}
Usually when I want to use some new feature with this provider, I make changes in UI and run terraform plan
to see what's missing in my code.
Strange, let's take a look at network traffic:
The response for GET /api/dashboard/:id has included an appropriate field: filteringParameters
but terraform provider doesn't pick it up.
Let's try to add it to the config:
resource "metabase_dashboard" "dashboard" {
name = "๐ Some great dashboard"
description = "๐ก With plenty of actionable stuff."
parameters_json = jsonencode([
{
id = "12345678"
name = "foo"
slug = "foo"
type = "string/="
sectionId = "string"
filteringParameters = ["23456789"]
},
{
id = "23456789"
name = "bar"
slug = "bar"
type = "string/="
sectionId = "string"
filteringParameters = ["12345678"]
},
])
cards_json = jsonencode([])
}
and run terraform apply
...
Now it shows as a change (it shouldn't because this is already the state of the server).
After confirmation I get an error:
Also network traffic inspections shows that the PUT request did not include the filteringParameters
at all:
which results in my changes made in UI being rolled back:
Seems to me that maybe there is some json processing in the provider both in parsing GET responses and in creating PUT requests which keeps only the known fields, filteringParameters
not being among them. Please let me know if I'm missing something obvious here or just doing it wrong. Cheers!
Metabase added support for API Keys in v0.49. It would be wonderful if we could supply an api key instead of username+password in the provider setup.
Acceptance tests should be run for each pull request.
Hi,
With
I have an error when I create a new collection, the collection is well created but I have the following on console when doing the terraform apply
โ Error: Provider produced inconsistent result after apply
โ
โ When applying changes to metabase_collection.my_business_reports, provider
โ "provider[\"registry.terraform.io/flovouin/metabase\"]" produced an unexpected new value: .color: was
โ cty.StringVal("#cdeabc"), but now null.
โ
โ This is a bug in the provider, which should be reported in the provider's own issue tracker.
Thank you for your work ๐
The metabase_permissions_graph
resource will error if the Metabase Analytics (pro feature) permissions are changed. Example:
โท
โ Error: Unexpected error while calling the Metabase API for operation 'get permissions graph'.
โ
โ json: cannot unmarshal object into Go struct field PermissionsGraphDatabaseAccess.groups.data.schemas of type metabase.PermissionsGraphDatabaseAccessSchemas
โต
This is caused by Metabase changing the response to /api/permissions/graph
to a schema different than what's in metabase-api.yml
. Thus the client is erroring out.
Apply the following terraform:
terraform {
required_version = ">= 1.0"
required_providers {
metabase = {
source = "local/providers/metabase"
version = "1.0.0"
}
}
}
provider "metabase" {
endpoint = "http://localhost:3000/api"
username = < user you created >
password = < password you created >
}
import {
to = metabase_permissions_graph.read
id = 1
}
resource "metabase_permissions_graph" "read" {
advanced_permissions = false
permissions = []
provider = metabase
}
After changing the metabase analytics permissions, response schema from /api/permissions/graph
will differ from what's defined in metabase-api.yml
, leading to errors in the generated client.
Here is a successful response. This was taken from a fresh instance of Metabase Pro with nothing but the sample database. Note the database 13371337
-- this is the metabase analytics database.
{
"revision": 17,
"groups": {
"1": {
"1": {
"download": {
"native": "full",
"schemas": "full"
}
}
},
"2": {
"1": {
"data": {
"native": "write",
"schemas": "all"
},
"download": {
"native": "full",
"schemas": "full"
},
"data-model": {
"schemas": "all"
},
"details": "yes"
},
"13371337": {
"data": {
"native": "write",
"schemas": "all"
},
"download": {
"native": "full",
"schemas": "full"
},
"data-model": {
"schemas": "all"
},
"details": "yes"
}
}
},
"sandboxes": [],
"impersonations": []
}
Response after modifying permissions. Note how schemas
has changed from a string to an object. The OpenAPI spec only allows strings:
terraform-provider-metabase/metabase-api.yaml
Line 1282 in 607ca76
{
"revision": 17,
"groups": {
"1": {
"1": {
"download": {
"native": "full",
"schemas": "full"
}
},
"13371337": {
"data": {
// PROBLEM: `schemas` is not a string:
"schemas": {
"public": {
"9": {
"query": "all"
},
"10": {
"query": "all"
},
"11": {
"query": "all"
},
"12": {
"query": "all"
},
"13": {
"query": "all"
},
"14": {
"query": "all"
},
"15": {
"query": "all"
},
"16": {
"query": "all"
},
"17": {
"query": "all"
},
"18": {
"query": "all"
},
"19": {
"query": "all"
},
"20": {
"query": "all"
},
"21": {
"query": "all"
}
}
}
}
}
},
"2": {
"1": {
"data": {
"native": "write",
"schemas": "all"
},
"download": {
"native": "full",
"schemas": "full"
},
"data-model": {
"schemas": "all"
},
"details": "yes"
},
"13371337": {
"data": {
"native": "write",
"schemas": "all"
},
"download": {
"native": "full",
"schemas": "full"
},
"data-model": {
"schemas": "all"
},
"details": "yes"
}
}
}
}
When I try to create a metabase_dashboard resource using version 0.3.0 of this provider, I receive this error:
Error: Unexpected response while calling the Metabase API for operation 'create dashcard'.
...
Status code: 404, body: "API endpoint does not exist."
In the metabase logs I see that the failing endpoint is POST /api/dashboard/5/cards
.
However when I use the Metabase UI to add cards, I notice that same endpoint but with a PUT, not a POST.
I think the easy solution might be to switch the POST to a PUT when handling the metabase_dashboard
resource's cards_json
attribute.
I would like to be able to export dashboards with tabs using mbtf and be able to execute the generated HCL to build the dashboard accordingly.
Hi @flovouin, amazing job on the provider.
I have been trying to use it manage my permissions but seems like thats not possible if granular permissions are used in metabase.
Attaching the screenshot of what I am facing when importing the metabase_permissions_graph
resource :
Is there a workaround for this? If I can still manage the rest without granular permissions.
Hey there,
thank you for developing this provider. Id like to report a bug:
When applying changes to metabase_database.custom, provider "provider[\"registry.terraform.io/flovouin/metabase\"]" produced an unexpected new value: .custom_details: inconsistent values for sensitive attribute.
This is a bug in the provider, which should be reported in the provider's own issue tracker.
Terraform Code:
metabase = {
source = "flovouin/metabase"
version = "0.4.0"
}
provider "metabase" {
endpoint = "https://${local.metabase_domain}/api"
username = terraform_data.wait_for_metabase.input
password = var.metabase_admin_pw
}
resource "metabase_database" "custom" {
name = "Warehouse"
depends_on = [kubectl_manifest.letsencrypt_issuer_production]
custom_details = {
engine = "postgres"
details_json = jsonencode({
host = "cluster-rw.${kubernetes_namespace.warehouse.metadata[0].name}"
port = data.kubernetes_secret.warehouse.data["port"]
dbname = data.kubernetes_secret.warehouse.data["dbname"]
user = data.kubernetes_secret.warehouse.data["username"]
password = data.kubernetes_secret.warehouse.data["password"]
ssl = false
tunnel-enabled = false
advanced-options = false
})
redacted_attributes = [
"password",
]
}
}
I have tried with both metabase 0.48 and 0.49
Hi @flovouin!
Your provider popped up just in time for me and my team ๐ thank you very much for that!
In the docs of metabase_database resource you mentioned to create an issue for the support of additional databases. That's what this issue is all about.
It would be great for us to manage the following databases by your provider:
Best,
Pierre
mbtf
can currently be installed manually by checking out the repository and running go install
. It would be nice to distribute it as a release artefact, such that it can be downloaded from GitHub directly.
It would be great to have proper support for models
I would like to be able to export through mbtf all table metadata values.
Description
Visibility
Cast to a specific data type
Filtering on this field
Display values
Formatting -> Display as, Date style, abbreviate days and months, show the time, time style
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.