opentofu/internal/command/jsonprovider/schema.go
Liam Cervante b917154a97
Make required JSON structured output structures public for processing (#32367)
* prep for processing the structured run output

* undo unwanted change to a json key
2023-01-09 10:48:23 +01:00

39 lines
822 B
Go

package jsonprovider
import (
"github.com/hashicorp/terraform/internal/configs/configschema"
)
type Schema struct {
Version uint64 `json:"version"`
Block *Block `json:"block,omitempty"`
}
// marshalSchema is a convenience wrapper around mashalBlock. Schema version
// should be set by the caller.
func marshalSchema(block *configschema.Block) *Schema {
if block == nil {
return &Schema{}
}
var ret Schema
ret.Block = marshalBlock(block)
return &ret
}
func marshalSchemas(blocks map[string]*configschema.Block, rVersions map[string]uint64) map[string]*Schema {
if blocks == nil {
return map[string]*Schema{}
}
ret := make(map[string]*Schema, len(blocks))
for k, v := range blocks {
ret[k] = marshalSchema(v)
version, ok := rVersions[k]
if ok {
ret[k].Version = version
}
}
return ret
}