Help with design of schema from JSON in custom provider

I’ve looked and can’t seem to find any existing module or provider to support my effort so deciding to delve into attempting to design my own provider to do so. Intending to only need to provide a data source so no need to implement full CRUD, just need a Readcontext. Just trying to wrap my head around how best to define the schema given the existing JSON format that I’m intending to ingest.

The data resource is going to be used to populate AWS Lambda layers within given regions for different layer names. The JSON follows the format of:

{
    "layer-name-A": {
        "ca-central-1": "1",
        "eu-central-1": "1",
        "us-east-1": "1",
        "us-west-1": "1",
    },
    "layer-name-B": {
        "ca-central-1": "1",
        "eu-central-1": "1",
        "us-east-1": "1",
        "us-west-1": "1",
    },
    ## ...
}

Where it would have multiple layers which would then have multiple regions for that layer. The value of the region would then just simply be the layer version. Looking at the provider tutorial it appeared to be more geared towards a list with multiple items and trying to wrap my head around the schema design to implement as I realize that it all bases on that.

The ultimate goal of this is to be able to request the layer_name and region and have it be able to provide the correct Lambda layer version back. In order to do that I need to parse the JSON with the data on the latest version published.

I’m thinking the call would become something along the lines of

data "my_lambda_layer_version" "this" {
  layer_name = "layer-X"
  region     = "us-east-1"
}

I could then use data.my_lambd_layer_version.this.arn to reference in my aws_lambda_function resource layers attribute.

TIA for any advice and suggestions as this is my first attempt at Terraform provider design and Go programming at that.

I’m struggling to wrap my head around some of this, but assuming you were going to get that JSON as the response, and the user was going to specify the layer name (the top level keys, like layer-name-A) and the region (the second level keys, like ca-central-1), presumably what you’re trying to return is the second level values in the JSON (1 in your JSON above, for all keys?).

I imagine the schema to do something like that would look like this:

schema.Resource{
  Schema: map[string]*schema.Schema{
    "layer_name": {
      Type: schema.TypeString,
      Required: true,
    },
    "region": {
      Type: schema.TypeString,
      Required: true,
    },
    "arn": {
      Type: schema.TypeString,
      Computed: true,
    },
  },
}