Remove remote/local var warns support. Will be handled in a future iteration

Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
This commit is contained in:
yottta
2025-03-07 11:01:56 +02:00
committed by Christian Mesh
parent cd927a7dc9
commit 17c5cad0c6
3 changed files with 7 additions and 29 deletions

View File

@@ -478,16 +478,12 @@ You can correct this by removing references to sensitive values, or by carefully
}, diags
}
// evalVariableDeprecation checks a variable "deprecated" message
func evalVariableDeprecation(addr addrs.AbsInputVariableInstance, config *configs.Variable, expr hcl.Expression, ctx EvalContext, onlyLocal bool) (diags tfdiags.Diagnostics) {
// evalVariableDeprecation checks if a variable is deprecated and if so it returns a warning diagnostic to be shown to the user
func evalVariableDeprecation(addr addrs.AbsInputVariableInstance, config *configs.Variable, expr hcl.Expression, ctx EvalContext) tfdiags.Diagnostics {
if !config.DeprecatedSet {
log.Printf("[TRACE] evalVariableDeprecation: variable %s is having no deprecation configured", addr)
return nil
}
if onlyLocal && strings.HasPrefix(config.DeclRange.Filename, ".terraform") {
log.Printf("[TRACE] evalVariableDeprecation: variable %s is part of a remote module and was requested to ignore those", addr)
return nil
}
// if the variable is not given in the module call, do not show a warning
if expr == nil {
log.Printf("[TRACE] evalVariableDeprecation: variable %s is marked as deprecated but is not used", addr)
@@ -499,7 +495,7 @@ func evalVariableDeprecation(addr addrs.AbsInputVariableInstance, config *config
return nil
}
log.Printf("[TRACE] evalVariableDeprecation: usage of deprecated variable %q detected", addr)
// Any deprecated
var diags tfdiags.Diagnostics
return diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagWarning,
Summary: fmt.Sprintf(`The variable %q is marked as deprecated by module author`, config.Name),

View File

@@ -1484,10 +1484,9 @@ func TestEvalVariableValidations_deprecationDiagnostics(t *testing.T) {
}
tests := map[string]struct {
varAddr addrs.AbsInputVariableInstance
varCfg *configs.Variable
expr hcl.Expression
onlyLocal bool
varAddr addrs.AbsInputVariableInstance
varCfg *configs.Variable
expr hcl.Expression
expectedDiags tfdiags.Diagnostics
}{
@@ -1544,7 +1543,6 @@ func TestEvalVariableValidations_deprecationDiagnostics(t *testing.T) {
tt.varCfg,
expr,
ctx,
false,
)
if gotLen, expectedLen := len(gotDiags), len(tt.expectedDiags); gotLen != expectedLen {
@@ -1568,20 +1566,4 @@ func TestEvalVariableValidations_deprecationDiagnostics(t *testing.T) {
}
})
}
t.Run("remote-mod-called-from-root", func(t *testing.T) {
varAddr := addrs.InputVariable{Name: "foo"}.Absolute(addrs.RootModuleInstance.Child("foo-call", nil))
varCfg := cfg.Children["foo-call"].Module.Variables["foo"]
// NOTE: this is just to test that diags are not returned when remote are excluded
varCfg.DeclRange.Filename = ".terraform/modules/" + varCfg.DeclRange.Filename
gotDiags := evalVariableDeprecation(
varAddr,
varCfg,
cfg.Module.ModuleCalls["foo-call"].Source,
ctx,
true,
)
if len(gotDiags) != 0 {
t.Fatalf("unexpected diags returned. %+v", gotDiags)
}
})
}

View File

@@ -146,7 +146,7 @@ func (n *nodeVariableReferenceInstance) ModulePath() addrs.Module {
func (n *nodeVariableReferenceInstance) Execute(ctx EvalContext, op walkOperation) tfdiags.Diagnostics {
log.Printf("[TRACE] nodeVariableReferenceInstance: evaluating %s", n.Addr)
diags := evalVariableValidations(n.Addr, n.Config, n.Expr, ctx)
diags = diags.Append(evalVariableDeprecation(n.Addr, n.Config, n.Expr, ctx, false)) // TODO provide this bool from cli arg
diags = diags.Append(evalVariableDeprecation(n.Addr, n.Config, n.Expr, ctx))
if op == walkValidate {
var filtered tfdiags.Diagnostics