config: change module syntax

This commit is contained in:
Mitchell Hashimoto 2014-09-14 14:43:54 -07:00
parent 5e4c2b4f49
commit 8dc8eac4bf
4 changed files with 35 additions and 43 deletions

View File

@ -32,7 +32,6 @@ type Config struct {
// call-site within an existing configuration.
type Module struct {
Name string
Type string
Source string
RawConfig *RawConfig
}
@ -106,7 +105,7 @@ func ProviderConfigName(t string, pcs []*ProviderConfig) string {
// A unique identifier for this module.
func (r *Module) Id() string {
return fmt.Sprintf("%s.%s", r.Type, r.Name)
return fmt.Sprintf("module.%s", r.Name)
}
// A unique identifier for this resource.
@ -318,7 +317,6 @@ func (m *Module) mergerMerge(other merger) merger {
result := *m
result.Name = m2.Name
result.Type = m2.Type
result.RawConfig = result.RawConfig.merge(m2.RawConfig)
if m2.Source != "" {

View File

@ -194,7 +194,7 @@ func loadFileHcl(root string) (configurable, []string, error) {
// represents exactly one module definition in the HCL configuration.
// We leave it up to another pass to merge them together.
func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
var allTypes []*hclobj.Object
var allNames []*hclobj.Object
// See loadResourcesHcl for why this exists. Don't touch this.
for _, o1 := range os.Elem(false) {
@ -202,7 +202,7 @@ func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
for _, o2 := range o1.Elem(true) {
// Iterate all of this type to get _all_ the types
for _, o3 := range o2.Elem(false) {
allTypes = append(allTypes, o3)
allNames = append(allNames, o3)
}
}
}
@ -212,15 +212,13 @@ func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
// Now go over all the types and their children in order to get
// all of the actual resources.
for _, t := range allTypes {
for _, obj := range t.Elem(true) {
for _, obj := range allNames {
k := obj.Key
var config map[string]interface{}
if err := hcl.DecodeObject(&config, obj); err != nil {
return nil, fmt.Errorf(
"Error reading config for %s[%s]: %s",
t.Key,
"Error reading config for %s: %s",
k,
err)
}
@ -231,8 +229,7 @@ func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
rawConfig, err := NewRawConfig(config)
if err != nil {
return nil, fmt.Errorf(
"Error reading config for %s[%s]: %s",
t.Key,
"Error reading config for %s: %s",
k,
err)
}
@ -243,8 +240,7 @@ func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
err = hcl.DecodeObject(&source, o)
if err != nil {
return nil, fmt.Errorf(
"Error parsing source for %s[%s]: %s",
t.Key,
"Error parsing source for %s: %s",
k,
err)
}
@ -252,12 +248,10 @@ func loadModulesHcl(os *hclobj.Object) ([]*Module, error) {
result = append(result, &Module{
Name: k,
Type: t.Key,
Source: source,
RawConfig: rawConfig,
})
}
}
return result, nil
}

View File

@ -663,7 +663,7 @@ foo
`
const modulesModulesStr = `
foo.bar
module.bar
source = baz
memory
`

View File

@ -1,4 +1,4 @@
module "foo" "bar" {
module "bar" {
memory = "1G"
source = "baz"
}