SetAttributeTraversal either replaces the expression of an existing attribute of the given name or adds a new attribute definition to the end of the body. The new expression is given as a hcl.Traversal, which must be an absolute traversal. To set a literal value, use SetAttributeValue. The return
(name string, traversal hcl.Traversal)
| 202 | // The return value is the attribute that was either modified in-place or |
| 203 | // created. |
| 204 | func (b *Body) SetAttributeTraversal(name string, traversal hcl.Traversal) *Attribute { |
| 205 | attr := b.GetAttribute(name) |
| 206 | expr := NewExpressionAbsTraversal(traversal) |
| 207 | if attr != nil { |
| 208 | attr.expr = attr.expr.ReplaceWith(expr) |
| 209 | } else { |
| 210 | attr := newAttribute() |
| 211 | attr.init(name, expr) |
| 212 | b.appendItem(attr) |
| 213 | } |
| 214 | return attr |
| 215 | } |
| 216 | |
| 217 | // RemoveAttribute removes the attribute with the given name from the body. |
| 218 | // |