opentofu/internal/command/jsonprovider/schema.go
Martin Atkins 31349a9c3a Move configs/ to internal/configs/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07: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
}