From 9e6d5da27791c5f551b4bf43a38b661cfaa78123 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Fri, 13 Mar 2020 16:04:42 +0100 Subject: [PATCH] hcl2: add general kv store that could be used anywhere --- hcl2template/types.kv.go | 8 ++++++++ hcl2template/types.kv.hcl2spec.go | 32 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 hcl2template/types.kv.go create mode 100644 hcl2template/types.kv.hcl2spec.go diff --git a/hcl2template/types.kv.go b/hcl2template/types.kv.go new file mode 100644 index 000000000..92fac7642 --- /dev/null +++ b/hcl2template/types.kv.go @@ -0,0 +1,8 @@ +//go:generate mapstructure-to-hcl2 -type KeyValue + +package hcl2template + +type KeyValue struct { + Key string + Value string +} diff --git a/hcl2template/types.kv.hcl2spec.go b/hcl2template/types.kv.hcl2spec.go new file mode 100644 index 000000000..464c18d95 --- /dev/null +++ b/hcl2template/types.kv.hcl2spec.go @@ -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 +}