From 6f014283336c073f6cbed467a3a9d3ab6693133c Mon Sep 17 00:00:00 2001 From: Christian Mesh Date: Mon, 5 Aug 2024 12:12:32 -0400 Subject: [PATCH] Fix missing module source panic (#1888) Signed-off-by: Christian Mesh --- CHANGELOG.md | 1 + internal/configs/config_build.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4dea29cd4..4a65d8ed05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ENHANCEMENTS: BUG FIXES: * Ensure that using a sensitive path for templatefile that it doesn't panic([#1801](https://github.com/opentofu/opentofu/issues/1801)) +* Fixed crash when module source is not present ([#1888](https://github.com/opentofu/opentofu/pull/1888)) ## Previous Releases diff --git a/internal/configs/config_build.go b/internal/configs/config_build.go index 6d0babeb28..d95eba691d 100644 --- a/internal/configs/config_build.go +++ b/internal/configs/config_build.go @@ -138,12 +138,15 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, Name: call.Name, Path: path, SourceAddr: call.SourceAddr, - SourceAddrRange: call.Source.Range(), VersionConstraint: call.Version, Parent: parent, CallRange: call.DeclRange, Call: NewStaticModuleCall(path, call.Variables, parent.Root.Module.SourceDir, call.Workspace), } + if call.Source != nil { + // Invalid modules sometimes have a nil source field which is handled through loadModule below + req.SourceAddrRange = call.Source.Range() + } child, modDiags := loadModule(parent.Root, &req, walker) diags = append(diags, modDiags...) if child == nil {