-
Notifications
You must be signed in to change notification settings - Fork 523
/
graph_vertex_local.go
62 lines (48 loc) 路 1.37 KB
/
graph_vertex_local.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package hcl
import (
"fmt"
"sync"
"github.com/rs/zerolog"
)
type VertexLocal struct {
logger zerolog.Logger
moduleConfigs *ModuleConfigs
block *Block
attr *Attribute
}
func (v *VertexLocal) ID() string {
return fmt.Sprintf("%s%s", v.block.FullName(), v.attr.Name())
}
func (v *VertexLocal) ModuleAddress() string {
return v.block.ModuleAddress()
}
func (v *VertexLocal) References() []VertexReference {
return v.attr.VerticesReferenced(v.block)
}
func (v *VertexLocal) Visit(mutex *sync.Mutex) error {
mutex.Lock()
defer mutex.Unlock()
moduleInstances := v.moduleConfigs.Get(v.block.ModuleAddress())
if len(moduleInstances) == 0 {
return fmt.Errorf("no module instances found for module address %q", v.block.ModuleAddress())
}
for _, moduleInstance := range moduleInstances {
e := moduleInstance.evaluator
v.logger.Debug().Msgf("adding attribute %s to the evaluation context", v.ID())
var attrInstance *Attribute
for _, b := range e.module.Blocks {
if b.LocalName() == v.block.LocalName() {
attrInstance = b.GetAttribute(v.attr.Name())
if attrInstance != nil {
break
}
}
}
if attrInstance == nil {
return fmt.Errorf("could not find attribute %q in module %q", v.ID(), moduleInstance.name)
}
key := fmt.Sprintf("local.%s", attrInstance.Name())
e.ctx.SetByDot(attrInstance.Value(), key)
}
return nil
}