mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
479c6b2466
The "config" package is no longer used and will be removed as part of the 0.12 release cleanup. Since configschema is part of the "new world" of configuration modelling, it makes more sense for it to live as a subdirectory of the newer "configs" package.
39 lines
854 B
Go
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
|
|
}
|