|
9 | 9 | "github.com/hashicorp/hcl/v2" |
10 | 10 | "github.com/hashicorp/hcl/v2/gohcl" |
11 | 11 | "github.com/hashicorp/hcl/v2/hclsyntax" |
12 | | - hcljson "github.com/hashicorp/hcl/v2/json" |
13 | 12 |
|
14 | 13 | "github.com/hashicorp/terraform/internal/addrs" |
15 | 14 | "github.com/hashicorp/terraform/internal/lang" |
@@ -539,34 +538,25 @@ func decodeDataBlock(block *hcl.Block, override, nested bool) (*Resource, hcl.Di |
539 | 538 | // replace_triggered_by expressions, ensuring they only contains references to |
540 | 539 | // a single resource, and the only extra variables are count.index or each.key. |
541 | 540 | func decodeReplaceTriggeredBy(expr hcl.Expression) ([]hcl.Expression, hcl.Diagnostics) { |
542 | | - // Since we are manually parsing the replace_triggered_by argument, we |
543 | | - // need to specially handle json configs, in which case the values will |
544 | | - // be json strings rather than hcl. To simplify parsing however we will |
545 | | - // decode the individual list elements, rather than the entire expression. |
546 | | - isJSON := hcljson.IsJSONExpression(expr) |
547 | | - |
548 | 541 | exprs, diags := hcl.ExprList(expr) |
| 542 | + if diags.HasErrors() { |
| 543 | + return nil, diags |
| 544 | + } |
549 | 545 |
|
550 | 546 | for i, expr := range exprs { |
551 | | - if isJSON { |
552 | | - // We can abuse the hcl json api and rely on the fact that calling |
553 | | - // Value on a json expression with no EvalContext will return the |
554 | | - // raw string. We can then parse that as normal hcl syntax, and |
555 | | - // continue with the decoding. |
556 | | - v, ds := expr.Value(nil) |
557 | | - diags = diags.Extend(ds) |
558 | | - if diags.HasErrors() { |
559 | | - continue |
560 | | - } |
561 | | - |
562 | | - expr, ds = hclsyntax.ParseExpression([]byte(v.AsString()), "", expr.Range().Start) |
563 | | - diags = diags.Extend(ds) |
564 | | - if diags.HasErrors() { |
565 | | - continue |
566 | | - } |
567 | | - // make sure to swap out the expression we're returning too |
568 | | - exprs[i] = expr |
| 547 | + // Since we are manually parsing the replace_triggered_by argument, we |
| 548 | + // need to specially handle json configs, in which case the values will |
| 549 | + // be json strings rather than hcl. To simplify parsing however we will |
| 550 | + // decode the individual list elements, rather than the entire |
| 551 | + // expression. |
| 552 | + var jsDiags hcl.Diagnostics |
| 553 | + expr, jsDiags = unwrapJSONRefExpr(expr) |
| 554 | + diags = diags.Extend(jsDiags) |
| 555 | + if diags.HasErrors() { |
| 556 | + continue |
569 | 557 | } |
| 558 | + // re-assign the value in case it was replaced by a json expression |
| 559 | + exprs[i] = expr |
570 | 560 |
|
571 | 561 | refs, refDiags := lang.ReferencesInExpr(addrs.ParseRef, expr) |
572 | 562 | for _, diag := range refDiags { |
|
0 commit comments