2015-01-21 16:39:16 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2015-01-23 19:52:51 -06:00
|
|
|
"github.com/hashicorp/terraform/config/module"
|
2015-01-22 19:12:32 -06:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2015-01-21 16:39:16 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// graphNodeConfig is an interface that all graph nodes for the
|
|
|
|
// configuration graph need to implement in order to build the variable
|
|
|
|
// dependencies properly.
|
|
|
|
type graphNodeConfig interface {
|
2015-01-23 17:21:27 -06:00
|
|
|
dag.NamedVertex
|
2015-01-21 16:39:16 -06:00
|
|
|
|
|
|
|
// Variables returns the full list of variables that this node
|
2015-01-21 17:37:17 -06:00
|
|
|
// depends on. The values within the slice should map to the VarName()
|
|
|
|
// values that are returned by any nodes.
|
|
|
|
Variables() []string
|
2015-01-21 16:39:16 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 16:53:50 -06:00
|
|
|
// GraphNodeConfigModule represents a module within the configuration graph.
|
|
|
|
type GraphNodeConfigModule struct {
|
|
|
|
Module *config.Module
|
2015-01-23 19:52:51 -06:00
|
|
|
Tree *module.Tree
|
2015-01-21 16:53:50 -06:00
|
|
|
}
|
|
|
|
|
2015-01-26 23:23:27 -06:00
|
|
|
func (n *GraphNodeConfigModule) DependableName() []string {
|
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
2015-01-21 16:53:50 -06:00
|
|
|
func (n *GraphNodeConfigModule) Name() string {
|
|
|
|
return fmt.Sprintf("module.%s", n.Module.Name)
|
|
|
|
}
|
|
|
|
|
2015-01-21 17:37:17 -06:00
|
|
|
func (n *GraphNodeConfigModule) Variables() []string {
|
|
|
|
vars := n.Module.RawConfig.Variables
|
|
|
|
result := make([]string, 0, len(vars))
|
|
|
|
for _, v := range vars {
|
|
|
|
result = append(result, varNameForVar(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2015-01-21 16:53:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2015-01-21 16:39:16 -06:00
|
|
|
type GraphNodeConfigProvider struct {
|
|
|
|
Provider *config.ProviderConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *GraphNodeConfigProvider) Name() string {
|
|
|
|
return fmt.Sprintf("provider.%s", n.Provider.Name)
|
|
|
|
}
|
|
|
|
|
2015-01-21 17:37:17 -06:00
|
|
|
func (n *GraphNodeConfigProvider) Variables() []string {
|
|
|
|
vars := n.Provider.RawConfig.Variables
|
|
|
|
result := make([]string, 0, len(vars))
|
|
|
|
for _, v := range vars {
|
|
|
|
result = append(result, varNameForVar(v))
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2015-01-21 16:39:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeConfigResource represents a resource within the config graph.
|
|
|
|
type GraphNodeConfigResource struct {
|
|
|
|
Resource *config.Resource
|
|
|
|
}
|
|
|
|
|
2015-01-26 22:17:52 -06:00
|
|
|
func (n *GraphNodeConfigResource) DependableName() []string {
|
|
|
|
return []string{n.Resource.Id()}
|
|
|
|
}
|
|
|
|
|
2015-01-21 16:39:16 -06:00
|
|
|
func (n *GraphNodeConfigResource) Name() string {
|
|
|
|
return n.Resource.Id()
|
|
|
|
}
|
|
|
|
|
2015-01-21 17:37:17 -06:00
|
|
|
func (n *GraphNodeConfigResource) Variables() []string {
|
|
|
|
result := make([]string, len(n.Resource.DependsOn),
|
|
|
|
len(n.Resource.RawCount.Variables)+
|
|
|
|
len(n.Resource.RawConfig.Variables)+
|
|
|
|
len(n.Resource.DependsOn))
|
|
|
|
copy(result, n.Resource.DependsOn)
|
|
|
|
for _, v := range n.Resource.RawCount.Variables {
|
|
|
|
result = append(result, varNameForVar(v))
|
|
|
|
}
|
|
|
|
for _, v := range n.Resource.RawConfig.Variables {
|
|
|
|
result = append(result, varNameForVar(v))
|
2015-01-21 16:39:16 -06:00
|
|
|
}
|
|
|
|
|
2015-01-21 17:37:17 -06:00
|
|
|
return result
|
2015-01-21 16:39:16 -06:00
|
|
|
}
|