-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
terraform test: Collect variables from default var file within testin…
…g directory (#34341) * Add logic to collect variables for terrafrom test * Add tests for test variable collection * Update the test variable collection implementation * Update internal/backend/local/test.go Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com> * Update internal/backend/local/test.go Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com> * Move test variables into var file * resolve diff from cross-branch switch * go fmt --------- Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
- Loading branch information
1 parent
41435f8
commit c98e355
Showing
8 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
variable "foo" { | ||
description = "This is test variable" | ||
default = "def_value" | ||
} | ||
|
||
variable "fooJSON" { | ||
description = "This is test variable" | ||
default = "def_value" | ||
} | ||
|
||
output "out_foo" { | ||
value = var.foo | ||
} | ||
|
||
output "out_fooJSON" { | ||
value = var.fooJSON | ||
} |
13 changes: 13 additions & 0 deletions
13
internal/command/testdata/test/tfvars_in_test_dir/tests/main.tftest.hcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
run "primary" { | ||
assert { | ||
condition = var.foo == var.test_foo | ||
error_message = "Expected: ${var.test_foo}, Actual: ${var.foo}" | ||
} | ||
} | ||
|
||
run "secondary" { | ||
assert { | ||
condition = var.fooJSON == var.test_foo_json | ||
error_message = "Expected: ${var.test_foo_json}, Actual: ${var.fooJSON}" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
internal/command/testdata/test/tfvars_in_test_dir/tests/terraform.tfvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
foo = "foo_tfvars_value" | ||
test_foo = "foo_tfvars_value" | ||
test_foo_json = "foo_json_tfvars_value" |
3 changes: 3 additions & 0 deletions
3
internal/command/testdata/test/tfvars_in_test_dir/tests/terraform.tfvars.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"fooJSON": "foo_json_tfvars_value" | ||
} |