From b9245a402dd4a4bcc68f8147de6ad9c02af7f547 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 23 Oct 2019 10:36:10 -0700 Subject: [PATCH] add structure to its own struct to make generated code stop complaining --- builder/amazon/common/run_config.go | 14 ++++--- builder/amazon/common/run_config.hcl2spec.go | 42 ++++++++++++++------ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index 00b018d4a..228ad52f6 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -1,5 +1,5 @@ //go:generate struct-markdown -//go:generate mapstructure-to-hcl2 -type AmiFilterOptions,SecurityGroupFilterOptions,SubnetFilterOptions,VpcFilterOptions,PolicyDocument +//go:generate mapstructure-to-hcl2 -type AmiFilterOptions,SecurityGroupFilterOptions,SubnetFilterOptions,VpcFilterOptions,PolicyDocument,Statement package common @@ -54,13 +54,15 @@ type VpcFilterOptions struct { Filters map[string]string } +type Statement struct { + Effect string + Action []string + Resource string +} + type PolicyDocument struct { Version string - Statement []struct { - Effect string - Action []string - Resource string - } + Statement []Statement } func (d *VpcFilterOptions) Empty() bool { diff --git a/builder/amazon/common/run_config.hcl2spec.go b/builder/amazon/common/run_config.hcl2spec.go index 48c0b0008..2ef6ce62d 100644 --- a/builder/amazon/common/run_config.hcl2spec.go +++ b/builder/amazon/common/run_config.hcl2spec.go @@ -1,4 +1,4 @@ -// Code generated by "mapstructure-to-hcl2 -type AmiFilterOptions,SecurityGroupFilterOptions,SubnetFilterOptions,VpcFilterOptions,PolicyDocument"; DO NOT EDIT. +// Code generated by "mapstructure-to-hcl2 -type AmiFilterOptions,SecurityGroupFilterOptions,SubnetFilterOptions,VpcFilterOptions,PolicyDocument,Statement"; DO NOT EDIT. package common import ( @@ -33,12 +33,8 @@ func (*FlatAmiFilterOptions) HCL2Spec() map[string]hcldec.Spec { // FlatPolicyDocument is an auto-generated flat version of PolicyDocument. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatPolicyDocument struct { - Version *string `cty:"version"` - Statement []struct { - Effect string - Action []string - Resource string - } `cty:"statement"` + Version *string `cty:"version"` + Statement []FlatStatement `cty:"statement"` } // FlatMapstructure returns a new FlatPolicyDocument. @@ -50,12 +46,8 @@ func (*PolicyDocument) FlatMapstructure() interface{} { return new(FlatPolicyDoc // This spec is used by HCL to read the fields of FlatPolicyDocument. func (*FlatPolicyDocument) HCL2Spec() map[string]hcldec.Spec { s := map[string]hcldec.Spec{ - "version": &hcldec.AttrSpec{Name: "version", Type: cty.String, Required: false}, - "statement": &hcldec.BlockObjectSpec{TypeName: "statement", Nested: hcldec.ObjectSpec((*struct { - Effect string - Action []string - Resource string - })(nil).HCL2Spec())}, + "version": &hcldec.AttrSpec{Name: "version", Type: cty.String, Required: false}, + "statement": &hcldec.BlockListSpec{TypeName: "statement", Nested: &hcldec.BlockSpec{TypeName: "statement", Nested: hcldec.ObjectSpec((*FlatStatement)(nil).HCL2Spec())}}, } return s } @@ -82,6 +74,30 @@ func (*FlatSecurityGroupFilterOptions) HCL2Spec() map[string]hcldec.Spec { return s } +// FlatStatement is an auto-generated flat version of Statement. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatStatement struct { + Effect *string `cty:"effect"` + Action []string `cty:"action"` + Resource *string `cty:"resource"` +} + +// FlatMapstructure returns a new FlatStatement. +// FlatStatement is an auto-generated flat version of Statement. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*Statement) FlatMapstructure() interface{} { return new(FlatStatement) } + +// HCL2Spec returns the hcldec.Spec of a FlatStatement. +// This spec is used by HCL to read the fields of FlatStatement. +func (*FlatStatement) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "effect": &hcldec.AttrSpec{Name: "effect", Type: cty.String, Required: false}, + "action": &hcldec.AttrSpec{Name: "action", Type: cty.List(cty.String), Required: false}, + "resource": &hcldec.AttrSpec{Name: "resource", Type: cty.String, Required: false}, + } + return s +} + // FlatSubnetFilterOptions is an auto-generated flat version of SubnetFilterOptions. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatSubnetFilterOptions struct {