Skip to content

feat: add specific code to module missing warning #162

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

Merged
merged 1 commit into from
Jul 1, 2025
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
5 changes: 5 additions & 0 deletions types/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const (
// DiagnosticCodeRequired is used when a parameter value is `null`, but
// the parameter is required.
DiagnosticCodeRequired = "required"

// DiagnosticModuleNotLoaded is used when a module block is present, but
// the mode failed to load. This can be because `.terraform/modules` is
// not present.
DiagnosticModuleNotLoaded = "module_not_loaded"
)

type DiagnosticExtra struct {
Expand Down
6 changes: 4 additions & 2 deletions warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/aquasecurity/trivy/pkg/iac/terraform"
"github.com/hashicorp/hcl/v2"

"github.com/coder/preview/types"
)

func warnings(modules terraform.Modules) hcl.Diagnostics {
Expand Down Expand Up @@ -53,12 +55,12 @@ func unresolvedModules(modules terraform.Modules) hcl.Diagnostics {
label += " " + fmt.Sprintf("%q", l)
}

diags = diags.Append(&hcl.Diagnostic{
diags = diags.Append(types.DiagnosticCode(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: "Module not loaded. Did you run `terraform init`?",
Detail: fmt.Sprintf("Module '%s' in file %q cannot be resolved. This module will be ignored.", label, block.HCLBlock().DefRange),
Subject: &(block.HCLBlock().DefRange),
})
}, types.DiagnosticModuleNotLoaded))
}
}
}
Expand Down
Loading