mirror of
https://github.com/hashicorp/terraform.git
synced 2026-05-28 04:03:27 -04:00
use validate for primitive types
This commit is contained in:
parent
e6d969a2eb
commit
b09ef138fc
3 changed files with 29 additions and 23 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
diags = diags.Append(ctx.Deprecations().ValidateAsConfig(blockVal, n.ModulePath()))
|
||||
var blockVal, limit, includeResource cty.Value
|
||||
var includeDiags tfdiags.Diagnostics
|
||||
|
||||
limit, _, limitDiags := newLimitEvaluator(true).EvaluateExpr(ctx, n.Config.List.Limit)
|
||||
diags = diags.Append(limitDiags)
|
||||
if limitDiags.HasErrors() {
|
||||
return diags
|
||||
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()))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue