SetAttributeValue either replaces the expression of an existing attribute of the given name or adds a new attribute definition to the end of the block. The value is given as a cty.Value, and must therefore be a literal. To set a variable reference or other traversal, use SetAttributeTraversal. The
(name string, val cty.Value)
| 181 | // The return value is the attribute that was either modified in-place or |
| 182 | // created. |
| 183 | func (b *Body) SetAttributeValue(name string, val cty.Value) *Attribute { |
| 184 | attr := b.GetAttribute(name) |
| 185 | expr := NewExpressionLiteral(val) |
| 186 | if attr != nil { |
| 187 | attr.expr = attr.expr.ReplaceWith(expr) |
| 188 | } else { |
| 189 | attr := newAttribute() |
| 190 | attr.init(name, expr) |
| 191 | b.appendItem(attr) |
| 192 | } |
| 193 | return attr |
| 194 | } |
| 195 | |
| 196 | // SetAttributeTraversal either replaces the expression of an existing attribute |
| 197 | // of the given name or adds a new attribute definition to the end of the body. |