Skip to content

Commit c3d6e86

Browse files
authored
feat: add specific code to module missing warning (#162)
1 parent 25471dd commit c3d6e86

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

types/diagnostics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const (
1010
// DiagnosticCodeRequired is used when a parameter value is `null`, but
1111
// the parameter is required.
1212
DiagnosticCodeRequired = "required"
13+
14+
// DiagnosticModuleNotLoaded is used when a module block is present, but
15+
// the mode failed to load. This can be because `.terraform/modules` is
16+
// not present.
17+
DiagnosticModuleNotLoaded = "module_not_loaded"
1318
)
1419

1520
type DiagnosticExtra struct {

warnings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66

77
"github.com/aquasecurity/trivy/pkg/iac/terraform"
88
"github.com/hashicorp/hcl/v2"
9+
10+
"github.com/coder/preview/types"
911
)
1012

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

56-
diags = diags.Append(&hcl.Diagnostic{
58+
diags = diags.Append(types.DiagnosticCode(&hcl.Diagnostic{
5759
Severity: hcl.DiagWarning,
5860
Summary: "Module not loaded. Did you run `terraform init`?",
5961
Detail: fmt.Sprintf("Module '%s' in file %q cannot be resolved. This module will be ignored.", label, block.HCLBlock().DefRange),
6062
Subject: &(block.HCLBlock().DefRange),
61-
})
63+
}, types.DiagnosticModuleNotLoaded))
6264
}
6365
}
6466
}

0 commit comments

Comments
 (0)