Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow escaped interpolation-like sequences in variable defaults #13137

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command/test-fixtures/validate-valid/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "var_with_escaped_interp" {
# This is here because in the past it failed. See Github #13001
default = "foo-$${bar.baz}"
}

resource "test_instance" "foo" {
ami = "bar"

Expand Down
11 changes: 9 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,15 @@ func (c *Config) Validate() error {
}

interp := false
fn := func(ast.Node) (interface{}, error) {
interp = true
fn := func(n ast.Node) (interface{}, error) {
// LiteralNode is a literal string (outside of a ${ ... } sequence).
// interpolationWalker skips most of these. but in particular it
// visits those that have escaped sequences (like $${foo}) as a
// signal that *some* processing is required on this string. For
// our purposes here though, this is fine and not an interpolation.
if _, ok := n.(*ast.LiteralNode); !ok {
interp = true
}
return "", nil
}

Expand Down
7 changes: 7 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,13 @@ func TestConfigValidate_varDefaultInterpolate(t *testing.T) {
}
}

func TestConfigValidate_varDefaultInterpolateEscaped(t *testing.T) {
c := testConfig(t, "validate-var-default-interpolate-escaped")
if err := c.Validate(); err != nil {
t.Fatalf("should be valid, but got err: %s", err)
}
}

func TestConfigValidate_varDup(t *testing.T) {
c := testConfig(t, "validate-var-dup")
if err := c.Validate(); err == nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "foo" {
# This should be considered valid since the sequence is escaped and is
# thus not actually an interpolation.
default = "foo bar $${aws_instance.foo.bar}"
}