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

Method SetAttributeTraversal

hclwrite/ast_body.go:204–215  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

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

Tested by 2