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:
json
{"name":"app","description":"fun","env":"dev", "monitoring": true, "runtime_version":"1.18.39"}
Schema
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,
},
}