Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split schema.go to block/nested_block/attribute.go
- Loading branch information
1 parent
b24f726
commit b320ed9
Showing
5 changed files
with
101 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tfschema | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/config/configschema" | ||
) | ||
|
||
// Attribute is wrapper for configschema.Attribute | ||
type Attribute struct { | ||
// Type is a type of the attribute's value. | ||
// Note that Type is not cty.Type | ||
// We cannot import github.com/hashicorp/terraform/vendor/github.com/zclconf/go-cty/cty | ||
// On the other hand, tfschema does not need a dynamic type. | ||
// So, we use a simple representation of type. | ||
Type Type `json:"type"` | ||
Required bool `json:"required"` | ||
Optional bool `json:"optional"` | ||
Computed bool `json:"computed"` | ||
Sensitive bool `json:"sensitive"` | ||
} | ||
|
||
func NewAttribute(a *configschema.Attribute) *Attribute { | ||
return &Attribute{ | ||
Type: *NewType(a.Type), | ||
Required: a.Required, | ||
Optional: a.Optional, | ||
Computed: a.Computed, | ||
Sensitive: a.Sensitive, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tfschema | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/hashicorp/terraform/config/configschema" | ||
) | ||
|
||
// Block is wrapper for configschema.Block | ||
type Block struct { | ||
Attributes map[string]*Attribute `json:"attributes"` | ||
BlockTypes map[string]*NestedBlock `json:"block_types"` | ||
} | ||
|
||
func NewBlock(b *configschema.Block) *Block { | ||
return &Block{ | ||
Attributes: NewAttributes(b.Attributes), | ||
BlockTypes: NewBlockTypes(b.BlockTypes), | ||
} | ||
} | ||
|
||
func NewAttributes(as map[string]*configschema.Attribute) map[string]*Attribute { | ||
m := make(map[string]*Attribute) | ||
|
||
for k, v := range as { | ||
m[k] = NewAttribute(v) | ||
} | ||
|
||
return m | ||
} | ||
|
||
func NewBlockTypes(bs map[string]*configschema.NestedBlock) map[string]*NestedBlock { | ||
m := make(map[string]*NestedBlock) | ||
|
||
for k, v := range bs { | ||
m[k] = NewNestedBlock(v) | ||
} | ||
|
||
return m | ||
} | ||
|
||
func (b *Block) FormatJSON() (string, error) { | ||
bytes, err := json.MarshalIndent(b, "", " ") | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(bytes), nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tfschema | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/config/configschema" | ||
) | ||
|
||
// NestedBlock is wrapper for configschema.NestedBlock | ||
type NestedBlock struct { | ||
Block | ||
Nesting configschema.NestingMode `json:"nesting"` | ||
MinItems int `json:"min_items"` | ||
MaxItems int `json:"max_items"` | ||
} | ||
|
||
func NewNestedBlock(b *configschema.NestedBlock) *NestedBlock { | ||
block := NewBlock(&b.Block) | ||
return &NestedBlock{ | ||
Block: *block, | ||
Nesting: b.Nesting, | ||
MinItems: b.MinItems, | ||
MaxItems: b.MaxItems, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.