terraform/internal/command/testdata/test
Liam Cervante 551ba2e525
Implement controlling destroy functionality within Terraform Test (#37359)
* Add ability to parse backend blocks present in a test file's run blocks, validate configuration (#36541)

* Add ability to parse backend blocks from a run block

* Add validation to avoid multiple backend blocks across run blocks that use the same internal state file. Update tests.

* Add validation to avoid multiple backend blocks within a single run block. Update tests.

* Remove use of quotes in diagnostic messages

* Add validation to avoid backend blocks being used in plan run blocks. Update tests.

* Correct local backend blocks in new test fixtures

* Add test to show that different test files can use same backend block for same state key.

* Add validation to enforce state-storage backend types are used

* Remove TODO comment

We only need to consider one file at a time when checking if a state_key already has a backend associated with it; parallelism in `terraform test` is scoped down to individual files.

* Add validation to assert that the backend block must be in the first apply command for an internal state

* Consolidate backend block validation inside a single if statement

* Add initial version of validation that ensures a backend isn't re-used within a file

* Explicitly set the state_key at the point of parsing the config

TODO: What should be done with method (moduletest.Run).GetStateKey?

* Update test fixture now that reusing backend configs has been made invalid

* Add automated test showing validation of reused configuration blocks

* Skip test due to flakiness, minor change to test config naming

* Update test so it tolerates non-deterministic order run blocks are evaluated in

* Remove unnecessary value assignment to r.StateKey

* Replace use of GetStateKey() with accessing the state key that's now set during test config parsing

* Fix bug so that run blocks using child modules get the correct state key set at parsing time

* Update acceptance test to also cover scenario where root and child module state keys are in use

* Update test name

* Add newline to regex

* Ensure consistent place where repeat backend error is raised from

* Write leftover test state(s) to file (#36614)

* Add additional validation that the backend used in a run is a supported type (#36648)

* Prevent test run when leftover state data is present (#36685)

* `test`: Set the initial state for a state files from a backend, allow the run that defines a backend to write state to the backend (#36646)

* Allow use of backend block to set initial state for a state key

* Note about alternative place to keep 'backend factories'

* Allow the run block defining the backend to write state to it

* Fix rebase

* Change to accessing backend init functions via ContextOpts

* Add tests demonstrating how runs containing backend blocks use and update persisted state

* Fix test fixture

* Address test failure due to trouble opening the state file

This problem doesn't happen on MacOS, so I assume is due to the Linux environment of GitHub runners.

* Fix issue with paths properly

I hope

* Fix defect in test assertion

* Pivot back to approach introduced in 4afc3d7

* Let failing tests write to persistent state, add test case covering that.

I split the acceptance tests into happy/unhappy paths for this, which required some of the helper functions' declarations to be raised up to package-level.

* Change how we update internal state files, so that information about the associated backend is never lost

* Fix UpdateStateFile

* Ensure that the states map set by TestStateTransformer associates a backend with the correct run.

* Misc spelling fixes in comments and a log

* Replace state get/set functions with existing helpers (#36747)

* Replace state get/set functions with existing helpers

* Compare to string representation of state

* Compare to string representation of state

* Terraform Test: Allow skipping cleanup of entire test file or individual run blocks (#36729)

* Add validation to enforce skip_cleanup=false cannot be used with backend blocks (#36857)

* Integrate use of backend blocks in tests with skip_cleanup feature (#36848)

* Fix nil pointer error, update test to not be table-driven

* Make using a backend block implicitly set skip_cleanup to true

* Stop state artefacts being created when a backend is in use and no cleanup errors have occurred

* Return diagnostics so calling code knows if cleanup experienced issues or not

* Update tests to show that when cleanup fails a state artefact is created

* Add comment about why diag not returned

* Bug fix - actually pull in the state from the state manager!

* Split and simplify (?) tests to show the backend block can create and/or reuse prior state

* Update test to use new fixtures, assert about state artefact. Fix nil pointer

* Update test fixture in use, add guardrail for flakiness of forced error during cleanup

* Refactor so resource ID set in only one place

* Add documentation for using a `backend` block during `test` (#36832)

* Add backend as a documented block in a run block

* Add documentation about backend blocks in run blocks.

* Make the relationship between backends and state keys more clear, other improvements

* More test documentation (#36838)

* Terraform Test: cleanup command (#36847)

* Allow cleanup of states that depend on prior runs outputs (#36902)

* terraform test: refactor graph edge calculation

* create fake run block nodes during cleanup operation

* tidy up TODOs

* fix tests

* remove old changes

* Update internal/moduletest/graph/node_state_cleanup.go

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

* Improve diagnostics around skip_cleanup conflicts (#37385)

* Improve diagnostics around skip_cleanup conflicts

* remove unused dynamic node

* terraform test: refactor manifest file for simplicity (#37412)

* test: refactor apply and plan functions so no run block is needed

* terraform test: write and load state manifest files

* Terraform Test: Allow skipping cleanup of entire test file or individual run blocks (#36729)

* terraform test: add support for skip_cleanup attr

* terraform test: add cleanup command

* terraform test: add backend blocks

* pause

* fix tests

* remove commented code

* terraform test: make controlling destroy functionality experimental (#37419)

* address comments

* Update internal/moduletest/graph/node_state_cleanup.go

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

---------

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>

* add experimental changelog entries

---------

Co-authored-by: Sarah French <15078782+SarahFrench@users.noreply.github.com>
Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>
Co-authored-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
2025-09-10 17:22:20 +02:00
..
backend-with-skip-cleanup Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
bad-references terraform test: automatically create edges based on references (#37200) 2025-06-03 14:33:43 +02:00
cleanup Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
complex_condition Produce detailed diagnostic objects when test run assertions fail (#36522) 2025-03-03 15:46:04 +01:00
custom_condition_checks testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
custom_condition_inputs testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
custom_condition_outputs testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
custom_condition_resources testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
dangling_data_block terraform test: rearrange the order of destroy operations (#34293) 2023-11-29 16:37:52 +01:00
default_optional_values apply defaults when processing variables for assertions 2023-09-14 08:32:25 +02:00
default_variables test framework: expand variables available to test assertions (#33611) 2023-08-01 09:59:29 +02:00
deferred_changes terraform test: enable deferrals in Terraform Test with the specified flag (#37370) 2025-07-30 11:03:41 +02:00
destroy_fail Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
empty_module_with_output Add test verifying issue #34476 has been fixed (#34478) 2024-01-05 17:05:17 +01:00
env-vars terraform test: Push evaluation of variables to as late as possible (#35014) 2024-04-23 13:10:41 +02:00
env-vars-in-module terraform test: Push evaluation of variables to as late as possible (#35014) 2024-04-23 13:10:41 +02:00
ephemeral_input test: pass in variables during apply 2024-10-16 16:30:31 +02:00
ephemeral_input_with_error test: pass in variables during apply 2024-10-16 16:30:31 +02:00
ephemeral_resource test: pass in variables during apply 2024-10-16 16:30:31 +02:00
expect-failures-assertions test: don't panic when resolving references that haven't been evaluated (#37484) 2025-08-26 09:20:37 +02:00
expect_failures_checks testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
expect_failures_during_apply Continue test execution after an expected failure (#36447) 2025-02-10 12:34:17 +01:00
expect_failures_inputs Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
expect_failures_outputs Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
expect_failures_resources Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
expected_failures_during_planning Continue test execution after an expected failure (#36447) 2025-02-10 12:34:17 +01:00
functions_available terraform test: Fix crash when file level variables reference variables. (#34531) 2024-01-22 20:00:22 +01:00
global_var_ref_in_suite_var run terraform fmt on test 2024-02-23 13:50:46 +01:00
global_var_refs terraform test: Fix crash when file level variables reference variables. (#34531) 2024-01-22 20:00:22 +01:00
invalid testing framework: validate the configuration before terraform test (#33559) 2023-07-26 10:56:44 +02:00
invalid-cleanup-warnings Remove invalid warning during cleanup phase (#35172) 2024-05-23 10:32:39 +02:00
invalid-module testing framework: validate the configuration before terraform test (#33559) 2023-07-26 10:56:44 +02:00
invalid-overrides testing framework: add warnings for override blocks with invalid targets (#34181) 2023-11-13 10:36:06 +01:00
invalid_config Terraform test: Consolidate test execution procedure (#36459) 2025-02-11 14:48:48 +01:00
invalid_default_state Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
junit-output Produce detailed diagnostic objects when test run assertions fail (#36522) 2025-03-03 15:46:04 +01:00
long_running Test framework will produce regular updates in -json mode (#33953) 2023-10-02 09:14:20 +02:00
missing-provider test framework: include transformed config before validating config (#33608) 2023-08-01 09:47:00 +02:00
missing-provider-definition-in-file Terraform test: Consolidate test execution procedure (#36459) 2025-02-11 14:48:48 +01:00
missing-provider-in-run-block test framework: include transformed config before validating config (#33608) 2023-08-01 09:47:00 +02:00
missing-provider-in-test-module test framework: include transformed config before validating config (#33608) 2023-08-01 09:47:00 +02:00
mocking test: also allow mock_data and mock_resource blocks to generate data during planning (#36317) 2025-01-15 08:19:05 +01:00
mocking-error terraform test: allow computed/mocked values override during planning (#36227) 2025-01-08 12:39:03 +01:00
mocking-invalid terraform test: allow computed/mocked values override during planning (#36227) 2025-01-08 12:39:03 +01:00
multiple_files testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
nested_unknown_values Add additional validation around unknown and null values in test variables (#33861) 2023-09-14 09:44:21 +02:00
no-tests terraform test: fix regression when running with no tests (#37475) (#37477) 2025-08-26 08:37:14 +02:00
no_providers_in_main Fix root cause of race condition in testing framework tests 2023-08-09 16:47:59 +02:00
no_state No state to cleaup when it is empty (#36526) 2025-02-18 19:33:41 +01:00
non-existent-backend-type Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
null-outputs Handle null outputs in Terraform test files (#33781) 2023-09-01 16:53:23 +02:00
null_value_in_assert Add additional validation around unknown and null values in test variables (#33861) 2023-09-14 09:44:21 +02:00
null_value_in_vars Add additional validation around unknown and null values in test variables (#33861) 2023-09-14 09:44:21 +02:00
only_modules Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
parallel Terraform test: Execute eligible test runs in parallel (#36300) 2025-02-05 15:18:38 +01:00
parallel-errors terraform test: check specific dependencies before skipping run blocks (#37204) 2025-06-05 10:44:04 +00:00
parallel_divided Terraform test: Consolidate test execution procedure (#36459) 2025-02-11 14:48:48 +01:00
partial_updates Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
pass_with_locals testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
pass_with_outputs testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
pass_with_variables explicitely disallow duplicate run block names in test files (#33836) 2023-09-09 08:05:37 +02:00
plan_then_apply explicitely disallow duplicate run block names in test files (#33836) 2023-09-09 08:05:37 +02:00
prevent-destroy terraform test: override prevent_destroy meta attribute (#37364) 2025-07-25 13:54:56 +02:00
provider-functions-available Include provider functions in scope used to evaluate test assertions (#34825) 2024-03-13 13:26:12 +01:00
provider_runs testing framework: allow providers to reference run blocks (#34118) 2023-11-08 09:21:20 +01:00
provider_runs_invalid terraform test: move providers into the graph (#37216) 2025-06-06 16:27:34 +02:00
provider_vars terraform test: allow providers in test files to reference variables (#34069) 2023-10-16 16:57:20 +02:00
rds_shared_subnet test: create all edges to leaf cleanup nodes (#37564) 2025-09-09 11:20:56 +02:00
removed-backend-type Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
reused-backend-config Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
reused-backend-config-child-modules Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
sensitive_input_values Produce detailed diagnostic objects when test run assertions fail (#36522) 2025-03-03 15:46:04 +01:00
shared_state Terraform test: Execute eligible test runs in parallel (#36300) 2025-02-05 15:18:38 +01:00
shared_state_object Introduce 'run' keyword for referencing outputs from earlier run blocks (#33683) 2023-08-16 11:06:00 +02:00
simple_fail testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
simple_pass testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
simple_pass_count Test run Parallelism of 1 should not result in deadlock (#37292) 2025-07-07 09:44:32 +02:00
simple_pass_nested testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
simple_pass_nested_alternate testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
simple_pass_very_nested testing framework: allow users to specify deeply nested testing directories (#33584) 2023-07-27 10:38:21 +02:00
skip_cleanup Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
skip_cleanup_simple Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
skip_cleanup_with_run_deps Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
skip_destroy_on_empty terraform test: skip destroy step for empty run blocks (#34331) 2023-11-30 16:38:23 +01:00
skip_file_cleanup Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
state_propagation Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
tfvars_in_test_dir Add docs for automatic var files in test directories (#34349) 2023-12-06 08:10:45 +01:00
top-dir-only-nested-test-files Allow terraform init when only test files are present in directory (#36429) 2025-02-06 09:20:09 +01:00
top-dir-only-test-files Allow terraform init when only test files are present in directory (#36429) 2025-02-06 09:20:09 +01:00
unapplyable-plan Add test case to ensure no regression of already fixed crash (#36583) 2025-03-05 11:24:53 +01:00
undefined_variables test framework: expand variables available to test assertions (#33611) 2023-08-01 09:59:29 +02:00
unknown_value_in_assert Add additional validation around unknown and null values in test variables (#33861) 2023-09-14 09:44:21 +02:00
unknown_value_in_vars Add additional validation around unknown and null values in test variables (#33861) 2023-09-14 09:44:21 +02:00
valid-use-local-backend Implement controlling destroy functionality within Terraform Test (#37359) 2025-09-10 17:22:20 +02:00
variable_references terraform test: move variable evaluation into the terraform test graph (#37205) 2025-06-06 10:11:35 +02:00
variables testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
variables_types Allow referencing higher level variables from run blocks (#33722) 2023-08-24 16:15:22 +02:00
variables_undefined_in_config terraform test: allow providers in test files to reference variables (#34069) 2023-10-16 16:57:20 +02:00
with-default-variables terraform test: move variable evaluation into the terraform test graph (#37205) 2025-06-06 10:11:35 +02:00
with_double_interrupt testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
with_interrupt testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
with_interrupt_and_additional_file Test files should be marked as skipped if all their run blocks were skipped (#33950) 2023-09-28 13:49:14 +02:00
with_nested_setup_modules terraform test: fix crash when using nested modules from test run blocks (#33589) 2023-07-27 10:22:53 +02:00
with_provider_alias testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
with_setup_module testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
with_state_key feat: add state_key for test run blocks (#36185) 2025-01-16 10:34:47 +01:00
write-into-default-state terraform test: refactor graph edge calculation (#37357) 2025-07-23 16:09:45 +02:00
write-only-attributes write-only attributes: internal providers should set write-only attributes to null (#36824) 2025-04-02 15:58:42 +02:00
write-only-attributes-mocked write-only attributes: internal providers should set write-only attributes to null (#36824) 2025-04-02 15:58:42 +02:00
write-only-attributes-overridden write-only attributes: internal providers should set write-only attributes to null (#36824) 2025-04-02 15:58:42 +02:00