Commit graph

206 commits

Author SHA1 Message Date
Samsondeen
a1332299a5
Test run Parallelism of 1 should not result in deadlock (#37292) 2025-07-07 09:44:32 +02:00
Sarah French
b3d7dae793
Add config parsing and validation for PSS (#37178)
* Enable parsing of  blocks in individual files

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>

* Enable handling of state stores when parsing a module from its constituent files.

This includes: validations of duplicates and clashes, supporting override files.

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>

* Add tests for validation that detects conflicts between state_store blocks and others

* Add tests for state_store override behavior

* Add tests for validation that detects when conflicting state-related blocks are used, either in the same file or across separate files

* Update error message summaries to explicitly say blocks conflict

* Add small changes to assertions in state_store override tests

* Update state_store block parsing to expect scoped provider block

* Update tests following syntax change

* Make config parsing experimental

* Remove testModuleFromDirWithExperiment, as testModuleFromDirWithExperiments exists!

* Update code comment

---------

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
Co-authored-by: Radek Simko <radek.simko@gmail.com>
2025-06-09 18:43:02 +01:00
Liam Cervante
777a916435
terraform test: move providers into the graph (#37216)
* terraform test: move providers into the graph

* consistency checks

* remove flaky cycle test

* address comments

* Update internal/moduletest/graph/node_test_run.go

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

* go fmt

---------

Co-authored-by: Samsondeen <40821565+dsa0x@users.noreply.github.com>
2025-06-06 16:27:34 +02:00
Liam Cervante
53afa2cd2f
terraform test: move variable evaluation into the terraform test graph (#37205)
* terraform test: move variable evaluation into the terraform test graph

* make copyrightfix
2025-06-06 10:11:35 +02:00
Liam Cervante
063b7cf62b
terraform test: check specific dependencies before skipping run blocks (#37204)
* terraform test: check specific dependencies before skipping run blocks

* fix data race

* complete comment
2025-06-05 10:44:04 +00:00
Liam Cervante
757efaed9a
terraform test: automatically create edges based on references (#37200)
* terraform test: automatically create edges based on references

* address comments

* remove unused function
2025-06-03 14:33:43 +02:00
Liam Cervante
f80762d3d5
terraform test: add variable definitions to test files (#37195)
* terraform test: add variable definitions to test files

Currently, `terraform test` attempts to work out the type of any external variables by delaying evaluation until each run block executes so it can use the definitions within the run blocks's module. This means that the values of variables can technically change between run blocks which isn't ideal.

This commit is the first in a chain which will move the evaluation of variables into the terraform test graph. We need to give the users the option of specifying the type for external variables within the file as these variables are now going to be assessed outside of the context of a run block. To do this, we introduce the optional variable blocks that are added by this commit.

* update comment
2025-06-03 07:47:12 +00:00
Sarah French
884fc64618
Remove unused test fixture "push-backend-new" (#36842) 2025-04-03 17:21:02 +01:00
Liam Cervante
7fadbe34de
write-only attributes: internal providers should set write-only attributes to null (#36824)
* write-only attributes: internal providers should set write-only attributes to null

* add changelog

* fix copywrite headers
2025-04-02 15:58:42 +02:00
Samsondeen
595cd80666
CLI command for listing state identities (#36705) 2025-03-18 18:13:06 +01:00
Liam Cervante
aaf617d6d7
Add test case to ensure no regression of already fixed crash (#36583) 2025-03-05 11:24:53 +01:00
Samsondeen
3f4ed7e019
Ensure that all states are cleaned up (#36616) 2025-03-04 10:49:39 +01:00
Samsondeen
1bd312f155
Produce detailed diagnostic objects when test run assertions fail (#36522) 2025-03-03 15:46:04 +01:00
James Bardin
332bce3531 diagnostics should not contain URLs
Especially if they are not permanent. Remove the URL and update the
wording/quoting to better match existing style.
2025-02-28 13:02:43 -05:00
Samsondeen
018110c012
No state to cleaup when it is empty (#36526) 2025-02-18 19:33:41 +01:00
Samsondeen
2e91113224
Terraform test: Consolidate test execution procedure (#36459) 2025-02-11 14:48:48 +01:00
Samsondeen
4161e88391
Continue test execution after an expected failure (#36447) 2025-02-10 12:34:17 +01:00
Samsondeen
7f29df96a0
Allow terraform init when only test files are present in directory (#36429) 2025-02-06 09:20:09 +01:00
Radek Simko
70a1fd5e98
Fix diagnostic & avoid variable override via environment (#36435)
* add changie entry

* add test

* Fix diagnostic & avoid variable override via environment
2025-02-05 17:27:15 +00:00
Samsondeen
2f0f537e69
Terraform test: Execute eligible test runs in parallel (#36300) 2025-02-05 15:18:38 +01:00
Sarah French
6b81f7184c
Change JUnit terraform test output to include test failure details inside <failure> elements, use the error message as the message attribute (#36316)
* Add details to `<failure>` element describing which assertion failed

* Remove unused diagnostic string

* Set `message` attribute of `<failure>` element to failed assertion's error message

* Make `<failure>` contain diagnostic's message, refactor how `message` attribute is set

* Ensure that system-err is only added when needed

* Update test fixtures

* Make diags usage clearer, ensure all test failure diags in "failure" element

* Refactor how "skipped" element value is set

* Fix failing test Test_TestJUnitXMLFile_Save
2025-01-22 16:42:04 +00:00
Kévin Andrieux
258f91ab0c
feat: add state_key for test run blocks (#36185)
* feat: add state_alias for test run blocks

* fix: move `state_alias` to run block + rename to `state_key`

* docs: add state_key changelog entry

* docs: add state_key in run block documentation

* Revert "docs: add state_key in run block documentation"

This reverts commit ccccf62a76.

* Revert "docs: add state_key changelog entry"

This reverts commit 86e2ad8dc3.
2025-01-16 10:34:47 +01:00
Liam Cervante
408f323efa
test: also allow mock_data and mock_resource blocks to generate data during planning (#36317) 2025-01-15 08:19:05 +01: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
Samsondeen
aec7c3cc89
terraform test: allow computed/mocked values override during planning (#36227) 2025-01-08 12:39:03 +01:00
Mark DeCrane
e6bd282963
Merge pull request #36062 from hashicorp/TF-19313/modules-cmd-human-view
`terraform modules` cmd human view
2024-12-16 10:34:25 -05:00
Samsondeen
aa38305344
Merge pull request #36186 from hashicorp/sams/skip-graph-cycle-validation
Skip graph cycle validation when using the graph command
2024-12-11 17:32:02 +01:00
Samsondeen Dare
77c362b414 Skip graph cycle validation when using the graph command 2024-12-10 13:45:14 +01:00
James Bardin
c128eaa092 don't validate apply variables from auto files
The CLI attempts to prevent the user from inputting non-ephemeral
variables during apply which don't match the stored plan values. Since
the user can't avoid variables parsed from auto-loaded files, we have to
ignore those values.
2024-12-09 12:13:08 -05:00
James Bardin
4883499a89 test non-string env var input variables
Non-string input variables taken from the environment initially need to
be parsed and stored as string, since there is no type associated type
information. Make sure these are correctly handled when validated during
apply.
2024-11-27 13:16:33 -05:00
Mark DeCrane
b2a90cf587 Testing updates 2024-11-21 12:54:29 -05:00
Daniel Schmidt
2e026dec0f
ephemeral: set ephemeral variables for combined plans as well
they are by definition the same as in the plan, but there is no reason to skip the validation step
2024-11-06 14:20:02 +01:00
Sebastian Rivera
a5294c2096 Impl tests for the modules command 2024-10-28 13:31:09 -04:00
Bruno Schaatsbergen
098234e244
states: check root output value changes in refresh-only mode (#35812)
* check root output values when determining plan applicability in refresh mode

In refresh-only mode, we do not anticipate proposing any actions; however, a plan is marked as “applyable” if there are changes in the state between runs. Currently, a plan is considered “applyable” only when there are differences in managed resources. This approach seems to overlook changes in root output values. As a result, a plan can be marked as non-applyable, even when there are changes in the root output value, due to the lack of detected changes since only managed resources were checked.

* set 'applyable' to true
2024-10-23 15:27:53 +02:00
Daniel Schmidt
725add6a1a
test: pass in variables during apply
ephemeral variables need to be re-supplied
2024-10-16 16:30:31 +02:00
makx
2a9a8c2aca
show deprecation warning if -state is used with plan, apply, refresh (#35660)
* show deprecation warning if -state is used with plan, apply, refresh

* show deprecation warning if -state is used with plan, apply, refresh

* updated -state flag check condition

* added better diagnostic details view

* resolved failed test

* updated the content of the -state flag warning
2024-09-05 10:55:37 +02:00
kmoe
fab3673f8d
lang: stabilise ephemeral values experiment (#35636)
* lang: stabilise ephemeral values experiment

Stabilise the ephemeral values experiment and ephemeralasnull
experimental function.

* simplify handling of apply time input vars

As the final step in stabilising the ephemeral values experiment, we can
remove the separate code path for handling input variables supplied via
-var and -var-file during apply.

The intent here is conveyed in the tests: when applying a saved plan,
all ephemeral variables set in the plan (the "apply-time
variables"), must be set, and no others.

As per the TODO copied from the prototype, there is some more work to be
done here in making the handling of undeclared variables during apply as
sophisticated as that during plan, emitting helpful warnings (for
example) when input variables are supplied unnecessarily via environment
variables.

* experiments: officially conclude EV experiment

---------

Co-authored-by: Radek Simko <radek.simko@gmail.com>
2024-08-26 11:43:16 +01:00
Liam Cervante
4f62fcac53
init: fix invalid + duplicate required provider blocks crashing (#35533) 2024-08-06 10:38:13 +02:00
MicahKimel
3258744166
Remove invalid warning during cleanup phase (#35172)
* stop invalid warning during cleanup phase

* stop invalid warning during cleanup phase

* invalid warning during cleanup phase

* remove unwanted comment

* update GetVariables parameter for including warnings

* invalid warning during cleanup phase test case

* update invalid warnings in cleanup test case to throw a warning for the validation variable before cleanup phase

* remove unwanted warnings
2024-05-23 10:32:39 +02:00
Liam Cervante
48fc2d3ac7
terraform test: Disallow version constraints within test files (#35161) 2024-05-16 13:15:20 +02:00
Nick Fagerlund
40b6f21b3d
Merge pull request #35050 from hashicorp/rebrand-hcp-terraform
Rebrand Terraform Cloud to HCP Terraform
2024-04-23 13:27:52 -07:00
Sebastian Rivera
015f795ff0 Rebrand Terraform Cloud to HCP Terraform 2024-04-23 16:12:59 -04:00
Liam Cervante
448775102c
terraform test: Push evaluation of variables to as late as possible (#35014)
* terraform test: Push evaluation of variables to as late as possible

* Update internal/moduletest/hcl/variable_cache.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* address comments

---------

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2024-04-23 13:10:41 +02:00
Liam Cervante
6963c54bec
terraform test: don't remove sensitive marks from inputs (#35021) 2024-04-18 18:58:19 +02:00
UKEME BASSEY
7fb13b8868 fixing tests 2024-04-17 12:26:23 -04:00
UKEME BASSEY
c7bbc09631 move all command args from command/init to args/init 2024-04-17 12:26:23 -04:00
UKEME BASSEY
0ea25e3b40 fixing tests internal/command/init, view and argumento 2024-04-17 12:26:23 -04:00
UKEME BASSEY
26f01d699a add test for -json support 2024-04-17 12:26:23 -04:00
Liam Cervante
c6ff573180
Include provider functions in scope used to evaluate test assertions (#34825) 2024-03-13 13:26:12 +01:00
Daniel Schmidt
0529299cc3
run terraform fmt on test 2024-02-23 13:50:46 +01:00
Daniel Schmidt
7ae7a203d8
test: allow using global variables in suite-level variable definitions
Closes #34534
2024-02-20 16:40:30 +01:00
Martin Atkins
884e1fb2a4 terraform: Plans can be "complete" and "applyable"
These ideas are both already implied by some logic elsewhere in the system,
but until now we didn't have the decision logic centralized in a single
place that could therefore evolve over time without necessarily always
updating every caller together.

We'll now have the modules runtime produce its own boolean ruling about
each characteristic, which callers can rely on for the mechanical
decision-making of whether to offer the user an "approve" prompt, and
whether to remind the user after apply that it was an incomplete plan
that will probably therefore need at least one more plan/apply round to
converge.

The "Applyable" flag directly replaces the previous method Plan.CanApply,
with equivalent logic. Making this a field instead of a method means that
we can freeze it as part of a saved plan, rather than recalculating it
when we reload the plan, and we can export the field value in our export
formats like JSON while ensuring it'll always be consistent with what
Terraform is using internally.

Callers can (and should) still use other context in the plan to return
more tailored messages for specific situations they already know about
that might be useful to users, but with these flags as a baseline callers
can now just fall back to a generic presentation when encountering a
situation they don't yet understand, rather than making the wrong decision
and causing something strange to happen. That is: a lack of awareness of
a new rule will now cause just a generic message in the UI, rather than
incorrect behavior.

This commit mostly just deals with populating the flags, and then all of
the direct consequences of that on our various tests. Further changes to
actually make use of these flags elsewhere in the system will follow in
later commits, both in this repository and in other repositories.
2024-02-09 09:24:27 -08:00
HenriBlacksmith
49663bfc33
terraform fmt: add .tfmock.hcl as a supported file extension (#34580)
* terraform fmt: add .tfmock.hcl as a supported file extension

* terraform fmt: add test cases for .tfmock.hcl files formatting

* fix: update test to run on .tfmock.hcl files
2024-01-29 17:03:31 +01:00
James Bardin
c4a2f74054
Merge pull request #34567 from hashicorp/jbardin/handling-instance-value-marks
apply schema marks to returned instance values
2024-01-24 15:13:20 -05:00
James Bardin
8994e914b7 add sensitive attributes to test json output 2024-01-24 14:21:29 -05:00
James Bardin
8655b08b19 fix sensitive_attributes in test
Add the missing sensitive_attributes to the test state, and update the
output to reflect the new `"checks"` attribute name.
2024-01-24 14:17:50 -05:00
Liam Cervante
9658f9df6b
mocking overrides: default to concrete empty object when values are missing (#34563) 2024-01-24 12:39:58 +01:00
Liam Cervante
430970c02b
terraform test: Fix crash when file level variables reference variables. (#34531)
* terraform test: Fix crash when referencing variables within the file level variable block

* also allow functions within variables blocks

* add tests
2024-01-22 20:00:22 +01:00
Liam Cervante
7e18b1183d
Add test verifying issue #34476 has been fixed (#34478) 2024-01-05 17:05:17 +01:00
Liam Cervante
5cbf7c5f96
Add docs for automatic var files in test directories (#34349) 2023-12-06 08:10:45 +01: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
9ea1aa0a86
terraform test: skip destroy step for empty run blocks (#34331) 2023-11-30 16:38:23 +01:00
Liam Cervante
6670ab43f7
terraform test: rearrange the order of destroy operations (#34293) 2023-11-29 16:37:52 +01:00
Martin Atkins
844b1616e8 command/graph: Simpler resource-only graph by default
Unless a user specifically requests a real operation graph using the
-type option, we'll by default present a simplified graph which only
represents the relationships between resources, since resources are the
main side-effects and so the ordering of these is more interesting than
the ordering of Terraform's internal implementation details.
2023-11-28 13:48:48 -08:00
Liam Cervante
dedb296773
terraform test: connect mock behaviour to test framework (#34205)
* connect mock behaviour to test framework

* fix calling unconfigured providers
2023-11-14 08:50:37 +01:00
Liam Cervante
57edb9c248
testing framework: add warnings for override blocks with invalid targets (#34181)
* testing framework: add warnings for override blocks with invalid targets

* pre-add the override sources for upcoming features

* address comments
2023-11-13 10:36:06 +01:00
Liam Cervante
b9f6b23ba3
testing framework: add support for functions in variables and providers (#34204) 2023-11-13 09:25:32 +01:00
Liam Cervante
ad77877136
terraform test: remove marks before passing variables as inputs to a plan (#34190)
* remove marks before passing variables as inputs to a plan

* fix doc comments
2023-11-08 09:34:04 +01:00
Liam Cervante
f90d71f723
testing framework: allow providers to reference run blocks (#34118)
* testing framework: allow providers to reference run block

* missing copywrite header
2023-11-08 09:21:20 +01:00
Liam Cervante
5bbdc4c3b6
terraform test: allow providers in test files to reference variables (#34069)
* Process only relevant variables in the testing framework

* add support for variables within test provider configurations

* remove unused function

* fix consistency checks
2023-10-16 16:57:20 +02:00
Liam Cervante
01c0480e77
Test framework will produce regular updates in -json mode (#33953)
* Test framework will produce regular updates in -json mode

* add tests

* docs

* docs tweaking
2023-10-02 09:14:20 +02:00
James Bardin
2664c062c9
Merge pull request #33932 from hashicorp/jbardin/import-for-each
Import block expansion with for_each
2023-09-29 09:47:52 -04:00
Liam Cervante
fba5dad097
Test files should be marked as skipped if all their run blocks were skipped (#33950) 2023-09-28 13:49:14 +02:00
James Bardin
2c4608fe9e update import validate test
The diagnostics have been made more accurate, pointing to the
problematic line rather than just the import block name.
2023-09-26 11:37:35 -04:00
Liam Cervante
f8d4664bcd
Add additional validation around unknown and null values in test variables (#33861)
* Add additional validation around unknown values in test variables

* address comments
2023-09-14 09:44:21 +02:00
Liam Cervante
1c7dfa22b7 Add warning when testing and combining expect_failures with apply operations 2023-09-14 08:47:07 +02:00
Liam Cervante
84e2ebc225 apply defaults when processing variables for assertions 2023-09-14 08:32:25 +02:00
Liam Cervante
041b54fb4b
explicitely disallow duplicate run block names in test files (#33836) 2023-09-09 08:05:37 +02:00
Liam Cervante
a560730376
Make the test command fail if resources could not be cleaned up (#33809)
* Make the test command fail if resources could not be cleaned up

* remove redundant return statement
2023-09-08 19:57:23 +02:00
Liam Cervante
802d49a9ca
Handle null outputs in Terraform test files (#33781) 2023-09-01 16:53:23 +02:00
Liam Cervante
5e63aa01c7
Allow referencing higher level variables from run blocks (#33722) 2023-08-24 16:15:22 +02:00
Brandon Croft
114f876f81
Merge pull request #33602 from hashicorp/TF-8071-download-and-verify-the-plugin-in-terraform
Download and authenticate the cloudplugin
2023-08-18 07:08:33 -06: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
Brandon Croft
63e017b81b
cloudplugin: download and verify plugin
Adds a client that encapsulates the process of downloading a cloudplugin manifest from a Terraform Cloud, downloads the appropriate binary to the specified location, and validates that it was distributed by HashiCorp
2023-08-14 14:07:20 -06:00
Liam Cervante
126f34e4e8 Implement updates to testing framework based on recent feedback 2023-08-10 10:49:01 +02:00
Liam Cervante
3cce200d0e Fix root cause of race condition in testing framework tests 2023-08-09 16:47:59 +02:00
Liam Cervante
f8b1fe47dd
Make config errors more important during init operations (#33628)
* make config errors more important during init operations

* address comments
2023-08-09 11:19:00 +02:00
Liam Cervante
8b764f2e1b
fix race condition in no_provides_in_main test (#33616) 2023-08-02 11:02:26 +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
f397954c52
testing framework: allow users to specify deeply nested testing directories (#33584) 2023-07-27 10:38:21 +02:00
Liam Cervante
4122ba86fc
terraform test: fix crash when using nested modules from test run blocks (#33589) 2023-07-27 10:22:53 +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
55792309eb
test framework: add support for testing files to fmt command (#33576) 2023-07-26 10:38:47 +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
c91f91cc9e
testing framework: change test file extension to .tftest.hcl (#33553) 2023-07-20 16:57:05 +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
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