terraform: config graph respects depends_on
This commit is contained in:
parent
eb1a1fa7c9
commit
012dcca7d5
|
@ -54,8 +54,7 @@ func Graph2(mod *module.Tree) (*depgraph.Graph, error) {
|
||||||
// of var names to the actual node with that name.
|
// of var names to the actual node with that name.
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
m := make(map[string]depgraph.Node)
|
m := make(map[string]depgraph.Node)
|
||||||
for _, v := range n.Variables() {
|
for _, id := range n.Variables() {
|
||||||
id := varNameForVar(v)
|
|
||||||
m[id] = fullMap[id]
|
m[id] = fullMap[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,9 @@ type graphNodeConfig interface {
|
||||||
depgraph.Node
|
depgraph.Node
|
||||||
|
|
||||||
// Variables returns the full list of variables that this node
|
// Variables returns the full list of variables that this node
|
||||||
// depends on.
|
// depends on. The values within the slice should map to the VarName()
|
||||||
Variables() map[string]config.InterpolatedVariable
|
// values that are returned by any nodes.
|
||||||
|
Variables() []string
|
||||||
|
|
||||||
// VarName returns the name that is used to identify a variable
|
// VarName returns the name that is used to identify a variable
|
||||||
// maps to this node. It should match the result of the
|
// maps to this node. It should match the result of the
|
||||||
|
@ -67,8 +68,14 @@ func (n *GraphNodeConfigModule) Name() string {
|
||||||
return fmt.Sprintf("module.%s", n.Module.Name)
|
return fmt.Sprintf("module.%s", n.Module.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigModule) Variables() map[string]config.InterpolatedVariable {
|
func (n *GraphNodeConfigModule) Variables() []string {
|
||||||
return n.Module.RawConfig.Variables
|
vars := n.Module.RawConfig.Variables
|
||||||
|
result := make([]string, 0, len(vars))
|
||||||
|
for _, v := range vars {
|
||||||
|
result = append(result, varNameForVar(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigModule) VarName() string {
|
func (n *GraphNodeConfigModule) VarName() string {
|
||||||
|
@ -88,8 +95,14 @@ func (n *GraphNodeConfigProvider) Name() string {
|
||||||
return fmt.Sprintf("provider.%s", n.Provider.Name)
|
return fmt.Sprintf("provider.%s", n.Provider.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigProvider) Variables() map[string]config.InterpolatedVariable {
|
func (n *GraphNodeConfigProvider) Variables() []string {
|
||||||
return n.Provider.RawConfig.Variables
|
vars := n.Provider.RawConfig.Variables
|
||||||
|
result := make([]string, 0, len(vars))
|
||||||
|
for _, v := range vars {
|
||||||
|
result = append(result, varNameForVar(v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigProvider) VarName() string {
|
func (n *GraphNodeConfigProvider) VarName() string {
|
||||||
|
@ -107,19 +120,20 @@ func (n *GraphNodeConfigResource) Name() string {
|
||||||
return n.Resource.Id()
|
return n.Resource.Id()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigResource) Variables() map[string]config.InterpolatedVariable {
|
func (n *GraphNodeConfigResource) Variables() []string {
|
||||||
var m map[string]config.InterpolatedVariable
|
result := make([]string, len(n.Resource.DependsOn),
|
||||||
if n.Resource != nil {
|
len(n.Resource.RawCount.Variables)+
|
||||||
m = make(map[string]config.InterpolatedVariable)
|
len(n.Resource.RawConfig.Variables)+
|
||||||
for k, v := range n.Resource.RawCount.Variables {
|
len(n.Resource.DependsOn))
|
||||||
m[k] = v
|
copy(result, n.Resource.DependsOn)
|
||||||
}
|
for _, v := range n.Resource.RawCount.Variables {
|
||||||
for k, v := range n.Resource.RawConfig.Variables {
|
result = append(result, varNameForVar(v))
|
||||||
m[k] = v
|
}
|
||||||
}
|
for _, v := range n.Resource.RawConfig.Variables {
|
||||||
|
result = append(result, varNameForVar(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *GraphNodeConfigResource) VarName() string {
|
func (n *GraphNodeConfigResource) VarName() string {
|
||||||
|
|
|
@ -40,6 +40,19 @@ func TestGraph(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGraph2_dependsOn(t *testing.T) {
|
||||||
|
g, err := Graph2(testModule(t, "graph-depends-on"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(g.String())
|
||||||
|
expected := strings.TrimSpace(testGraphDependsOnStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad:\n\n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGraph2_modules(t *testing.T) {
|
func TestGraph2_modules(t *testing.T) {
|
||||||
g, err := Graph2(testModule(t, "graph-modules"))
|
g, err := Graph2(testModule(t, "graph-modules"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,6 +77,12 @@ provider.aws
|
||||||
openstack_floating_ip.random
|
openstack_floating_ip.random
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testGraphDependsOnStr = `
|
||||||
|
aws_instance.db
|
||||||
|
aws_instance.web
|
||||||
|
aws_instance.web
|
||||||
|
`
|
||||||
|
|
||||||
const testGraphModulesStr = `
|
const testGraphModulesStr = `
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
aws_security_group.firewall
|
aws_security_group.firewall
|
||||||
|
|
Loading…
Reference in New Issue