2015-01-21 23:39:16 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2015-01-24 02:52:51 +01:00
|
|
|
"github.com/hashicorp/terraform/config/module"
|
2015-01-23 02:12:32 +01:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2015-01-21 23:39:16 +01: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-24 00:21:27 +01:00
|
|
|
dag.NamedVertex
|
2015-01-21 23:39:16 +01:00
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
// All graph nodes should be dependent on other things, and able to
|
|
|
|
// be depended on.
|
|
|
|
GraphNodeDependable
|
|
|
|
GraphNodeDependent
|
2015-01-21 23:39:16 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 23:53:50 +01:00
|
|
|
// GraphNodeConfigModule represents a module within the configuration graph.
|
|
|
|
type GraphNodeConfigModule struct {
|
|
|
|
Module *config.Module
|
2015-01-24 02:52:51 +01:00
|
|
|
Tree *module.Tree
|
2015-01-21 23:53:50 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 06:23:27 +01:00
|
|
|
func (n *GraphNodeConfigModule) DependableName() []string {
|
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
2015-01-21 23:53:50 +01:00
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func (n *GraphNodeConfigModule) DependentOn() []string {
|
2015-01-22 00:37:17 +01:00
|
|
|
vars := n.Module.RawConfig.Variables
|
|
|
|
result := make([]string, 0, len(vars))
|
|
|
|
for _, v := range vars {
|
2015-01-27 23:56:01 +01:00
|
|
|
if vn := varNameForVar(v); vn != "" {
|
|
|
|
result = append(result, vn)
|
|
|
|
}
|
2015-01-22 00:37:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2015-01-21 23:53:50 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func (n *GraphNodeConfigModule) Name() string {
|
|
|
|
return fmt.Sprintf("module.%s", n.Module.Name)
|
|
|
|
}
|
|
|
|
|
2015-01-21 23:53:50 +01: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 23:39:16 +01:00
|
|
|
type GraphNodeConfigProvider struct {
|
|
|
|
Provider *config.ProviderConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *GraphNodeConfigProvider) Name() string {
|
|
|
|
return fmt.Sprintf("provider.%s", n.Provider.Name)
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func (n *GraphNodeConfigProvider) DependableName() []string {
|
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *GraphNodeConfigProvider) DependentOn() []string {
|
2015-01-22 00:37:17 +01:00
|
|
|
vars := n.Provider.RawConfig.Variables
|
|
|
|
result := make([]string, 0, len(vars))
|
|
|
|
for _, v := range vars {
|
2015-01-27 23:56:01 +01:00
|
|
|
if vn := varNameForVar(v); vn != "" {
|
|
|
|
result = append(result, vn)
|
|
|
|
}
|
2015-01-22 00:37:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
2015-01-21 23:39:16 +01:00
|
|
|
}
|
|
|
|
|
2015-02-03 10:43:18 +01:00
|
|
|
// GraphNodeEvalable impl.
|
|
|
|
func (n *GraphNodeConfigProvider) EvalTree() EvalNode {
|
2015-02-05 23:32:36 +01:00
|
|
|
return ProviderEvalTree(n.Provider.Name, n.Provider.RawConfig)
|
2015-02-03 10:43:18 +01:00
|
|
|
}
|
|
|
|
|
2015-01-28 06:48:46 +01:00
|
|
|
// GraphNodeProvider implementation
|
|
|
|
func (n *GraphNodeConfigProvider) ProviderName() string {
|
|
|
|
return n.Provider.Name
|
|
|
|
}
|
|
|
|
|
2015-01-21 23:39:16 +01:00
|
|
|
// GraphNodeConfigResource represents a resource within the config graph.
|
|
|
|
type GraphNodeConfigResource struct {
|
|
|
|
Resource *config.Resource
|
|
|
|
}
|
|
|
|
|
2015-01-27 05:17:52 +01:00
|
|
|
func (n *GraphNodeConfigResource) DependableName() []string {
|
|
|
|
return []string{n.Resource.Id()}
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:56:01 +01:00
|
|
|
func (n *GraphNodeConfigResource) DependentOn() []string {
|
2015-01-22 00:37:17 +01:00
|
|
|
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 {
|
2015-01-27 23:56:01 +01:00
|
|
|
if vn := varNameForVar(v); vn != "" {
|
|
|
|
result = append(result, vn)
|
|
|
|
}
|
2015-01-22 00:37:17 +01:00
|
|
|
}
|
|
|
|
for _, v := range n.Resource.RawConfig.Variables {
|
2015-01-27 23:56:01 +01:00
|
|
|
if vn := varNameForVar(v); vn != "" {
|
|
|
|
result = append(result, vn)
|
|
|
|
}
|
2015-01-21 23:39:16 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 00:37:17 +01:00
|
|
|
return result
|
2015-01-21 23:39:16 +01:00
|
|
|
}
|
2015-01-27 23:56:01 +01:00
|
|
|
|
|
|
|
func (n *GraphNodeConfigResource) Name() string {
|
|
|
|
return n.Resource.Id()
|
|
|
|
}
|
2015-01-28 06:48:46 +01:00
|
|
|
|
2015-02-05 00:44:23 +01:00
|
|
|
// GraphNodeEvalable impl.
|
|
|
|
func (n *GraphNodeConfigResource) EvalTree() EvalNode {
|
2015-02-05 02:23:26 +01:00
|
|
|
return &EvalSequence{
|
|
|
|
Nodes: []EvalNode{
|
|
|
|
&EvalValidateResource{
|
|
|
|
Provider: &EvalGetProvider{Name: n.ProvidedBy()},
|
2015-02-05 23:32:36 +01:00
|
|
|
Config: &EvalInterpolate{Config: n.Resource.RawConfig},
|
2015-02-05 02:23:26 +01:00
|
|
|
ProviderType: n.ProvidedBy(),
|
|
|
|
},
|
|
|
|
},
|
2015-02-05 00:44:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 06:48:46 +01:00
|
|
|
// GraphNodeProviderConsumer
|
|
|
|
func (n *GraphNodeConfigResource) ProvidedBy() string {
|
|
|
|
return resourceProvider(n.Resource.Type)
|
|
|
|
}
|