40947c2bf6
This will allow to generate the config files: ```go package main import ( "fmt" "github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/hclwrite" "github.com/hashicorp/packer/builder/alicloud/ecs" ) func main() { name := "name" app := ecs.FlatConfig{ AlicloudImageName: &name, ECSSystemDiskMapping: &ecs.FlatAlicloudDiskDevice{ DiskName: &name, }, } f := hclwrite.NewEmptyFile() block := gohcl.EncodeAsBlock(&app, `source "something" "something"`) f.Body().AppendBlock(block) fmt.Printf("%s", f.Bytes()) } ``` Will output: ``` source "something" "something" { packer_user_variables = null packer_sensitive_variables = null image_name = "name" image_share_account = null image_unshare_account = null image_copy_regions = null image_copy_names = null tags = null tag = null system_disk_mapping = { disk_category = null, disk_delete_with_instance = null, disk_descri ption = null, disk_device = null, disk_encrypted = null, disk_name = "name", disk_size = null, disk_ snapshot_id = null } image_disk_mappings = null ssh_remote_tunnels = null ssh_local_tunnels = null ssh_public_key = null ssh_private_key = null } ``` This is a good first step for #9015 and #9282 fix #9304
108 lines
4.5 KiB
Go
108 lines
4.5 KiB
Go
// Code generated by "mapstructure-to-hcl2 -type KeyValue,KeyValues,KeyValueFilter,NameValue,NameValues,NameValueFilter"; 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" hcl:"key"`
|
|
Value *string `cty:"value" hcl:"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
|
|
}
|
|
|
|
// FlatKeyValueFilter is an auto-generated flat version of KeyValueFilter.
|
|
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
|
|
type FlatKeyValueFilter struct {
|
|
Filters map[string]string `cty:"filters" hcl:"filters"`
|
|
Filter []FlatKeyValue `cty:"filter" hcl:"filter"`
|
|
}
|
|
|
|
// FlatMapstructure returns a new FlatKeyValueFilter.
|
|
// FlatKeyValueFilter is an auto-generated flat version of KeyValueFilter.
|
|
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
|
|
func (*KeyValueFilter) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
|
|
return new(FlatKeyValueFilter)
|
|
}
|
|
|
|
// HCL2Spec returns the hcl spec of a KeyValueFilter.
|
|
// This spec is used by HCL to read the fields of KeyValueFilter.
|
|
// The decoded values from this spec will then be applied to a FlatKeyValueFilter.
|
|
func (*FlatKeyValueFilter) HCL2Spec() map[string]hcldec.Spec {
|
|
s := map[string]hcldec.Spec{
|
|
"filters": &hcldec.AttrSpec{Name: "filters", Type: cty.Map(cty.String), Required: false},
|
|
"filter": &hcldec.BlockListSpec{TypeName: "filter", Nested: hcldec.ObjectSpec((*FlatKeyValue)(nil).HCL2Spec())},
|
|
}
|
|
return s
|
|
}
|
|
|
|
// FlatNameValue is an auto-generated flat version of NameValue.
|
|
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
|
|
type FlatNameValue struct {
|
|
Name *string `cty:"name" hcl:"name"`
|
|
Value *string `cty:"value" hcl:"value"`
|
|
}
|
|
|
|
// FlatMapstructure returns a new FlatNameValue.
|
|
// FlatNameValue is an auto-generated flat version of NameValue.
|
|
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
|
|
func (*NameValue) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
|
|
return new(FlatNameValue)
|
|
}
|
|
|
|
// HCL2Spec returns the hcl spec of a NameValue.
|
|
// This spec is used by HCL to read the fields of NameValue.
|
|
// The decoded values from this spec will then be applied to a FlatNameValue.
|
|
func (*FlatNameValue) HCL2Spec() map[string]hcldec.Spec {
|
|
s := map[string]hcldec.Spec{
|
|
"name": &hcldec.AttrSpec{Name: "name", Type: cty.String, Required: false},
|
|
"value": &hcldec.AttrSpec{Name: "value", Type: cty.String, Required: false},
|
|
}
|
|
return s
|
|
}
|
|
|
|
// FlatNameValueFilter is an auto-generated flat version of NameValueFilter.
|
|
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
|
|
type FlatNameValueFilter struct {
|
|
Filters map[string]string `cty:"filters" hcl:"filters"`
|
|
Filter []FlatNameValue `cty:"filter" hcl:"filter"`
|
|
}
|
|
|
|
// FlatMapstructure returns a new FlatNameValueFilter.
|
|
// FlatNameValueFilter is an auto-generated flat version of NameValueFilter.
|
|
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
|
|
func (*NameValueFilter) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
|
|
return new(FlatNameValueFilter)
|
|
}
|
|
|
|
// HCL2Spec returns the hcl spec of a NameValueFilter.
|
|
// This spec is used by HCL to read the fields of NameValueFilter.
|
|
// The decoded values from this spec will then be applied to a FlatNameValueFilter.
|
|
func (*FlatNameValueFilter) HCL2Spec() map[string]hcldec.Spec {
|
|
s := map[string]hcldec.Spec{
|
|
"filters": &hcldec.AttrSpec{Name: "filters", Type: cty.Map(cty.String), Required: false},
|
|
"filter": &hcldec.BlockListSpec{TypeName: "filter", Nested: hcldec.ObjectSpec((*FlatNameValue)(nil).HCL2Spec())},
|
|
}
|
|
return s
|
|
}
|