terraform: Interpolate if there are any interpolations [GH-159]
This commit is contained in:
parent
cdc2a53553
commit
da2e221628
|
@ -35,6 +35,7 @@ BUG FIXES:
|
||||||
* core: The `file()` function can load files in sub-directories. [GH-213]
|
* core: The `file()` function can load files in sub-directories. [GH-213]
|
||||||
* core: Fix issue where some JSON structures didn't map properly into
|
* core: Fix issue where some JSON structures didn't map properly into
|
||||||
Terraform structures. [GH-177]
|
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: Fix issues around failing to read EIPs. [GH-122]
|
||||||
* providers/aws: Autoscaling groups now register and export load
|
* providers/aws: Autoscaling groups now register and export load
|
||||||
balancers. [GH-207]
|
balancers. [GH-207]
|
||||||
|
|
|
@ -25,6 +25,7 @@ const UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66"
|
||||||
// information from deep within the structure.
|
// information from deep within the structure.
|
||||||
type RawConfig struct {
|
type RawConfig struct {
|
||||||
Raw map[string]interface{}
|
Raw map[string]interface{}
|
||||||
|
Interpolations []Interpolation
|
||||||
Variables map[string]InterpolatedVariable
|
Variables map[string]InterpolatedVariable
|
||||||
|
|
||||||
config map[string]interface{}
|
config map[string]interface{}
|
||||||
|
@ -87,9 +88,12 @@ func (r *RawConfig) Interpolate(vs map[string]string) error {
|
||||||
|
|
||||||
func (r *RawConfig) init() error {
|
func (r *RawConfig) init() error {
|
||||||
r.config = r.Raw
|
r.config = r.Raw
|
||||||
|
r.Interpolations = nil
|
||||||
r.Variables = nil
|
r.Variables = nil
|
||||||
|
|
||||||
fn := func(i Interpolation) (string, error) {
|
fn := func(i Interpolation) (string, error) {
|
||||||
|
r.Interpolations = append(r.Interpolations, i)
|
||||||
|
|
||||||
for k, v := range i.Variables() {
|
for k, v := range i.Variables() {
|
||||||
if r.Variables == nil {
|
if r.Variables == nil {
|
||||||
r.Variables = make(map[string]InterpolatedVariable)
|
r.Variables = make(map[string]InterpolatedVariable)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
func TestNewRawConfig(t *testing.T) {
|
func TestNewRawConfig(t *testing.T) {
|
||||||
raw := map[string]interface{}{
|
raw := map[string]interface{}{
|
||||||
"foo": "${var.bar}",
|
"foo": "${var.bar}",
|
||||||
|
"bar": `${file("boom.txt")}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, err := NewRawConfig(raw)
|
rc, err := NewRawConfig(raw)
|
||||||
|
@ -16,6 +17,9 @@ func TestNewRawConfig(t *testing.T) {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(rc.Interpolations) != 2 {
|
||||||
|
t.Fatalf("bad: %#v", rc.Interpolations)
|
||||||
|
}
|
||||||
if len(rc.Variables) != 1 {
|
if len(rc.Variables) != 1 {
|
||||||
t.Fatalf("bad: %#v", rc.Variables)
|
t.Fatalf("bad: %#v", rc.Variables)
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,11 +305,6 @@ func (c *Context) computeVars(raw *config.RawConfig) error {
|
||||||
return nil
|
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
|
// Start building up the variables. First, defaults
|
||||||
vs := make(map[string]string)
|
vs := make(map[string]string)
|
||||||
for k, v := range c.defaultVars {
|
for k, v := range c.defaultVars {
|
||||||
|
|
Loading…
Reference in New Issue