terraform-provider-devcycle icon indicating copy to clipboard operation
terraform-provider-devcycle copied to clipboard

SDKKeys reported as list[] strings instead of a map of `key_kind -> key`

Open OlgierdEthon opened this issue 8 months ago • 4 comments

The provider forces the downstream consumer to rely on implementation detail, such as those statements order to be able to use the keys.

A better approach would be to return a map with fields such as mobile, server, etc. containing the corresponding keys, exactly as it is done in the API

Additionally in the currently published version which btw differs from the latest one in the repo there's a bug that causes the key to appear in triplicate (or 4 times, can't recall now).

OlgierdEthon avatar Mar 31 '25 20:03 OlgierdEthon

Hi,

Our current terraform provider is limited in its functionality due to its drift from our API - as it has evolved quite substantially since we initially developed this. Additionally - we've archived our SDK wrapper for the Management API that this provider uses heavily.

We don't currently have a roadmap item to update this provider in any specific time window; but if you raise it with your account manager they can bring it into a higher internal priority.

Thanks!

JamieSinn avatar Mar 31 '25 20:03 JamieSinn

Our current workaround is to fix the issue with an external script:

data "external" "extract_server_key" {
  program = ["python3", "${path.module}/keys_shim.py"]

  query = {
    keys = join("|", devcycle_environment.environment.sdk_keys)
  }
}

used like so:

data.external.extract_server_key.result["mobile"] # or server or whatever

with keys_shim.py being:

import json
import sys

tf_query = json.load(sys.stdin)

keys = tf_query["keys"].split("|")

unique_keys = set(keys)
assert len(unique_keys) == 3

result = {}
for k in unique_keys:
    dvc_part, kind, *secret = k.split("_")
    assert dvc_part == "dvc"
    result[kind] = k

json.dump(result, sys.stdout)

OlgierdEthon avatar Apr 01 '25 08:04 OlgierdEthon

Interesting; I think when we re-do this sdk_key will be a native resource in terraform with a type property to help you filter this all out.

In the mean time - you might be able to make use of the DVC CLI if you're using an external provider - https://docs.devcycle.com/cli/ The CLI has commands that can handle creation/editing/deletion of the various elements on the platform.

JamieSinn avatar Apr 01 '25 14:04 JamieSinn

Actually a colleague pointed out a much simpler solution (doesn't require firing up the external machinery):

  server_key = [for k in devcycle_environment.environment.sdk_keys : k if strcontains(k, "server")][0]

Re future: yeah, I'd essentially would love to do .server - how you have it in the latest API is perfect!

OlgierdEthon avatar Apr 07 '25 09:04 OlgierdEthon