Skip to content

Commit

Permalink
Merge pull request #31612 from hashicorp/backport/jbardin/static-vali…
Browse files Browse the repository at this point in the history
…date-warnings/initially-steady-rattler

Backport of don't lose warnings from static validation into v1.2
  • Loading branch information
jbardin committed Aug 10, 2022
2 parents b248819 + a2efe63 commit f58aeb3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/lang/eval.go
Expand Up @@ -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
}

Expand Down
35 changes: 35 additions & 0 deletions internal/terraform/context_validate_test.go
Expand Up @@ -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)
}
}

0 comments on commit f58aeb3

Please sign in to comment.