diff --git a/command/command_test.go b/command/command_test.go index 34d044292..6d571b1eb 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -2,6 +2,7 @@ package command import ( "bytes" + "io/ioutil" "path/filepath" "testing" @@ -27,6 +28,15 @@ func outputCommand(t *testing.T, m Meta) (string, string) { return out.String(), err.String() } +func testFixtureContent(n ...string) string { + path := filepath.Join(append([]string{fixturesDir}, n...)...) + b, err := ioutil.ReadFile(path) + if err != nil { + panic(err) + } + return string(b) +} + func testFixture(n ...string) string { paths := []string{fixturesDir} paths = append(paths, n...) diff --git a/command/inspect_test.go b/command/inspect_test.go index 50cf31b06..5fda6c0d1 100644 --- a/command/inspect_test.go +++ b/command/inspect_test.go @@ -153,6 +153,13 @@ Note: If your build names contain user variables or template functions such as 'timestamp', these are processed at build time, and therefore only show in their raw form here. `}, + { + []string{ + "inspect", filepath.Join(testFixture("hcl-inspect-with-sensitive-vars")), + }, + nil, + testFixtureContent("hcl-inspect-with-sensitive-vars", "expected-output.txt"), + }, } for _, tc := range tc { diff --git a/command/test-fixtures/hcl-inspect-with-sensitive-vars/expected-output.txt b/command/test-fixtures/hcl-inspect-with-sensitive-vars/expected-output.txt new file mode 100644 index 000000000..3d13bb4ac --- /dev/null +++ b/command/test-fixtures/hcl-inspect-with-sensitive-vars/expected-output.txt @@ -0,0 +1,16 @@ +Packer Inspect: HCL2 mode + +> input-variables: + +var.not_sensitive: "I am soooo not sensitive" +var.not_sensitive_unknown: "" +var.sensitive: "" +var.sensitive_array: "[\n \"\",\n \"\",\n]" +var.sensitive_tags: "{\n \"first_key\" = \"\"\n \"second_key\" = \"\"\n}" +var.sensitive_unknown: "" + +> local-variables: + + +> builds: + diff --git a/command/test-fixtures/hcl-inspect-with-sensitive-vars/vars.pkr.hcl b/command/test-fixtures/hcl-inspect-with-sensitive-vars/vars.pkr.hcl new file mode 100644 index 000000000..e3bd983c7 --- /dev/null +++ b/command/test-fixtures/hcl-inspect-with-sensitive-vars/vars.pkr.hcl @@ -0,0 +1,29 @@ + +variable "not_sensitive" { + default = "I am soooo not sensitive" +} + +variable "not_sensitive_unknown" { +} + +variable "sensitive" { + default = "I am soooo sensitive" + sensitive = true +} + +variable "sensitive_array" { + default = ["Im supersensitive", "me too !!!!"] + sensitive = true +} + +variable "sensitive_tags" { + default = { + first_key = "this-is-mega-sensitive" + second_key = "this-is-also-sensitive" + } + sensitive = true +} + +variable "sensitive_unknown" { + sensitive = true +}