From 203a5651614ee9af4d8900ee67d530ab1bf025e2 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 18 Nov 2015 17:16:03 -0600 Subject: [PATCH 1/3] scripts: check for the correct env vars in dist.sh we need AWS keys now, not bintray keys --- scripts/dist.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/dist.sh b/scripts/dist.sh index 1488d1b71..a9b57cd87 100755 --- a/scripts/dist.sh +++ b/scripts/dist.sh @@ -9,8 +9,8 @@ if [ -z $VERSION ]; then fi # Make sure we have a bintray API key -if [ -z $BINTRAY_API_KEY ]; then - echo "Please set your bintray API key in the BINTRAY_API_KEY env var." +if [[ -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY ]]; then + echo "Please set AWS access keys as env vars before running this script." exit 1 fi From 6ae3218f8a5034796a33c16f018800d3ea180ad6 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Thu, 19 Nov 2015 16:06:30 +0200 Subject: [PATCH 2/3] Add failing tests for JSON configuration parsing Reproduces the issue reported by @svanharmelen in #3964. --- config/loader_test.go | 96 +++++++++++++++++++++++++ config/test-fixtures/attributes.tf | 15 ++++ config/test-fixtures/attributes.tf.json | 27 +++++++ 3 files changed, 138 insertions(+) create mode 100644 config/test-fixtures/attributes.tf create mode 100644 config/test-fixtures/attributes.tf.json diff --git a/config/loader_test.go b/config/loader_test.go index 18b26f9c5..bc1deb890 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -557,6 +557,102 @@ func TestLoad_temporary_files(t *testing.T) { } } +func TestLoad_hclAttributes(t *testing.T) { + c, err := LoadFile(filepath.Join(fixtureDir, "attributes.tf")) + if err != nil { + t.Fatalf("Bad: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + actual := resourcesStr(c.Resources) + print(actual) + if actual != strings.TrimSpace(jsonAttributeStr) { + t.Fatalf("bad:\n%s", actual) + } + + r := c.Resources[0] + if r.Name != "test" && r.Type != "cloudstack_firewall" { + t.Fatalf("Bad: %#v", r) + } + + raw := r.RawConfig + if raw.Raw["ipaddress"] != "192.168.0.1" { + t.Fatalf("Bad: %s", raw.Raw["ipAddress"]) + } + + rule := raw.Raw["rule"].([]map[string]interface{})[0] + if rule["protocol"] != "tcp" { + t.Fatalf("Bad: %s", rule["protocol"]) + } + + if rule["source_cidr"] != "10.0.0.0/8" { + t.Fatalf("Bad: %s", rule["source_cidr"]) + } + + ports := rule["ports"].([]interface{}) + + if ports[0] != "80" { + t.Fatalf("Bad ports: %s", ports[0]) + } + if ports[1] != "1000-2000" { + t.Fatalf("Bad ports: %s", ports[1]) + } +} + +func TestLoad_jsonAttributes(t *testing.T) { + c, err := LoadFile(filepath.Join(fixtureDir, "attributes.tf.json")) + if err != nil { + t.Fatalf("Bad: %s", err) + } + + if c == nil { + t.Fatal("config should not be nil") + } + + actual := resourcesStr(c.Resources) + print(actual) + if actual != strings.TrimSpace(jsonAttributeStr) { + t.Fatalf("bad:\n%s", actual) + } + + r := c.Resources[0] + if r.Name != "test" && r.Type != "cloudstack_firewall" { + t.Fatalf("Bad: %#v", r) + } + + raw := r.RawConfig + if raw.Raw["ipaddress"] != "192.168.0.1" { + t.Fatalf("Bad: %s", raw.Raw["ipAddress"]) + } + + rule := raw.Raw["rule"].([]map[string]interface{})[0] + if rule["protocol"] != "tcp" { + t.Fatalf("Bad: %s", rule["protocol"]) + } + + if rule["source_cidr"] != "10.0.0.0/8" { + t.Fatalf("Bad: %s", rule["source_cidr"]) + } + + ports := rule["ports"].([]interface{}) + + if ports[0] != "80" { + t.Fatalf("Bad ports: %s", ports[0]) + } + if ports[1] != "1000-2000" { + t.Fatalf("Bad ports: %s", ports[1]) + } +} + +const jsonAttributeStr = ` +cloudstack_firewall[test] (x1) + ipaddress + rule +` + const heredocProvidersStr = ` aws access_key diff --git a/config/test-fixtures/attributes.tf b/config/test-fixtures/attributes.tf new file mode 100644 index 000000000..2fe0291e0 --- /dev/null +++ b/config/test-fixtures/attributes.tf @@ -0,0 +1,15 @@ +provider "cloudstack" { + api_url = "bla" + api_key = "bla" + secret_key = "bla" +} + +resource "cloudstack_firewall" "test" { + ipaddress = "192.168.0.1" + + rule { + source_cidr = "10.0.0.0/8" + protocol = "tcp" + ports = ["80", "1000-2000"] + } +} diff --git a/config/test-fixtures/attributes.tf.json b/config/test-fixtures/attributes.tf.json new file mode 100644 index 000000000..773274d48 --- /dev/null +++ b/config/test-fixtures/attributes.tf.json @@ -0,0 +1,27 @@ +{ + "provider": { + "cloudstack": { + "api_url": "bla", + "api_key": "bla", + "secret_key": "bla" + } + }, + "resource": { + "cloudstack_firewall": { + "test": { + "ipaddress": "192.168.0.1", + "rule": [ + { + "source_cidr": "10.0.0.0/8", + "protocol": "tcp", + "ports": [ + "80", + "1000-2000" + ] + } + ] + } + } + } +} + From 15e79270098062666f4305ed267bfda8e6a2e7e4 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Thu, 19 Nov 2015 09:31:33 -0600 Subject: [PATCH 3/3] 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 18b26f9c5..5be023cb1 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 000000000..4fe9a020b --- /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)}" +}