Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle external terragrunt dep without panic #101

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/module/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (s *Service) loadTerragruntDependenciesFromDigraph(r io.Reader) error {
continue
}
// Convert dependency paths to module IDs
dependencyIDs := make([]resource.ID, len(depPaths))
for i, path := range depPaths {
dependencyIDs := make([]resource.ID, 0, len(depPaths))
for _, path := range depPaths {
// If absolute path then convert to path relative to pug's working
// directory.
if filepath.IsAbs(path) {
Expand All @@ -176,7 +176,7 @@ func (s *Service) loadTerragruntDependenciesFromDigraph(r io.Reader) error {
// Skip loading this dependency
continue
}
dependencyIDs[i] = mod.ID
dependencyIDs = append(dependencyIDs, mod.ID)
}
s.table.Update(mod.ID, func(existing *Module) error {
existing.Common = existing.WithDependencies(dependencyIDs...)
Expand Down
4 changes: 4 additions & 0 deletions internal/module/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/leg100/pug/internal"
"github.com/leg100/pug/internal/logging"
"github.com/leg100/pug/internal/resource"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -22,6 +23,7 @@ func TestLoadTerragruntDependenciesFromDigraph(t *testing.T) {
svc := &Service{
table: &fakeModuleTable{modules: []*Module{vpc, redis, mysql, backend, frontend}},
workdir: workdir,
logger: logging.Discard,
}

// Check it can handle both relative and absolute paths - `terragrunt
Expand Down Expand Up @@ -50,11 +52,13 @@ digraph {
"%[1]s/root/backend-app" -> "%[1]s/root/mysql";
"%[1]s/root/backend-app" -> "%[1]s/root/redis";
"%[1]s/root/backend-app" -> "%[1]s/root/vpc";
"%[1]s/root/backend-app" -> "/outside_workdir/kafka";
"%[1]s/root/mysql" ;
"%[1]s/root/mysql" -> "%[1]s/root/vpc";
"%[1]s/root/redis" ;
"%[1]s/root/redis" -> "%[1]s/root/vpc";
"%[1]s/root/vpc" ;
"/outside_workdir/kafka" ;
}
`, workdir)
)
Expand Down
13 changes: 9 additions & 4 deletions internal/tui/module/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ func (m *ListMaker) Make(_ resource.ID, width, height int) (tea.Model, error) {
currentWorkspace.Key: m.Helpers.CurrentWorkspaceName(mod.CurrentWorkspaceID),
table.ResourceCountColumn.Key: m.Helpers.ModuleCurrentResourceCount(mod),
}
dependencyNames := make([]string, len(mod.Dependencies()))
for i, id := range mod.Dependencies() {
mod, _ := m.ModuleService.Get(id)
dependencyNames[i] = mod.Path
dependencyNames := make([]string, 0, len(mod.Dependencies()))
for _, id := range mod.Dependencies() {
mod, err := m.ModuleService.Get(id)
if err != nil {
// Should never happen
dependencyNames = append(dependencyNames, fmt.Sprintf("error: %s", err.Error()))
continue
}
dependencyNames = append(dependencyNames, mod.Path)
}
row[dependencies.Key] = strings.Join(dependencyNames, ",")
return row
Expand Down
Loading