mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
don't lose warnings from static validation
Warnings were dropped from static reference validation if there weren't also errors in the configuration.
This commit is contained in:
parent
c4e223c7a0
commit
893a5336d8
@ -259,8 +259,9 @@ func (s *Scope) evalContext(refs []*addrs.Reference, selfAddr addrs.Referenceabl
|
||||
// First we'll do static validation of the references. This catches things
|
||||
// early that might otherwise not get caught due to unknown values being
|
||||
// present in the scope during planning.
|
||||
if staticDiags := s.Data.StaticValidateReferences(refs, selfAddr); staticDiags.HasErrors() {
|
||||
diags = diags.Append(staticDiags)
|
||||
staticDiags := s.Data.StaticValidateReferences(refs, selfAddr)
|
||||
diags = diags.Append(staticDiags)
|
||||
if staticDiags.HasErrors() {
|
||||
return ctx, diags
|
||||
}
|
||||
|
||||
|
@ -2447,3 +2447,38 @@ resource "aws_instance" "test" {
|
||||
t.Fatal(diags.ErrWithWarnings())
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Validate_deprecatedAttr(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
p.GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema(&ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"foo": {Type: cty.String, Optional: true, Deprecated: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "aws_instance" "test" {
|
||||
}
|
||||
locals {
|
||||
deprecated = aws_instance.test.foo
|
||||
}
|
||||
|
||||
`,
|
||||
})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
diags := ctx.Validate(m)
|
||||
warn := diags.ErrWithWarnings().Error()
|
||||
if !strings.Contains(warn, `The attribute "foo" is deprecated`) {
|
||||
t.Fatalf("expected deprecated warning, got: %q\n", warn)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user