From a8f97a08052ff206a7b9844f031d9f7db9d4dc24 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 30 Jan 2019 18:15:52 -0800 Subject: [PATCH] core: Use hcl.ApplyPath for ignore_changes and "requires replace" We were previously using cty.Path.Apply, which serves a similar purpose but implements the more restrictive traversal behaviors down at the cty layer. hcl.ApplyPath uses the same rules as HCL expressions and so ensures consistent behavior with normal user expressions. cty.Path.Apply also previously had a crashing bug (discussed in #20084) that was causing a panic here. That has now been fixed in cty, but since we're no longer using it here that's a moot point. The HCL traversing implementation has been fuzz-tested and unit tested a lot more thoroughly so should not run into the same crashers we saw with cty before. --- terraform/eval_diff.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index e0f0b0444..0f6b12d81 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -240,8 +240,8 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) { // when we use this value below, if the provider misbehaves.) continue } - plannedChangedVal, err := path.Apply(plannedNewVal) - if err != nil { + plannedChangedVal, pathDiags := hcl.ApplyPath(plannedNewVal, path, nil) + if pathDiags.HasErrors() { // This always indicates a provider bug, since RequiresReplace // should always refer only to whole attributes (and not into // attribute values themselves) and these should always be @@ -492,9 +492,9 @@ func processIgnoreChangesIndividual(prior, proposed cty.Value, ignoreChanges []h // If we're able to follow the same path through the prior value, // we'll take the value there instead, effectively undoing the // change that was planned. - priorV, err := path.Apply(prior) - if err != nil { - // We just ignore the error and move on here, since we assume it's + priorV, diags := hcl.ApplyPath(prior, path, nil) + if diags.HasErrors() { + // We just ignore the errors and move on here, since we assume it's // just because the prior value was a slightly-different shape. // It could potentially also be that the traversal doesn't match // the schema, but we should've caught that during the validate