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)