MCPcopy
hub / github.com/hashicorp/hcl / SetAttributeValue

Method SetAttributeValue

hclwrite/ast_body.go:183–194  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

181// The return value is the attribute that was either modified in-place or
182// created.
183func (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.

Implementers 8

Bodyhclsyntax/structure.go
unknownBodyext/dynblock/unknown_body.go
expandBodyext/dynblock/expand_body.go
deepWrapperext/transform/transform.go
diagBodyext/transform/error.go
bodyjson/structure.go
mockBodyhcltest/mock.go

Calls 6

GetAttributeMethod · 0.95
appendItemMethod · 0.95
NewExpressionLiteralFunction · 0.85
newAttributeFunction · 0.85
ReplaceWithMethod · 0.80
initMethod · 0.45