package terraform
import (
- "errors"
-
- "github.com/hashicorp/terraform/config/module"
+ "github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/dag"
)
type FlatConfigTransformer struct {
Concrete ConcreteResourceNodeFunc // What to turn resources into
- Module *module.Tree
+ Config *configs.Config
}
func (t *FlatConfigTransformer) Transform(g *Graph) error {
- // If no module, we do nothing
- if t.Module == nil {
+ // We have nothing to do if there is no configuration.
+ if t.Config == nil {
return nil
}
- // If the module is not loaded, that is an error
- if !t.Module.Loaded() {
- return errors.New("module must be loaded")
- }
-
- return t.transform(g, t.Module)
+ return t.transform(g, t.Config)
}
-func (t *FlatConfigTransformer) transform(g *Graph, m *module.Tree) error {
- // If no module, no problem
- if m == nil {
+func (t *FlatConfigTransformer) transform(g *Graph, config *configs.Config) error {
+ // If we have no configuration then there's nothing to do.
+ if config == nil {
return nil
}
// Transform all the children.
- for _, c := range m.Children() {
+ for _, c := range config.Children {
if err := t.transform(g, c); err != nil {
return err
}
}
- // Get the configuration for this module
- config := m.Config()
-
- // Write all the resources out
- for _, r := range config.Resources {
- // Grab the address for this resource
- addr, err := parseResourceAddressConfig(r)
- if err != nil {
- return err
- }
- addr.Path = m.Path()
+ module := config.Module
+ // For now we assume that each module call produces only one module
+ // instance with no key, since we don't yet support "count" and "for_each"
+ // on modules.
+ // FIXME: As part of supporting "count" and "for_each" on modules, rework
+ // this so that we'll "expand" the module call first and then create graph
+ // nodes for each module instance separately.
+ instPath := config.Path.UnkeyedInstanceShim()
- // Build the abstract resource. We have the config already so
- // we'll just pre-populate that.
+ for _, r := range module.ManagedResources {
+ addr := r.Addr().Absolute(instPath)
abstract := &NodeAbstractResource{
Addr: addr,
Config: r,
}
+ // Grab the address for this resource
var node dag.Vertex = abstract
if f := t.Concrete; f != nil {
node = f(abstract)