From 714d390a0cdd39c3c50e7dabf30f6d2dfd130acf Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 30 Jun 2025 13:47:02 -0500 Subject: [PATCH] feat: add specific code to module missing warning --- types/diagnostics.go | 5 +++++ warnings.go | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/types/diagnostics.go b/types/diagnostics.go index 1884726..c13da4d 100644 --- a/types/diagnostics.go +++ b/types/diagnostics.go @@ -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 { diff --git a/warnings.go b/warnings.go index 781f49a..12011f5 100644 --- a/warnings.go +++ b/warnings.go @@ -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 { @@ -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)) } } }