terraform: put modules into the config graph

This commit is contained in:
Mitchell Hashimoto 2015-01-21 14:53:50 -08:00
parent 0f8c0eb981
commit eb1a1fa7c9
3 changed files with 49 additions and 3 deletions

View File

@ -25,7 +25,7 @@ func Graph2(mod *module.Tree) (*depgraph.Graph, error) {
// Create the node list we'll use for the graph
nodes := make([]graphNodeConfig, 0,
(len(config.Modules)+len(config.Resources))*2)
(len(config.ProviderConfigs)+len(config.Modules)+len(config.Resources))*2)
// Write all the provider configs out
for _, pc := range config.ProviderConfigs {
@ -38,7 +38,9 @@ func Graph2(mod *module.Tree) (*depgraph.Graph, error) {
}
// Write all the modules out
// TODO
for _, m := range config.Modules {
nodes = append(nodes, &GraphNodeConfigModule{Module: m})
}
// Build the full map of the var names to the nodes.
fullMap := make(map[string]depgraph.Node)

View File

@ -56,7 +56,28 @@ func (n *graphNodeConfigBasicDepMap) setDepMap(m map[string]depgraph.Node) {
n.DepMap = m
}
// GraphNodeConfigProvider represents a resource within the config graph.
// GraphNodeConfigModule represents a module within the configuration graph.
type GraphNodeConfigModule struct {
graphNodeConfigBasicDepMap
Module *config.Module
}
func (n *GraphNodeConfigModule) Name() string {
return fmt.Sprintf("module.%s", n.Module.Name)
}
func (n *GraphNodeConfigModule) Variables() map[string]config.InterpolatedVariable {
return n.Module.RawConfig.Variables
}
func (n *GraphNodeConfigModule) VarName() string {
return n.Name()
}
// GraphNodeConfigProvider represents a configured provider within the
// configuration graph. These are only immediately in the graph when an
// explicit `provider` configuration block is in the configuration.
type GraphNodeConfigProvider struct {
graphNodeConfigBasicDepMap

View File

@ -40,6 +40,19 @@ func TestGraph(t *testing.T) {
}
}
func TestGraph2_modules(t *testing.T) {
g, err := Graph2(testModule(t, "graph-modules"))
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testGraphModulesStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
const testGraphBasicStr = `
aws_instance.web
aws_security_group.firewall
@ -50,3 +63,13 @@ openstack_floating_ip.random
provider.aws
openstack_floating_ip.random
`
const testGraphModulesStr = `
aws_instance.web
aws_security_group.firewall
module.consul
aws_security_group.firewall
module.consul
aws_security_group.firewall
provider.aws
`