Serial API Update

Hi all,

Currently I am extending this Metabase provider to handle collection permissions however I am finding difficult how to handle this with Terraform.

To update Metabase permission is required to send the current revision graph number like:

{
    "revision": 110,
    "groups": {
        "7": {
            "128": "read"
        }
    }
}

If the revision number (110) doesn’t match the current graph value in Metabase (for example, because the Graph has been by another process), the API request fails.

This is the case when Terraform update multiple resources, these actions, the permissions for a collection is stored by each resources state, and when multiple resources collection are updated, multiple request against Metabase API occurs in parallel, so the the revision number mismatch.

Is it possible to somehow to handle the provider to do this updates in serial rather than in parallel?
does anyone know any other example of another provider to see how they handle this case?

Thanks,

Hi @dlou :wave: Welcome to HashiCorp Discuss and thank you for posting this.

Serializing operations in a Terraform Provider is similar to any other Go code where you can implement a mutex to handle it. There is no built-in terraform-plugin-sdk or terraform-plugin-framework functionality for this, but you can use any Go package, such as the Go standard library sync.Mutex type.

One such example of mutex usage in a Terraform Provider is in the terraform-provider-aws codebase, which has a small wrapper for creating string key mutexes (which fun fact, used to actually be in terraform-plugin-sdk v1 as a helper/mutexkv package).

Hope this helps!

1 Like

@bflad thanks for your comment! I am not that familiar with programming in Golang but I’ll have a look!