From 13a09e0dbcbe9d8019cdda6d654b0c3ee8090fc2 Mon Sep 17 00:00:00 2001 From: Jack Flukinger Date: Tue, 8 Feb 2022 23:18:24 -0600 Subject: [PATCH 1/3] Fix panic for some deleted resources --- map.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/map.go b/map.go index f442fd9..e577c72 100644 --- a/map.go +++ b/map.go @@ -206,16 +206,33 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { if rs.Type == ResourceTypeData { ind = fmt.Sprintf("data.%s", ind) + } + + if rs.Type == ResourceTypeData && configs[parentConfig].Module.DataResources[ind] != nil { + fname = filepath.Base(configs[parentConfig].Module.DataResources[ind].Pos.Filename) + fmt.Printf("%v\n", ind) re.Line = &configs[parentConfig].Module.DataResources[ind].Pos.Line - } else if rs.Type == ResourceTypeResource { + + r.AddFileIfNotExists(parent, parentModule, fname) + + parent.Children[fname].Children[id] = re + + } else if rs.Type == ResourceTypeResource && configs[parentConfig].Module.ManagedResources[ind] != nil { + fname = filepath.Base(configs[parentConfig].Module.ManagedResources[ind].Pos.Filename) re.Line = &configs[parentConfig].Module.ManagedResources[ind].Pos.Line - } - r.AddFileIfNotExists(parent, parentModule, fname) + r.AddFileIfNotExists(parent, parentModule, fname) - parent.Children[fname].Children[id] = re + parent.Children[fname].Children[id] = re + + } else { + + r.AddFileIfNotExists(parent, parentModule, DefaultFileName) + + parent.Children[DefaultFileName].Children[id] = re + } } else { From f641f9c1ca1b9964211dabeadc5d78dd502d96ff Mon Sep 17 00:00:00 2001 From: Jack Flukinger Date: Wed, 9 Feb 2022 21:14:44 -0600 Subject: [PATCH 2/3] Fix panic --- rso.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/rso.go b/rso.go index 8ebc132..be9deae 100644 --- a/rso.go +++ b/rso.go @@ -211,16 +211,7 @@ func (r *rover) PopulateModuleState(rso *ResourcesOverview, module *tfjson.State } else { rs[id].Change.After = rst.AttributeValues } - - } else { - if prior { - rs[id].Change.Before = rst.AttributeValues - } else { - rs[id].Change.After = rst.AttributeValues - - } } - } for _, childModule := range module.ChildModules { From f2d1cf5ff9d65181dc81bed340bf53814ea94589 Mon Sep 17 00:00:00 2001 From: Jack Flukinger Date: Wed, 9 Feb 2022 22:24:50 -0600 Subject: [PATCH 3/3] Fix display name for nested data resources --- map.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/map.go b/map.go index e577c72..5454ecb 100644 --- a/map.go +++ b/map.go @@ -185,7 +185,12 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { tcr := &Resource{ Type: rs.Type, - Name: strings.TrimPrefix(crName, fmt.Sprintf("%s%s.", prefix, re.ResourceType)), + } + + if rs.Type == ResourceTypeData { + tcr.Name = strings.TrimPrefix(crName, fmt.Sprintf("%sdata.%s.", prefix, re.ResourceType)) + } else { + tcr.Name = strings.TrimPrefix(crName, fmt.Sprintf("%s%s.", prefix, re.ResourceType)) } if cr.Change.Actions != nil { @@ -211,7 +216,6 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { if rs.Type == ResourceTypeData && configs[parentConfig].Module.DataResources[ind] != nil { fname = filepath.Base(configs[parentConfig].Module.DataResources[ind].Pos.Filename) - fmt.Printf("%v\n", ind) re.Line = &configs[parentConfig].Module.DataResources[ind].Pos.Line r.AddFileIfNotExists(parent, parentModule, fname)