From 146d9eaec3b2277ed45cc7c563c7b6c1bfb078f2 Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Wed, 18 Oct 2023 07:19:26 -0400 Subject: [PATCH] Initial fix for underlying struct mis-match bug --- .../internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go b/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go index 3cd69a8bc..0d2870df0 100644 --- a/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go +++ b/cmd/packer-sdc/internal/mapstructure-to-hcl2/mapstructure-to-hcl2.go @@ -140,10 +140,17 @@ func (cmd *Command) Run(args []string) int { if !utOk { continue } + pos := sort.SearchStrings(typeNames, id.Name) if pos >= len(typeNames) || typeNames[pos] != id.Name { continue // not a struct we care about } + // Sometimes we see the underlying struct for a similar name typed, which results + // in an incorrect FlatMap. If the type names are not exactly the same skip. + if nt.Obj().Name() != id.Name { + continue // not the struct we are looking for + } + // make sure each type is found once where somehow sometimes they can be found twice typeNames = append(typeNames[:pos], typeNames[pos+1:]...) flatenedStruct, err := getMapstructureSquashedStruct(obj.Pkg(), utStruct)