diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/configs/configschema/none_required.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/configs/configschema/none_required.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/configs/configschema/none_required.go b/vendor/github.com/hashicorp/terraform/configs/configschema/none_required.go new file mode 100644 index 0000000..0be3b8f --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/configs/configschema/none_required.go | |||
@@ -0,0 +1,38 @@ | |||
1 | package configschema | ||
2 | |||
3 | // NoneRequired returns a deep copy of the receiver with any required | ||
4 | // attributes translated to optional. | ||
5 | func (b *Block) NoneRequired() *Block { | ||
6 | ret := &Block{} | ||
7 | |||
8 | if b.Attributes != nil { | ||
9 | ret.Attributes = make(map[string]*Attribute, len(b.Attributes)) | ||
10 | } | ||
11 | for name, attrS := range b.Attributes { | ||
12 | ret.Attributes[name] = attrS.forceOptional() | ||
13 | } | ||
14 | |||
15 | if b.BlockTypes != nil { | ||
16 | ret.BlockTypes = make(map[string]*NestedBlock, len(b.BlockTypes)) | ||
17 | } | ||
18 | for name, blockS := range b.BlockTypes { | ||
19 | ret.BlockTypes[name] = blockS.noneRequired() | ||
20 | } | ||
21 | |||
22 | return ret | ||
23 | } | ||
24 | |||
25 | func (b *NestedBlock) noneRequired() *NestedBlock { | ||
26 | ret := *b | ||
27 | ret.Block = *(ret.Block.NoneRequired()) | ||
28 | ret.MinItems = 0 | ||
29 | ret.MaxItems = 0 | ||
30 | return &ret | ||
31 | } | ||
32 | |||
33 | func (a *Attribute) forceOptional() *Attribute { | ||
34 | ret := *a | ||
35 | ret.Optional = true | ||
36 | ret.Required = false | ||
37 | return &ret | ||
38 | } | ||