Skip to content

Commit

Permalink
Merge pull request #92 from JackFlukinger/fix-panics
Browse files Browse the repository at this point in the history
Fix panics
  • Loading branch information
im2nguyen authored Feb 10, 2022
2 parents 28b7dc7 + f2d1cf5 commit ac4a0f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
31 changes: 26 additions & 5 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -206,16 +211,32 @@ 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)
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 {

Expand Down
9 changes: 0 additions & 9 deletions rso.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ac4a0f6

Please sign in to comment.