zclconf / go-cty

A type system for dynamic values in Go applications
MIT License
338 stars 70 forks source link

Encoding values with custom function (terraform provider) #165

Closed jnunezgts closed 1 year ago

jnunezgts commented 1 year ago

Hello,

I'm trying to encode a map into the following format:

resource "grafana_data_source" "prometheus" {

  json_data_encoded = jsonencode({
    httpMethod        = "POST"
    prometheusType    = "Mimir"
    prometheusVersion = "2.4.0"
  })

What I found from the documentation is that cty provides out of the box support to encode Strings, Boolean and other primitives like this:

flt, check := value.(float64)
if check {
   resourceBody.SetAttributeValue(key, cty.NumberFloatVal(flt))
}

There is a way to achieve the same with a map[string]interface{}?

I was looking through the documentation but I could not find anything that resembles what I need to do.

Thanks.

apparentlymart commented 1 year ago

Hi @jnunezgts!

I'm afraid I'm not sure exactly what you are asking, but this seems like it's a Terraform question rather than a cty question, so I'd suggest asking it in Terraform's forum instead. Thanks!