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:
James Bardin 2022-08-09 16:15:56 -04:00
parent c4e223c7a0
commit 893a5336d8
2 changed files with 38 additions and 2 deletions

View File

@ -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
}

View File

@ -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)
}
}