Commit graph

73 commits

Author SHA1 Message Date
Daniel Schmidt
8faccde780 implement centralized variable collection 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
Daniel Schmidt
90eae782bf move vars handling into own file 2026-02-18 12:47:12 +01:00
Daniel Schmidt
81b328f924
update copyright headers 2026-02-17 15:56:24 +01:00
Daniel Schmidt
592d0fe4dd
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
5e51b831be
refactor state-replace-provider command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
32fb18572d
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
89bea5de5b
refactor state-rm command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
c66d0d72c1
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
442126553b
refactor state-push command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
b9f6f14003
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
9f3c282096
refactor state-mv command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
52bbc57c62
refactor state-pull command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
acb6ed3f22
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
f7cde006ff
refactor state-show command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
da74b59ea1
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
3dbfbe5dc9
refactor state-list command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
af7783eb62
refactor providers lock command argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
c7729926fa
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:45 +01:00
Daniel Schmidt
0066780049
refactor providers mirror command argument parsing 2026-02-17 15:55:36 +01:00
Daniel Schmidt
c15f0409ed
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:36 +01:00
Daniel Schmidt
0c384e8cd8
refactor providers schema command argument parsing 2026-02-17 15:55:36 +01:00
Daniel Schmidt
6f32f249f7
refactor providers command argument parsing 2026-02-17 15:55:36 +01:00
Daniel Schmidt
3a2686938f
use the arguments package for import command 2026-02-17 15:55:36 +01:00
Daniel Schmidt
61923826f8
don't explicitly specify defaults in argument parsing 2026-02-17 15:55:36 +01:00
Daniel Schmidt
5a9c0196d9
let command handle defaults 2026-02-17 15:55:36 +01:00
Daniel Schmidt
6b83486498
use the arguments package for taint commands 2026-02-17 15:55:36 +01:00
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Sarah French
f2818db795
PSS : Add fs and inmem state storage implementations to the builtin simplev6 provider, update grpcwrap package, use PSS implementation in E2E test (#37790)
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
* feat: Implement `inmem` state store in provider-simple-v6
* feat: Add filesystem state store `fs` in provider-simple-v6, no locking implemented
* refactor: Move PSS chunking-related constants into the `pluggable` package, so they can be reused.
* feat: Implement PSS-related methods in grpcwrap package
* test: Add E2E test checking an init and apply (no plan) workflow is usable with both PSS implementations
* fix: Ensure state stores are configured with a suggested chunk size from Core

---------

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
2025-11-11 15:30:50 +00:00
Sarah French
6b73f710f8
PSS: Implement initialisation of new working directory (or use of -reconfigure flag) while using state_store (#37732)
* Minor fixes in diagnostics

This can only be done once modules have been parsed and the required providers data is available. There are multiple places where config is parsed, into either Config or Module structs, so this needs to be implemented in multiple places.

* Rename test to make it specific to use of backend block in config

* Update initBackend to accept whole initArgs collection

* Only process --backend-config data, when setting up a `backend`, if that data isn't empty

* Simplify how mock provider factories are made in tests

* Update mock provider's default logic to track and manage existing workspaces

* Add `ProviderSchema` method to `Pluggable` structs. This allows calling code to access the provider schema when using provider configuration data.

* Add function for converting a providerreqs.Version to a hashicorp/go-version Version.

This is needed for using locks when creating the backend state file.

* Implement initial version of init new working directories using `stateStore_C_s`. Default to creating the default workspace if no workspaces exist.

* Update test fixtures to match the hashicorp/test mock provider used in PSS tests

* Allow tests to obtain locks that include `testingOverrides` providers.

The `testingOverrides` field will only be set in tests, so this should not impact end users.

* Add tests showing TF can initialize a working directory for the first time (and do the same when forced by -reconfigure flag). Remove replaced tests.

* Add -create-default-workspace flag, to be used to disable creating the default workspace by default when -input=false (i.e for use in CI). Refactor creation of default workspace logic. Add tests.

* Allow reattached providers to be used during init for PSS

* Rename variable to `backendHash` so relation to `backend` is clearer

* Allow `(m *Meta) Backend` to return warning diagnostics

* Protect against nil testingOverrides in providerFactoriesFromLocks

* Add test case seeing what happens if default workspace selected, doesn't exist, but other workspaces do exist.

The consequences here are due to using `selectWorkspace` in `stateStore_C_s`, matching what's done in `backend_C_r_s`.

* Address code consistency check failure on PR

* Refactor use of mock in test that's experiencing EOF error...

* Remove test that requires test to supply input for user prompt

This test passes when run in isolation but fails when run alongside other tests, even when skipping all other tests using `testStdinPipe`. I don't think the value of this test is great enough to start changing how we test stdin input.

* Allow -create-default-workspace to be used regardless of whether input is enabled or disabled

* Add TF_SKIP_CREATE_DEFAULT_WORKSPACE environment variable

* Responses to feedback, including making testStdinPipe helper log details of errors copying data to stdin.

Note: We cannot call t.Fatal from a non-test goroutine.

* Use Errorf instead

* Allow backend state files to not include version data when a builtin or reattached provider is in use.

* Add clarifying comment about re-attached providers when finding the matching entry in required_providers

* Report that the default workspace was created to the view

* Refactor: use error comparison via `errors.Is` to identify when no workspaces exist.

* Move handling of TF_ENABLE_PLUGGABLE_STATE_STORAGE into init's ParseInit func.

* Validate that PSS-related flags can only be used when experiments are enabled, enforce coupling of PSS-related flags when in use.

* Slight rewording of output message about default workspace

* Update test to assert new output about default workspace
2025-10-15 10:44:21 +01:00
Samsondeen
2274026c68
query: add -query flag to validate command (#37671) 2025-10-01 11:33:52 +02: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
5124967f5a
actions: allow skipping refresh when invoking actions (#37541)
* actions: add invoke graph nodes

* fix small bugs

* add additional tests

* remove whitespace

* actions: invoke rendered actions

* also fix up apply message

* make description headers consistent

* fix copyright headers

* actions: allow skipping refresh when invoking actions

* go generate
2025-09-01 09:04:11 +00:00
Liam Cervante
b0ff7c271c
Revert "actions: allow skipping refresh when invoking actions (#37523)" (#37539)
This reverts commit d39fcc4f0b.
2025-09-01 08:54:23 +00:00
Liam Cervante
d39fcc4f0b
actions: allow skipping refresh when invoking actions (#37523)
* actions: add invoke graph nodes

* fix small bugs

* add additional tests

* remove whitespace

* actions: invoke rendered actions

* also fix up apply message

* make description headers consistent

* fix copyright headers

* actions: allow skipping refresh when invoking actions

* go generate
2025-08-29 13:08:02 +00:00
Liam Cervante
866363ffff
actions: add invoke nodes to the graph (#37521)
* actions: add invoke graph nodes

* fix small bugs

* add additional tests

* remove whitespace

* fix copyright headers

* go generate

* address comments
2025-08-29 14:43:09 +02:00
Liam Cervante
e854d8364d
actions: add invoke flag for plan and apply commands (#37512)
* actions: make action address targetable

* add missing functions

* copyright headers

* actions: add invoke flag for plan and apply commands
2025-08-28 12:11:52 +00:00
Sarah French
f494ff5540
Pull init command's Run method logic into separate method in new file, enable accessing experimental version of init logic via experiments and flags or ENVs (#37327)
* Pull `init` `Run` method into new method in a separate file, in preparation for adding experimental fork.

* Add license header

* Allow init args to be accessed before calling separate init run logic

* Add -enable-pss flag to the init command, to be used for accessing experimental init logic

* Fix- put call to `run` in else block!

* Make flag name more explicit

* Add an environment variable alternative to the CLI flag

* Make the panic text more user-friendly

* go fmt
2025-07-30 19:11:33 +01: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
Daniel Banck
2b9d25c7fd
Add terraform query subcommand (TF-25494) (#37174)
* WIP

* Reuse plan command for query CLI

* Basic CLI output

* Only fail a list request on error

* poc: store query results in separate field

* WIP: odd mixture between JSONs

* Fix list references

* Separate JSON rendering

The structured JSON now only logs a status on which list query is
currently running. The new jsonlist package can marshal the query fields
of a plan.

* Remove matcher

* Store results in an extra struct

* Structured list result logging

* Move list result output into hooks

* Add help text and additional flag

* Disable query runs with the cloud backend for now

* Review feedback
2025-07-02 15:06:25 +02: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
Sarah French
85b482e05a
Add testing helpers that allow comparing diagnostics, refactor existing tests to use them. (#36456)
* Add testing helpers for comparing diagnostics with different levels of stringency

* Refactor some existing tests to use the new helpers

* Replace use of diag comparison test helpers in terraform package

* Add header

* Add return statement back in ephemeral test

* Update internal/terraform/context_plan2_test.go
2025-02-19 13:59:29 +00:00
Samsondeen
86295f518c
Don't set default parallelism for cloud runs (#36441) 2025-02-06 08:54:08 +01: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
b16a50973f
Add reusable Diagnostic comparer to tfdiags package (#36385)
* Add `DiagnosticComparer` to standardize how diagnostics are compared for equality. This uses code originally in the s3 backend.

Co-authored-by: Graham Davison <gdavison@hashicorp.com>

* Refactor `test` related code to use new comparer

* Refactor `s3` related code to use new comparer

* Replace use of reflect and go-spew with new diagnostics comparison approach

* Fix whitespace

* Make `tfdiags.DiagnosticComparer` a var

* Fix DiagnosticComparer test

---------

Co-authored-by: Graham Davison <gdavison@hashicorp.com>
2025-01-22 17:44:16 +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
Sebastian Rivera
a5294c2096 Impl tests for the modules command 2024-10-28 13:31:09 -04:00
Sebastian Rivera
ee1a2a7858 Implement the modules command
The modules command provides a holistic view of all installed modules
for a given root module. It also includes information on whether a
installed module is currently referenced by configuration. As of now,
this command only supports a machine-readable view format.
2024-10-28 13:31:09 -04: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