JSON to schema.ResourceData in one call

What is the “best” way to copy values from a json to object to ResourceData?

At the very least, is there a better way to populate all/multiple values in schema.ResourceData, rather than needing to call func (d *ResourceData) Set(key string, value interface{}) over and over?

Given the ability to set a single key with a map[string]interface{}, it seems like a small step to set the all keys. This feels like a pretty common situation, but perhaps my approach is all wrong.

Working with/from something like the following:

{"name":"app","description":"fun","env":"dev", "monitoring": true, "runtime_version":"1.18.39"}


func resourceApplication() *schema.Resource {
	return &schema.Resource{
		Schema: map[string]*schema.Schema{
			"name": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,			},
			"description": &schema.Schema{
				Type:     schema.TypeString,
				Optional: true,
			"env": {
				Type: schema.TypeString,
				Required: true,
			"monitoring": &schema.Schema{
				Type:     schema.TypeBool,
				Optional: true,

Currently, the best way is to call helper/schema.ResourceData.Set over and over, unfortunately. :frowning:

You can do something like this:

var res map[string]interface{}
for k, v := range res {
  err := d.Set(k, v)
  if err != nil {

You probably don’t actually want to panic, but it is important to handle that error, as it’s the only way you’ll know if the results and the schema don’t line up 1:1.

This is an area of ongoing research and experimentation, and is unfortunately a bit more complex than it would seem. :frowning:

Thank you! Half the battle learning a new platform/tool is just knowing if you’ve hit it’s limits, or are just doing it wrong.

For whatever it is worth, I think makes sense to leave almost all all the the transform to/from provider data model out of Terraform.

For now I’m trying to make a go of it with “github.com/buger/jsonparser”, as it’s more of a push/event parser, and came up near the top on Google. :stuck_out_tongue: