From 15e79270098062666f4305ed267bfda8e6a2e7e4 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 19 Nov 2015 09:31:33 -0600 Subject: [PATCH] config: test covering escaped quotes syntax error This was never intended to be valid syntax, but it worked in the old HCL parser, and we've found a decent number of examples of it in the wild. Fixed in https://github.com/hashicorp/hcl/pull/62 and we'll keep this test in Terraform to cover the behavior. --- config/loader_test.go | 27 +++++++++++++++++++++++++++ config/test-fixtures/escapedquotes.tf | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 config/test-fixtures/escapedquotes.tf diff --git a/config/loader_test.go b/config/loader_test.go index 18b26f9c53..5be023cb1b 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -70,6 +70,26 @@ func TestLoadFileHeredoc(t *testing.T) { } } +func TestLoadFileEscapedQuotes(t *testing.T) { + c, err := LoadFile(filepath.Join(fixtureDir, "escapedquotes.tf")) + if err != nil { + t.Fatalf("err: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + if c.Dir != "" { + t.Fatalf("bad: %#v", c.Dir) + } + + actual := resourcesStr(c.Resources) + if actual != strings.TrimSpace(escapedquotesResourcesStr) { + t.Fatalf("bad:\n%s", actual) + } +} + func TestLoadFileBasic(t *testing.T) { c, err := LoadFile(filepath.Join(fixtureDir, "basic.tf")) if err != nil { @@ -571,6 +591,13 @@ aws_iam_policy[policy] (x1) policy ` +const escapedquotesResourcesStr = ` +aws_instance[quotes] (x1) + ami + vars + user: var.ami +` + const basicOutputsStr = ` web_ip vars diff --git a/config/test-fixtures/escapedquotes.tf b/config/test-fixtures/escapedquotes.tf new file mode 100644 index 0000000000..4fe9a020bb --- /dev/null +++ b/config/test-fixtures/escapedquotes.tf @@ -0,0 +1,7 @@ +variable "ami" { + default = [ "ami", "abc123" ] +} + +resource "aws_instance" "quotes" { + ami = "${join(\",\", var.ami)}" +}