terraform: module dependencies in graph use full name (FOR THE FUTURE)

This commit is contained in:
Mitchell Hashimoto 2015-04-30 17:19:01 -07:00
parent 90cfade626
commit 15ca84a682
4 changed files with 23 additions and 4 deletions

View File

@ -58,7 +58,15 @@ func (n *GraphNodeConfigModule) ConfigType() GraphNodeConfigType {
}
func (n *GraphNodeConfigModule) DependableName() []string {
return []string{n.Name()}
config := n.Tree.Config()
result := make([]string, 1, len(config.Outputs)+1)
result[0] = n.Name()
for _, o := range config.Outputs {
result = append(result, fmt.Sprintf("%s.%s", n.Name(), o.Name))
}
return result
}
func (n *GraphNodeConfigModule) DependentOn() []string {

View File

@ -1 +1,3 @@
resource "aws_instance" "server" {}
output "security_group" { value = "" }

View File

@ -105,7 +105,7 @@ func (t *ConfigTransformer) Transform(g *Graph) error {
func varNameForVar(raw config.InterpolatedVariable) string {
switch v := raw.(type) {
case *config.ModuleVariable:
return fmt.Sprintf("module.%s", v.Name)
return fmt.Sprintf("module.%s.%s", v.Name, v.Field)
case *config.ResourceVariable:
return v.ResourceId()
case *config.UserVariable:

View File

@ -174,9 +174,18 @@ func (n *graphNodeExpandedResource) StateDependencies() []string {
depsRaw := n.DependentOn()
deps := make([]string, 0, len(depsRaw))
for _, d := range depsRaw {
if !strings.HasPrefix(d, "var.") {
deps = append(deps, d)
// Ignore any variable dependencies
if strings.HasPrefix(d, "var.") {
continue
}
// This is sad. The dependencies are currently in the format of
// "module.foo.bar" (the full field). This strips the field off.
if strings.HasPrefix(d, "module.") {
parts := strings.SplitN(d, ".", 3)
d = strings.Join(parts[0:2], ".")
}
deps = append(deps, d)
}
return deps