opentofu/config/configschema/none_required.go
Martin Atkins ebafa51723 command: Various updates for the new backend package API
This is a rather-messy, complex change to get the "command" package
building again against the new backend API that was updated for
the new configuration loader.

A lot of this is mechanical rewriting to the new API, but
meta_config.go and meta_backend.go in particular saw some major
changes to interface with the new loader APIs and to deal with
the change in order of steps in the backend API.
2018-10-16 18:44:26 -07:00

39 lines
854 B
Go

package configschema
// NoneRequired returns a deep copy of the receiver with any required
// attributes translated to optional.
func (b *Block) NoneRequired() *Block {
ret := &Block{}
if b.Attributes != nil {
ret.Attributes = make(map[string]*Attribute, len(b.Attributes))
}
for name, attrS := range b.Attributes {
ret.Attributes[name] = attrS.forceOptional()
}
if b.BlockTypes != nil {
ret.BlockTypes = make(map[string]*NestedBlock, len(b.BlockTypes))
}
for name, blockS := range b.BlockTypes {
ret.BlockTypes[name] = blockS.noneRequired()
}
return ret
}
func (b *NestedBlock) noneRequired() *NestedBlock {
ret := *b
ret.Block = *(ret.Block.NoneRequired())
ret.MinItems = 0
ret.MaxItems = 0
return &ret
}
func (a *Attribute) forceOptional() *Attribute {
ret := *a
ret.Optional = true
ret.Required = false
return &ret
}