diff --git a/internal/deprecation/deprecation.go b/internal/deprecation/deprecation.go index 1507b9a07c..be9060c51e 100644 --- a/internal/deprecation/deprecation.go +++ b/internal/deprecation/deprecation.go @@ -38,7 +38,8 @@ func (d *Deprecations) SuppressModuleCallDeprecation(addr addrs.Module) { // Validate checks the given value for deprecation marks and returns diagnostics // for each deprecation found, unless deprecation warnings are suppressed for the given module. -// This is appropriate for non-terminal values (values that can be referenced) only. +// This is only appropriate for non-terminal values (values that can be referenced) and primitive +// values. // If the value can not be referenced, use ValidateDeep or ValidateAsConfig instead. func (d *Deprecations) Validate(value cty.Value, module addrs.Module, rng *hcl.Range) (cty.Value, tfdiags.Diagnostics) { deprecationMarks := marks.GetDeprecationMarks(value) diff --git a/internal/terraform/eval_count.go b/internal/terraform/eval_count.go index 836995d731..0eb12ddffd 100644 --- a/internal/terraform/eval_count.go +++ b/internal/terraform/eval_count.go @@ -102,7 +102,7 @@ func evaluateCountExpressionValue(expr hcl.Expression, ctx EvalContext) (cty.Val }) } - countVal, deprecationDiags := ctx.Deprecations().ValidateDeep(countVal, ctx.Path().Module(), expr.Range().Ptr()) + countVal, deprecationDiags := ctx.Deprecations().Validate(countVal, ctx.Path().Module(), expr.Range().Ptr()) diags = diags.Append(deprecationDiags) // Sensitive values are allowed in count but not for_each. This is a diff --git a/internal/terraform/node_resource_validate.go b/internal/terraform/node_resource_validate.go index 8028dd1e5c..0620e9cc0a 100644 --- a/internal/terraform/node_resource_validate.go +++ b/internal/terraform/node_resource_validate.go @@ -493,34 +493,39 @@ func (n *NodeValidatableResource) validateResource(ctx EvalContext) tfdiags.Diag return diags } - blockVal, _, valDiags := ctx.EvaluateBlock(n.Config.Config, schema.FullSchema, nil, keyData) - diags = diags.Append(valDiags) - if valDiags.HasErrors() { - return diags + var blockVal, limit, includeResource cty.Value + var includeDiags tfdiags.Diagnostics + + if n.Config.Config != nil { + var valDiags tfdiags.Diagnostics + blockVal, _, valDiags = ctx.EvaluateBlock(n.Config.Config, schema.FullSchema, nil, keyData) + diags = diags.Append(valDiags) + if valDiags.HasErrors() { + return diags + } + diags = diags.Append(ctx.Deprecations().ValidateAsConfig(blockVal, n.ModulePath())) } - diags = diags.Append(ctx.Deprecations().ValidateAsConfig(blockVal, n.ModulePath())) - limit, _, limitDiags := newLimitEvaluator(true).EvaluateExpr(ctx, n.Config.List.Limit) - diags = diags.Append(limitDiags) - if limitDiags.HasErrors() { - return diags - } if n.Config.List.Limit != nil { - var limitDeprecationDiags tfdiags.Diagnostics - limit, limitDeprecationDiags = ctx.Deprecations().Validate(limit, n.ModulePath(), n.Config.List.Limit.Range().Ptr()) - diags = diags.Append(limitDeprecationDiags) + var limitDiags tfdiags.Diagnostics + limit, _, limitDiags = newLimitEvaluator(true).EvaluateExpr(ctx, n.Config.List.Limit) + diags = diags.Append(limitDiags) + if limitDiags.HasErrors() { + return diags + } + _, deprecationDiags := ctx.Deprecations().Validate(limit, n.ModulePath(), n.Config.List.Limit.Range().Ptr()) + diags = diags.Append(deprecationDiags) limit = marks.RemoveDeprecationMarks(limit) } - includeResource, _, includeDiags := newIncludeRscEvaluator(true).EvaluateExpr(ctx, n.Config.List.IncludeResource) - diags = diags.Append(includeDiags) - if includeDiags.HasErrors() { - return diags - } if n.Config.List.IncludeResource != nil { - var includeDeprecationDiags tfdiags.Diagnostics - includeResource, includeDeprecationDiags = ctx.Deprecations().Validate(includeResource, n.ModulePath(), n.Config.List.IncludeResource.Range().Ptr()) - diags = diags.Append(includeDeprecationDiags) + includeResource, _, includeDiags = newIncludeRscEvaluator(true).EvaluateExpr(ctx, n.Config.List.IncludeResource) + diags = diags.Append(includeDiags) + if includeDiags.HasErrors() { + return diags + } + _, deprecationDiags := ctx.Deprecations().Validate(includeResource, n.ModulePath(), n.Config.List.IncludeResource.Range().Ptr()) + diags = diags.Append(deprecationDiags) includeResource = marks.RemoveDeprecationMarks(includeResource) }