From 2b38f9ba260b269cc232774a961a1c2cb68089b4 Mon Sep 17 00:00:00 2001 From: Jean-Francois Remy Date: Sat, 27 May 2023 17:03:34 -0700 Subject: [PATCH] SetAttribute* methods are not returning new Attribute The SetAttribute* methods are supposed to return the considered attribute (new or existing) However, because of the variable shadowing in the creation path, it does not return the new Attribute and instead return nil Fix the code to return the create Attribute when it is not already present in the body --- hclwrite/ast_body.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hclwrite/ast_body.go b/hclwrite/ast_body.go index 6321509a..994c6eb4 100644 --- a/hclwrite/ast_body.go +++ b/hclwrite/ast_body.go @@ -150,7 +150,7 @@ func (b *Body) SetAttributeRaw(name string, tokens Tokens) *Attribute { if attr != nil { attr.expr = attr.expr.ReplaceWith(expr) } else { - attr := newAttribute() + attr = newAttribute() attr.init(name, expr) b.appendItem(attr) } @@ -171,7 +171,7 @@ func (b *Body) SetAttributeValue(name string, val cty.Value) *Attribute { if attr != nil { attr.expr = attr.expr.ReplaceWith(expr) } else { - attr := newAttribute() + attr = newAttribute() attr.init(name, expr) b.appendItem(attr) } @@ -192,7 +192,7 @@ func (b *Body) SetAttributeTraversal(name string, traversal hcl.Traversal) *Attr if attr != nil { attr.expr = attr.expr.ReplaceWith(expr) } else { - attr := newAttribute() + attr = newAttribute() attr.init(name, expr) b.appendItem(attr) }