Add exclude mapstructure tag to exclude from hcl2spec struct (#8785)
This commit is contained in:
parent
6dbe86fcf4
commit
ce674ff272
|
@ -371,8 +371,8 @@ type Config struct {
|
|||
AllowedInboundIpAddresses []string `mapstructure:"allowed_inbound_ip_addresses"`
|
||||
|
||||
// Runtime Values
|
||||
UserName string
|
||||
Password string
|
||||
UserName string `mapstructure-to-hcl2:",skip"`
|
||||
Password string `mapstructure-to-hcl2:",skip"`
|
||||
tmpAdminPassword string
|
||||
tmpCertificatePassword string
|
||||
tmpResourceGroupName string
|
||||
|
|
|
@ -66,8 +66,6 @@ type FlatConfig struct {
|
|||
AdditionalDiskSize []int32 `mapstructure:"disk_additional_size" required:"false" cty:"disk_additional_size"`
|
||||
DiskCachingType *string `mapstructure:"disk_caching_type" required:"false" cty:"disk_caching_type"`
|
||||
AllowedInboundIpAddresses []string `mapstructure:"allowed_inbound_ip_addresses" cty:"allowed_inbound_ip_addresses"`
|
||||
UserName *string `cty:"user_name"`
|
||||
Password *string `cty:"password"`
|
||||
Type *string `mapstructure:"communicator" cty:"communicator"`
|
||||
PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"`
|
||||
SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"`
|
||||
|
@ -180,8 +178,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"disk_additional_size": &hcldec.AttrSpec{Name: "disk_additional_size", Type: cty.List(cty.Number), Required: false},
|
||||
"disk_caching_type": &hcldec.AttrSpec{Name: "disk_caching_type", Type: cty.String, Required: false},
|
||||
"allowed_inbound_ip_addresses": &hcldec.AttrSpec{Name: "allowed_inbound_ip_addresses", Type: cty.List(cty.String), Required: false},
|
||||
"user_name": &hcldec.AttrSpec{Name: "user_name", Type: cty.String, Required: false},
|
||||
"password": &hcldec.AttrSpec{Name: "password", Type: cty.String, Required: false},
|
||||
"communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false},
|
||||
"pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false},
|
||||
"ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false},
|
||||
|
|
|
@ -451,19 +451,31 @@ func getMapstructureSquashedStruct(topPkg *types.Package, utStruct *types.Struct
|
|||
log.Printf("could not parse field tag %s of : %v", tag, err)
|
||||
continue
|
||||
}
|
||||
if ms, err := structtag.Get("mapstructure"); err != nil {
|
||||
//no mapstructure tag
|
||||
} else if ms.HasOption("squash") {
|
||||
ot := field.Type()
|
||||
uot := ot.Underlying()
|
||||
utStruct, utOk := uot.(*types.Struct)
|
||||
if !utOk {
|
||||
|
||||
// Contains mapstructure-to-hcl2 tag
|
||||
if ms, err := structtag.Get("mapstructure-to-hcl2"); err == nil {
|
||||
// Stop if is telling to skip it
|
||||
if ms.HasOption("skip") {
|
||||
continue
|
||||
}
|
||||
|
||||
res = squashStructs(res, getMapstructureSquashedStruct(topPkg, utStruct))
|
||||
continue
|
||||
}
|
||||
|
||||
// Contains mapstructure tag
|
||||
if ms, err := structtag.Get("mapstructure"); err == nil {
|
||||
// Squash structs
|
||||
if ms.HasOption("squash") {
|
||||
ot := field.Type()
|
||||
uot := ot.Underlying()
|
||||
utStruct, utOk := uot.(*types.Struct)
|
||||
if !utOk {
|
||||
continue
|
||||
}
|
||||
|
||||
res = squashStructs(res, getMapstructureSquashedStruct(topPkg, utStruct))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if field.Pkg() != topPkg {
|
||||
field = types.NewField(field.Pos(), topPkg, field.Name(), field.Type(), field.Embedded())
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ type Config struct {
|
|||
ctx interpolate.Context
|
||||
|
||||
// The command to run inspec
|
||||
Command string
|
||||
SubCommand string
|
||||
Command string `mapstructure-to-hcl2:",skip"`
|
||||
SubCommand string `mapstructure-to-hcl2:",skip"`
|
||||
|
||||
// Extra options to pass to the inspec command
|
||||
ExtraArguments []string `mapstructure:"extra_arguments"`
|
||||
|
|
|
@ -16,8 +16,6 @@ type FlatConfig struct {
|
|||
PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error"`
|
||||
PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables"`
|
||||
PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables"`
|
||||
Command *string `cty:"command"`
|
||||
SubCommand *string `cty:"sub_command"`
|
||||
ExtraArguments []string `mapstructure:"extra_arguments" cty:"extra_arguments"`
|
||||
InspecEnvVars []string `mapstructure:"inspec_env_vars" cty:"inspec_env_vars"`
|
||||
Profile *string `mapstructure:"profile" cty:"profile"`
|
||||
|
@ -50,8 +48,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||
"packer_on_error": &hcldec.AttrSpec{Name: "packer_on_error", Type: cty.String, Required: false},
|
||||
"packer_user_variables": &hcldec.BlockAttrsSpec{TypeName: "packer_user_variables", ElementType: cty.String, Required: false},
|
||||
"packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false},
|
||||
"command": &hcldec.AttrSpec{Name: "command", Type: cty.String, Required: false},
|
||||
"sub_command": &hcldec.AttrSpec{Name: "sub_command", Type: cty.String, Required: false},
|
||||
"extra_arguments": &hcldec.AttrSpec{Name: "extra_arguments", Type: cty.List(cty.String), Required: false},
|
||||
"inspec_env_vars": &hcldec.AttrSpec{Name: "inspec_env_vars", Type: cty.List(cty.String), Required: false},
|
||||
"profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false},
|
||||
|
|
Loading…
Reference in New Issue