Repository: cloud-custodian/tfparse (language: python)

Issue:
multiple var files issue
support for multiple var files in https://github.com/cloud-custodian/tfparse/pull/136 didn't actually test multiple var files, and is incorrectly calling the parser options, which takes an array of strings, instead it was passed a single string in a loop, stomping over the previous values.


Discussion / hints:

Fix patch:
diff --git a/gotfparse/cmd/tfparse/main.go b/gotfparse/cmd/tfparse/main.go
index 822ab9b..bd64e49 100644
--- a/gotfparse/cmd/tfparse/main.go
+++ b/gotfparse/cmd/tfparse/main.go
@@ -30,8 +30,12 @@ func Parse(a *C.char, stopHCL C.int, debug C.int, allowDownloads C.int, num_vars
 		options = append(options, converter.WithAllowDownloads())
 	}
 
+	var varFiles []string
 	for _, v := range unsafe.Slice(vars_files, num_vars_files) {
-		options = append(options, converter.WithTFVarsPaths(C.GoString(v)))
+		varFiles = append(varFiles, C.GoString(v))
+	}
+	if len(varFiles) != 0 {
+		options = append(options, converter.WithTFVarsPaths(varFiles...))
 	}
 
 	tfd, err := converter.NewTerraformConverter(input, options...)
diff --git a/setup.py b/setup.py
index 9c6e4ca..ac3f59e 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@
     maintainer="Cloud Custodian Project",
     maintainer_email="cloud-custodian@googlegroups.com",
     license="Apache-2.0",
-    version="0.6.1",
+    version="0.6.2",
     classifiers=[
         "Development Status :: 3 - Alpha",
         "Intended Audience :: Developers",


Test patch:
diff --git a/tests/test_tfparse.py b/tests/test_tfparse.py
index f2834dd..5d3ac35 100644
--- a/tests/test_tfparse.py
+++ b/tests/test_tfparse.py
@@ -46,6 +46,30 @@ def test_vars(tmp_path):
     assert item["content"] == "goodbye"
 
 
+def test_multiple_var_files(tmp_path):
+    (tmp_path / "main.tf").write_text(
+        """
+        variable "abc" {
+          type = string
+        }
+        variable "def" {
+          type = string
+        }
+
+        resource aws_cloudwatch_log_group "bing" {
+          name = "${var.abc}-${var.def}-logs"
+        }
+        """
+    )
+    (tmp_path / "var1.tfvars").write_text('abc = "my"')
+    (tmp_path / "var2.tfvars").write_text('def = "app"')
+    parsed = load_from_path(
+        tmp_path, vars_paths=["var1.tfvars", "var2.tfvars"], debug=True
+    )
+    item = parsed["aws_cloudwatch_log_group"].pop()
+    assert item["name"] == "my-app-logs"
+
+
 def test_parse_vpc_module(tmp_path):
     mod_path = init_module("vpc_module", tmp_path, run_init=False)
     parsed = load_from_path(mod_path, allow_downloads=True)