From a2efe63df3a8142f3250ebc4abde7d0b79e0824b Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 9 Aug 2022 20:15:56 +0000 Subject: [PATCH] backport of commit 893a5336d859a762a35c43e8a0b6fa863712de1e --- internal/lang/eval.go | 5 +-- internal/terraform/context_validate_test.go | 35 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/internal/lang/eval.go b/internal/lang/eval.go index fe5fc1b76469..5c82392bcc44 100644 --- a/internal/lang/eval.go +++ b/internal/lang/eval.go @@ -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 } diff --git a/internal/terraform/context_validate_test.go b/internal/terraform/context_validate_test.go index cb1e31fe4ba6..47e71f404f07 100644 --- a/internal/terraform/context_validate_test.go +++ b/internal/terraform/context_validate_test.go @@ -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) + } +}