Commit graph

58 commits

Author SHA1 Message Date
Daniel Schmidt
d4d46b38a2 remove unused Meta.variableArgs 2026-02-18 12:47:12 +01:00
Daniel Schmidt
4e921a8eae move CollectValuesFromTests to arguments package
This keeps the CollectValues and CollectValuesFromTests implementations
together.
2026-02-18 12:47:12 +01:00
Daniel Schmidt
1190b52995 use centralized arguments collection in test 2026-02-18 12:47:12 +01:00
Daniel Schmidt
026c935961 move UnparsedVariableValue from backendrun to arguments
This prevents a cyclic dependency and also makes sense semantically.
The arguments package will collect the unparsed variable values and
the backendrun helpers will work to collect the values and transform
them into terraform.InputValue.
2026-02-18 12:47:12 +01:00
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Sebastien Dionne
1047b5355c
Fix typos and linguistic errors in documentation (#37770)
Some checks are pending
build / Build for windows_amd64 (push) Blocked by required conditions
build / Build for freebsd_arm (push) Blocked by required conditions
build / Build for linux_arm (push) Blocked by required conditions
build / Build for darwin_arm64 (push) Blocked by required conditions
build / Build for linux_arm64 (push) Blocked by required conditions
build / Build for windows_arm64 (push) Blocked by required conditions
build / Build Docker image for linux_386 (push) Blocked by required conditions
build / Build Docker image for linux_amd64 (push) Blocked by required conditions
build / Build Docker image for linux_arm (push) Blocked by required conditions
build / Build Docker image for linux_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_386 (push) Blocked by required conditions
build / Build e2etest for windows_386 (push) Blocked by required conditions
build / Build e2etest for darwin_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_amd64 (push) Blocked by required conditions
build / Build e2etest for windows_amd64 (push) Blocked by required conditions
build / Build e2etest for linux_arm (push) Blocked by required conditions
build / Build e2etest for darwin_arm64 (push) Blocked by required conditions
build / Build e2etest for linux_arm64 (push) Blocked by required conditions
build / Run e2e test for linux_386 (push) Blocked by required conditions
build / Run e2e test for windows_386 (push) Blocked by required conditions
build / Run e2e test for darwin_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_amd64 (push) Blocked by required conditions
build / Run e2e test for windows_amd64 (push) Blocked by required conditions
build / Run e2e test for linux_arm (push) Blocked by required conditions
build / Run e2e test for linux_arm64 (push) Blocked by required conditions
build / Run terraform-exec test for linux amd64 (push) Blocked by required conditions
Quick Checks / Unit Tests (push) Waiting to run
Quick Checks / Race Tests (push) Waiting to run
Quick Checks / End-to-end Tests (push) Waiting to run
Quick Checks / Code Consistency Checks (push) Waiting to run
Signed-off-by: Sebastien Dionne <survivant00@gmail.com>
2025-10-14 10:38:27 +01:00
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
Liam Cervante
dec0edfd5a
terraform test: enable deferrals in Terraform Test with the specified flag (#37370) 2025-07-30 11:03:41 +02:00
Samsondeen
a1332299a5
Test run Parallelism of 1 should not result in deadlock (#37292) 2025-07-07 09:44:32 +02:00
Mattias Fjellström
3252fa8f42
Add missing JUnit XML flag to test command help string (#37161)
The test command supports outputting a JUnit XML file with the -junit-xml flag. This flag was missing from the test command help string.
2025-05-26 09:04:03 +02:00
Samsondeen
16a34fe47f
Accept CLI option for the number of parallel ops in a test run's plan/apply (#36323) 2025-02-05 09:48:05 +01:00
Sarah French
21cafd70ea
Add more details to JUnit terraform test output to describe why a test was skipped (#36315)
* Add ability for TestJUnitXMLFile to access data about whether the test runner was Stopped

* Add details to XML describing why a Run was skipped

* Fix wording

* Code consistency changes

* Move all JUnit-related code down to where it's used

Away from the Views section of the code where it was relevant before

* Move JUnit-related error and warning diags to above where cancellable contexts are created

* Fix wording of user feedback

* Fix test to match updated skipped message text

* Fix test
2025-01-16 12:12:15 +00:00
Sarah French
8e1d36681c
Promote JUnit output 'terraform test' feature from experimental status, make incompatibility with remote test execution explicit via flag validation (#36324)
* Promote JUnit reports for `terraform test` out of experimental status

* Make JUnit output explicitly for local execution only

* Refactor how local test runner is passed JUnit data

* Add change file

* Add test for incompatible flags
2025-01-15 11:44:35 +00:00
Sarah French
ab6e4f2299
Refactor JUnit XML output of terraform test into a new junit package (#36304)
* Refactor JUnit XML output to use new concept of an Artifact

* Move JUnit-related code into new `artifact` package

* Refactor Artifact's Save method to return diagnostics, update comments

Previously TestJUnitXMLFile implemented the View interface, which cannot return errors. Now it's not a View any more we can simplify things.

* Make junitXMLTestReport output deterministic by iterating over a slice instead of a map, add test

* Provide sources to junitXMLTestReport, allowing complete error messages in the XML

We need to ensure that artifact.NewTestJUnitXMLFile is called once the config Loader is available as a non-nil pointer

* Whitespace

* Add some test coverage for JUnit XML output for `terraform test`

* Refactor how file is saved, add tests

* Move XML structs definitions outside of `junitXMLTestReport`

* Fix nil pointer bug

* Add missing file headers

* Refactor comparison of byte slices

* Rename package to `junit`, rename structs to match

* Add a test showing JUnit output when a test is skipped by the user
2025-01-13 13:25:58 +00:00
James Bardin
3a1a9408d9 fix Descendants spelling
this has proliferated everywhere
2024-10-09 11:09:02 -04:00
Nate Douglas
df653772e1
Fix typo in test.go 2024-09-10 16:45:50 -04:00
Sebastian Rivera
015f795ff0 Rebrand Terraform Cloud to HCP Terraform 2024-04-23 16:12:59 -04:00
UKEME BASSEY
c7bbc09631 move all command args from command/init to args/init 2024-04-17 12:26:23 -04:00
Martin Atkins
b43ddd8ff6 terraform test: Experimental JUnit XML reporting
This adds an experimental new option -junit-xml=FILENAME for the
"terraform test" command. When specified, it writes a JUnit XML report to
the specified filename once the test run is complete, while continuing to
report test progress in the UI in the usual way.

This is only experimental for now because it remains to be seen if this
particular mapping to the JUnit XML schema is actually useful in real
software -- this format is woefully underdocumented and implemented
slightly differently by each consumer -- and so we might change this
significantly before stabilizing it, or remove it altogether if it turns
out that there's no useful mapping to JUnit XML here. Hopefully those who
are interested in JUnit XML reports will try this experiment against their
favorite JUnit XML-consuming software and report back whether the report
is presented in a helpful way.

It's a de-facto convention for JUnit XML to be reported separately to a
file, rather than replacing the normal test run output, since tools that
consume this format tend to present its results in a separate and less
prominent place than the output of the command itself. This option is
designed to follow that convention for consistency with various other
software that produces this format.

The implementation here is intentionally pretty minimal and simplistic just
as a starting point for gathering feedback. The main priority is that it
be easy to evolve this based on feedback and to remove it altogether if we
decide not to stabilize this at all. If this does become stabilized, it
might deserve being factored out into a separate package so that we can
minimize the amount of logic embedded directly inside the views package,
and it will certainly need some unit tests to represent what we've
committed to supporting in future versions.
2024-01-15 08:51:02 -08:00
Kubo
c98e355ca1
terraform test: Collect variables from default var file within testing 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>
2023-12-04 08:15:56 +01:00
Liam Cervante
8ecda5f708
Increase timeout length after fatal interrupts for test cloud runs (#33956) 2023-09-28 18:05:38 +02:00
Liam Cervante
ffbcaf8bef
Implement TFC integration for private module registry test runs (#33710)
* implement module testing via TFC

* ready for review

* fix static checks

* licence headers
2023-09-14 09:01:25 +02:00
Liam Cervante
4c83e2d524
Terraform test directory must be local to the config directory (#33760) 2023-08-29 11:45:31 +02:00
Liam Cervante
edcc35c96c
testing framework: move local implementation into local directory (#33734) 2023-08-28 10:48:13 +02:00
Jared Baker
c566bcd6f7
Merge pull request #33730 from hashicorp/s3/modernization
backend/s3: Update S3 client to AWS SDK Go V2
2023-08-24 19:49:48 -04:00
Liam Cervante
5e63aa01c7
Allow referencing higher level variables from run blocks (#33722) 2023-08-24 16:15:22 +02:00
Jared Baker
de02f3461b
internal/command: fix slices.SortFunc signature 2023-08-24 08:40:41 -04:00
CJ Horton
98b81d3c50 add missing copyright headers 2023-08-16 11:21:49 -07:00
Liam Cervante
9742f22c4e
Introduce 'run' keyword for referencing outputs from earlier run blocks (#33683)
* introduce 'run' keyword for referencing outputs from earlier run blocks

* fix code consistency
2023-08-16 11:06:00 +02:00
Liam Cervante
836c64f172
simplify test_context evaluation (#33677) 2023-08-15 11:00:18 +02:00
Liam Cervante
126f34e4e8 Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
Liam Cervante
3bea1171af
test framework: expand variables available to test assertions (#33611) 2023-08-01 09:59:29 +02:00
Liam Cervante
4560a83721
test framework: include transformed config before validating config (#33608) 2023-08-01 09:47:00 +02:00
Liam Cervante
e1019b3641
testing framework: validate the configuration before terraform test (#33559)
* testing framework: call validate on the configuration before running terraform test

* address comments

* make tests pass after merge

* fix tests
2023-07-26 10:56:44 +02:00
Liam Cervante
080ddead6e
testing framework: perform a plan before starting any tests (#33561) 2023-07-26 10:24:25 +02:00
Liam Cervante
083c9afd5b
testing framework: add trace and debug statements during test executions (#33554) 2023-07-26 10:11:27 +02:00
Liam Cervante
c91f91cc9e
testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +02:00
Liam Cervante
6c7db16566
testing framework: refactor interrupt logic for immediate exits (#33532)
* testing framework: refactor interrupt logic

* fix formatting
2023-07-19 10:31:32 +02:00
Liam Cervante
6882dd9530
testing framework: introduce test command optional flags (#33504)
* testing framework: introduce test command optional flags

* address consistency checks
2023-07-19 10:07:46 +02:00
Liam Cervante
2cc81cfec6
testing framework: implement panic handling (#33525) 2023-07-19 09:57:09 +02:00
Liam Cervante
837716a703
testing framework: finalise expect_failures functionality (#33506) 2023-07-19 09:44:40 +02:00
Liam Cervante
4862812c94
testing framework: introduce interrupts for stopping tests (#33477)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks

* [testing framework] allow tests to define and override providers

* testing framework: introduce interrupts for stopping tests

* remove panic handling, will do it properly later
2023-07-10 14:53:13 +01:00
Liam Cervante
4b34902fab
[testing framework] allow tests to define and override providers (#33466)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks

* [testing framework] allow tests to define and override providers
2023-07-10 14:33:15 +01:00
Liam Cervante
5acc95dda7
[Testing Framework] Add module block to test run blocks (#33456)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks
2023-07-10 11:42:05 +01:00
Liam Cervante
ea162f6ab5
[testing framework] prepare for beta phase of development (#33445) 2023-07-06 15:53:18 +02:00
Liam Cervante
2eb99a0e44
Fix the Terraform build after recent merges (#33436) 2023-06-28 10:12:43 +02:00
Liam Cervante
dfc26c2ac4
[Testing Framework] Add test command to Terraform CLI (#33327)
* Add test structure to views package for rendering test output

* Add test file HCL configuration and parser functionality

* Adds a TestContext structure for evaluating assertions against the state and plan

* Add test command to Terraform CLI
2023-06-28 09:37:42 +02:00
Liam Cervante
48c818927c Remove old implementation of terraform test command 2023-06-12 11:17:42 +02:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Alisdair McDiarmid
8df065a2fe initwd: Switch from earlyconfig to configs
This is a mostly mechanical refactor with a handful of changes which
are necessary due to the semantic difference between earlyconfig and
configs.

When parsing root and descendant modules in the module installer, we now
check the core version requirements inline. If the Terraform version is
incompatible, we drop any other module loader diagnostics. This ensures
that future language additions don't clutter the output and confuse the
user.

We also add two new checks during the module load process:

* Don't try to load a module with a `nil` source address. This is a
  necessary change due to the move away from earlyconfig.

* Don't try to load a module with a blank name (i.e. `module ""`).
  Because our module loading manifest uses the stringified module path
  as its map key, this causes a collision with the root module, and a
  later panic. This is the bug which triggered this refactor in the
  first place.
2023-03-06 09:14:28 -05:00