flovouin / terraform-provider-metabase

A Terraform provider for the Metabase service. Also provides a utility to import dashboards and cards as Terraform definitions.
21 stars 6 forks source link

Error Creating Dashboard's Cards: API Endpoint Does Not Exist #31

Closed mcmohorn closed 8 months ago

mcmohorn commented 10 months ago

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.

Screenshot 2023-12-01 at 12 07 24 PM

I think the easy solution might be to switch the POST to a PUT when handling the metabase_dashboard resource's cards_json attribute.

mcmohorn commented 10 months ago

I'm using metabase enterprise v 1.47.2.

In metabase-api.yaml I see both a put and a post. I've reached out to metabase to see if the post was deprecated.

mcmohorn commented 10 months ago

I confirmed by checking their documentation here that there is no longer a POST with that signature. Should be using the PUT instead

flovouin commented 10 months ago

Hey @mcmohorn, thanks for the report.

Indeed, it looks like the API has changed quite a bit, from v0.45 requiring the creation of cards beforehand with limited parameters, v0.46 supporting more parameters, and then... v0.47 simply discarding the endpoint, as you noticed. I haven't been following these changes because to be honest I haven't used (or at least upgraded) Metabase in the past year.

Maybe the new API actually makes managing dashboard cards simpler, but I'll have to look at how IDs are supposed to be attributed to cards. (This was the point of the POST call, before setting the card configuration using PUT.)

One thing's for sure, because it is a breaking change in the Metabase API, it will be a breaking change for this provider as well. Let's hope it is not a breaking change in how the Terraform state has to be stored, that would be more problematic.

I'll try taking a look at this in the next few days. Unfortunately I don't have much bandwidth to allocate to this project. If that's an option for you, I'd recommend sticking to Metabase v0.46 for now.