hcl2: add general kv store that could be used anywhere

This commit is contained in:
Adrien Delorme 2020-03-13 16:04:42 +01:00
parent ae4b158ca3
commit 9e6d5da277
2 changed files with 40 additions and 0 deletions

8
hcl2template/types.kv.go Normal file
View File

@ -0,0 +1,8 @@
//go:generate mapstructure-to-hcl2 -type KeyValue
package hcl2template
type KeyValue struct {
Key string
Value string
}

View File

@ -0,0 +1,32 @@
// Code generated by "mapstructure-to-hcl2 -type KeyValue"; DO NOT EDIT.
package hcl2template
import (
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
)
// FlatKeyValue is an auto-generated flat version of KeyValue.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatKeyValue struct {
Key *string `cty:"key"`
Value *string `cty:"value"`
}
// FlatMapstructure returns a new FlatKeyValue.
// FlatKeyValue is an auto-generated flat version of KeyValue.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*KeyValue) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatKeyValue)
}
// HCL2Spec returns the hcl spec of a KeyValue.
// This spec is used by HCL to read the fields of KeyValue.
// The decoded values from this spec will then be applied to a FlatKeyValue.
func (*FlatKeyValue) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"key": &hcldec.AttrSpec{Name: "key", Type: cty.String, Required: false},
"value": &hcldec.AttrSpec{Name: "value", Type: cty.String, Required: false},
}
return s
}