mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
e6592dc710
Implement a new provider_meta block in the terraform block of modules, allowing provider-keyed metadata to be communicated from HCL to provider binaries. Bundled in this change for minimal protocol version bumping is the addition of markdown support for attribute descriptions and the ability to indicate when an attribute is deprecated, so this information can be shown in the schema dump. Co-authored-by: Paul Tyng <paul@paultyng.net>
78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package jsonprovider
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
|
)
|
|
|
|
type block struct {
|
|
Attributes map[string]*attribute `json:"attributes,omitempty"`
|
|
BlockTypes map[string]*blockType `json:"block_types,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
DescriptionKind string `json:"description_kind,omitempty"`
|
|
Deprecated bool `json:"deprecated,omitempty"`
|
|
}
|
|
|
|
type blockType struct {
|
|
NestingMode string `json:"nesting_mode,omitempty"`
|
|
Block *block `json:"block,omitempty"`
|
|
MinItems uint64 `json:"min_items,omitempty"`
|
|
MaxItems uint64 `json:"max_items,omitempty"`
|
|
}
|
|
|
|
func marshalBlockTypes(nestedBlock *configschema.NestedBlock) *blockType {
|
|
if nestedBlock == nil {
|
|
return &blockType{}
|
|
}
|
|
ret := &blockType{
|
|
Block: marshalBlock(&nestedBlock.Block),
|
|
MinItems: uint64(nestedBlock.MinItems),
|
|
MaxItems: uint64(nestedBlock.MaxItems),
|
|
}
|
|
|
|
switch nestedBlock.Nesting {
|
|
case configschema.NestingSingle:
|
|
ret.NestingMode = "single"
|
|
case configschema.NestingGroup:
|
|
ret.NestingMode = "group"
|
|
case configschema.NestingList:
|
|
ret.NestingMode = "list"
|
|
case configschema.NestingSet:
|
|
ret.NestingMode = "set"
|
|
case configschema.NestingMap:
|
|
ret.NestingMode = "map"
|
|
default:
|
|
ret.NestingMode = "invalid"
|
|
}
|
|
return ret
|
|
}
|
|
|
|
func marshalBlock(configBlock *configschema.Block) *block {
|
|
if configBlock == nil {
|
|
return &block{}
|
|
}
|
|
|
|
ret := block{
|
|
Deprecated: configBlock.Deprecated,
|
|
Description: configBlock.Description,
|
|
DescriptionKind: marshalStringKind(configBlock.DescriptionKind),
|
|
}
|
|
|
|
if len(configBlock.Attributes) > 0 {
|
|
attrs := make(map[string]*attribute, len(configBlock.Attributes))
|
|
for k, attr := range configBlock.Attributes {
|
|
attrs[k] = marshalAttribute(attr)
|
|
}
|
|
ret.Attributes = attrs
|
|
}
|
|
|
|
if len(configBlock.BlockTypes) > 0 {
|
|
blockTypes := make(map[string]*blockType, len(configBlock.BlockTypes))
|
|
for k, bt := range configBlock.BlockTypes {
|
|
blockTypes[k] = marshalBlockTypes(bt)
|
|
}
|
|
ret.BlockTypes = blockTypes
|
|
}
|
|
|
|
return &ret
|
|
}
|