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

Method SetAttributeRaw

hclwrite/ast_body.go:162–173  ·  view source on GitHub ↗

SetAttributeRaw either replaces the expression of an existing attribute of the given name or adds a new attribute definition to the end of the block, using the given tokens verbatim as the expression. The same caveats apply to this function as for NewExpressionRaw on which it is based. If possible,

(name string, tokens Tokens)

Source from the content-addressed store, hash-verified

160// it is based. If possible, prefer to use SetAttributeValue or
161// SetAttributeTraversal.
162func (b *Body) SetAttributeRaw(name string, tokens Tokens) *Attribute {
163 attr := b.GetAttribute(name)
164 expr := NewExpressionRaw(tokens)
165 if attr != nil {
166 attr.expr = attr.expr.ReplaceWith(expr)
167 } else {
168 attr := newAttribute()
169 attr.init(name, expr)
170 b.appendItem(attr)
171 }
172 return attr
173}
174
175// SetAttributeValue either replaces the expression of an existing attribute
176// of the given name or adds a new attribute definition to the end of the block.

Callers 1

TestBodySetAttributeRawFunction · 0.80

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
NewExpressionRawFunction · 0.85
newAttributeFunction · 0.85
ReplaceWithMethod · 0.80
initMethod · 0.45

Tested by 1

TestBodySetAttributeRawFunction · 0.64