From 91a3405e88131d41e1df14ccb1e3fc0bd7bd4572 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 16 Jan 2015 10:14:48 -0800 Subject: [PATCH] config: understand provisioner blocks in JSON [GH-807] --- CHANGELOG.md | 1 + config/loader_hcl.go | 10 +++++++++- config/loader_test.go | 8 ++++++++ config/test-fixtures/basic.tf | 10 ++++++++++ config/test-fixtures/basic.tf.json | 16 +++++++++++++++- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c9114332..17298cae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ BUG FIXES: * core: Escape characters `\"`, `\n`, and `\\` now work in interpolations. * core: Fix crash that could occur when there are exactly zero providers installed on a system. [GH-786] + * core: JSON TF configurations can configure provisioners. [GH-807] * provider/aws: ELB subnet change doesn't force new resource. [GH-804] PLUGIN CHANGES: diff --git a/config/loader_hcl.go b/config/loader_hcl.go index 10e178c1e..6c127ea8b 100644 --- a/config/loader_hcl.go +++ b/config/loader_hcl.go @@ -517,7 +517,15 @@ func loadProvisionersHcl(os *hclobj.Object, connInfo map[string]interface{}) ([] // for _, o1 := range os.Elem(false) { for _, o2 := range o1.Elem(true) { - pos = append(pos, o2) + + switch o1.Type { + case hclobj.ValueTypeList: + for _, o3 := range o2.Elem(true) { + pos = append(pos, o3) + } + case hclobj.ValueTypeObject: + pos = append(pos, o2) + } } } diff --git a/config/loader_test.go b/config/loader_test.go index e43b5a256..39fea0296 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -410,6 +410,10 @@ const basicResourcesStr = ` aws_instance[db] (x1) VPC security_groups + provisioners + file + destination + source dependsOn aws_instance.web vars @@ -418,6 +422,10 @@ aws_instance[web] (x1) ami network_interface security_groups + provisioners + file + destination + source vars resource: aws_security_group.firewall.foo user: var.foo diff --git a/config/test-fixtures/basic.tf b/config/test-fixtures/basic.tf index d271e2323..5751a8583 100644 --- a/config/test-fixtures/basic.tf +++ b/config/test-fixtures/basic.tf @@ -27,6 +27,11 @@ resource aws_instance "web" { device_index = 0 description = "Main network interface" } + + provisioner "file" { + source = "foo" + destination = "bar" + } } resource "aws_instance" "db" { @@ -34,6 +39,11 @@ resource "aws_instance" "db" { VPC = "foo" depends_on = ["aws_instance.web"] + + provisioner "file" { + source = "foo" + destination = "bar" + } } output "web_ip" { diff --git a/config/test-fixtures/basic.tf.json b/config/test-fixtures/basic.tf.json index 506e2a7b8..1b946e22b 100644 --- a/config/test-fixtures/basic.tf.json +++ b/config/test-fixtures/basic.tf.json @@ -22,7 +22,14 @@ "db": { "security_groups": ["${aws_security_group.firewall.*.id}"], "VPC": "foo", - "depends_on": ["aws_instance.web"] + "depends_on": ["aws_instance.web"], + + "provisioner": [{ + "file": { + "source": "foo", + "destination": "bar" + } + }] }, "web": { @@ -34,6 +41,13 @@ "network_interface": { "device_index": 0, "description": "Main network interface" + }, + + "provisioner": { + "file": { + "source": "foo", + "destination": "bar" + } } } },