terraform: Interpolate if there are any interpolations [GH-159]

This commit is contained in:
Mitchell Hashimoto 2014-08-21 15:05:56 -07:00
parent cdc2a53553
commit da2e221628
4 changed files with 9 additions and 5 deletions

View File

@ -35,6 +35,7 @@ BUG FIXES:
* core: The `file()` function can load files in sub-directories. [GH-213]
* core: Fix issue where some JSON structures didn't map properly into
Terraform structures. [GH-177]
* core: Resources with only `file()` calls will interpolate. [GH-159]
* providers/aws: Fix issues around failing to read EIPs. [GH-122]
* providers/aws: Autoscaling groups now register and export load
balancers. [GH-207]

View File

@ -25,6 +25,7 @@ const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66"
// information from deep within the structure.
type RawConfig struct {
Raw map[string]interface{}
Interpolations []Interpolation
Variables map[string]InterpolatedVariable
config map[string]interface{}
@ -87,9 +88,12 @@ func (r *RawConfig) Interpolate(vs map[string]string) error {
func (r *RawConfig) init() error {
r.config = r.Raw
r.Interpolations = nil
r.Variables = nil
fn := func(i Interpolation) (string, error) {
r.Interpolations = append(r.Interpolations, i)
for k, v := range i.Variables() {
if r.Variables == nil {
r.Variables = make(map[string]InterpolatedVariable)

View File

@ -9,6 +9,7 @@ import (
func TestNewRawConfig(t *testing.T) {
raw := map[string]interface{}{
"foo": "${var.bar}",
"bar": `${file("boom.txt")}`,
}
rc, err := NewRawConfig(raw)
@ -16,6 +17,9 @@ func TestNewRawConfig(t *testing.T) {
t.Fatalf("err: %s", err)
}
if len(rc.Interpolations) != 2 {
t.Fatalf("bad: %#v", rc.Interpolations)
}
if len(rc.Variables) != 1 {
t.Fatalf("bad: %#v", rc.Variables)
}

View File

@ -305,11 +305,6 @@ func (c *Context) computeVars(raw *config.RawConfig) error {
return nil
}
// If there are on variables, then we're done
if len(raw.Variables) == 0 {
return nil
}
// Start building up the variables. First, defaults
vs := make(map[string]string)
for k, v := range c.defaultVars {