How should mastercard restapi provider handle this complex map?

Hi All,

This is about complex schema which happens to be part of restapi provider. I’ve the provider configuration to pass resource as part of token API to create oauth2 tokens.

provider "restapi" {
  uri = "https://xxxx-yyy-zzzz"

  oauth_client_credentials {
    oauth_client_id      = "client-id"
    oauth_client_secret  = "secret"
    oauth_token_endpoint = "token-endpoint"
    endpoint_params = {
      resource = [oauth-resource]
    }
  }
}

The problem is with endpoint_params. It was never tested & with current version it’s throwing a panic as the SDK validation doesn’t support such a type. It was discussed as one of the issues on the provider itself. Link to the issue is here. The interesting thing is the maintainer says Terraform SDK can’t handle map with each key pointing to a list of strings. It’s highlighted here.

Okay, understood this isn’t yet supported but we could skip validation & let the data be directly passed to restapi. Nevertheless, I’ve problems getting it to work. The restapi provider uses go-oauth2 SDK expects endpoint_params in below format::

EndpointParams = url.Values {
   "resource": {"xxxx-yyyy-xxxx"},
}

However, the provider expects in below format ::

endpoint_params = {
      resource = ["xxxx-yyyy-xxxx"],
 }

I’ve been trying for sometime how to align the the data so that terraform can properly pass in the way the go-oauth2 SDK accepts when I skip the validation at provider level. I got the suggestion to skip validation from here.

Your help is very much appreciated.

Thanks,
Harsha

Okay, I got it in the meantime by slightly changing the variable structure.

Its now passed as map of strings rather map of list of strings as the oauth2 sdk doesnt accept the map anyways…

endpoint_params = { resource = "xxxx-yyyy-xxxx", }

restapi provider considers this as a jsonstring. More details here :: Fix for endpoint_params #202 by harshavmb · Pull Request #231 · Mastercard/terraform-provider-restapi · GitHub

1 Like