Commit graph

1067 commits

Author SHA1 Message Date
Daniel Banck
1ac8497994
Add support for Terraform Search in the cloud backend (TF-25935) (#37479) 2025-09-15 13:21:05 +02:00
Samsondeen
8097374c3d
Fix panic when generating json config for tf query (#37596) 2025-09-12 14:46:48 +02:00
Sarah French
90809dc7e8
Skip TestTest_Parallel due to flakiness (#37594) 2025-09-11 13:57:06 +00: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
00d680d819
apply: include sensitive metadata when comparing changed input values (#37582)
* apply: include sensitive metadata when comparing changed input values

* correct changelog entry
2025-09-10 11:11:31 +02:00
Samsondeen
af8cc7e315
test: create all edges to leaf cleanup nodes (#37564) 2025-09-09 11:20:56 +02:00
Kristin Laemmert
cad076409c
Fix e2e tests on windows (#37572)
* close file explicitly (for windows)
* drop the config file in the tf.Path root
2025-09-08 12:25:26 -04:00
Kristin Laemmert
cf9c491d9f
fix minor regression in tests (#37570)
At one point, these tests were explicitly passing an empty cli config filepath so that terraform would ignore any existing cli config file (only relevant if you are running these tests locally), but the behavior changed over time such that it was no longer working for these tests (now if the env var file path is empty, we fall back to the default). The actual behavior is reasonably correct (I've depended on passing in blank config file paths before, so I don't love it, but I don't see a need to break this either) so I've added a small method that drops a blank file in place to fix the behavior and avoid file not found errors.
2025-09-08 10:36:16 -04:00
James Bardin
1cb7d1859f
Merge pull request #37515 from hashicorp/jbardin/generate-config
provider GenerateResourceConfig
2025-09-05 16:31:23 -04:00
Sarah French
8503c45013
Update backend.Backend's StateMgr method to return diagnostics instead of primitive errors (#37496)
* Fix S3 backend test affected by making the Workspaces method return errors via diagnostics

* Address diagnostics comparison issues in test by ensuring expected diagnostics are defined in the context of the config they're triggered by

* Fix failing test case `TestBackendConfig_EC2MetadataEndpoint/envvar_invalid_mode` by making `diagnosticBase` struct comparable

* Add compile-time checks that diagnostic types fulfil interfaces

* Stop diagnosticBase implementing ComparableDiagnostic, re-add S3-specific comparer code to s3 package

* Update tests to use the S3-specific comparer again

* Fix test case missed in refactoring

* Update the backend.Backend interface to use diagnostics as return value from StateMgr method

* Fix calls to `Fatalf`
2025-09-04 11:14:35 +01:00
Sarah French
61a7914dd9
Add test helper to create mock provider that contains a state store (#37556)
* Add a helper for mocking a provider with a state store

* Update tests to use the new helper

* Update other test fixtures for consistency

The related tests pass before and after this change

* Update testing helper to return the underlying type, not the interface
2025-09-04 10:51:49 +01:00
Daniel Schmidt
85717fba7e actions: add number of invoked actions to plan summary 2025-09-03 10:12:09 +02:00
Daniel Schmidt
ad4371342f track partial expanded action invocations through deferred action invocation
like we do it for resources just simpler because we don't have layered addrs maps
2025-09-02 13:04:48 +02:00
Daniel Schmidt
b2c4766d5e implement review feedback 2025-09-02 13:04:48 +02:00
Daniel Schmidt
dffeeec81e partially expand triggers as well 2025-09-02 13:04:48 +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
673717d01a
actions: render invoked actions (#37540)
* 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

* go generate
2025-09-01 09:01:48 +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
8488fbb35c
Revert "actions: render invoked actions (#37522)" (#37538)
This reverts commit 0fae555389.
2025-09-01 08:51:14 +00:00
James Bardin
4c610ac5e6 use the new genconfig types throughout 2025-08-29 15:11:56 -04:00
James Bardin
ddc47f15e7 remove the recursive genconfig resource struct
The Resource struct didn't really match the data structure. Refactor
this to make it easier to break up the config generation calls so we can
pass in final config from the provider.
2025-08-29 15:11:56 -04:00
Daniel Schmidt
176263d936 actions: remove future action types
removing them for now, this gives us more flexibility in the future since the schema is not yet locked in
2025-08-29 16:25:41 +02:00
Liam Cervante
e43eeaaf2e
actions: update JSON output to include invoked actions (#37527)
* actions: update JSON output to include invoked actions

* fix more tests
2025-08-29 15:43:34 +02:00
Sarah French
5be24bf1d0
Fix experimental gating of PSS feature (#37526)
* Stop `state_store` being parsed when experiments aren't enabled

* Update tests that show the feature is experimentally gated

* Refactor to use unparsed hcl.Block for diagnostics when experiments aren't enabled
2025-08-29 14:23:35 +01: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
0fae555389
actions: render invoked actions (#37522)
* 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

* go generate
2025-08-29 12:52:12 +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
Daniel Schmidt
8b65426ecf move action schemas out of experimental flag 2025-08-28 12:04:51 +02:00
Sarah French
f9b4f0a898
Update info for debugging why this test may fail (#37461) 2025-08-27 10:03:31 +01:00
Daniel Banck
2463f864dd
Exclude nested config block from list resource schemas (#37495)
* Exclude nested config block from list resource schemas

* Guard action schemas by experimental flag

* Fix tests
2025-08-26 13:17:27 -04:00
Sarah French
b11b54e142
Add code comment to make in-progress migration from Ui to View more obvious (#37492) 2025-08-26 13:40:25 +00:00
Liam Cervante
f931bc4e0e
test: don't panic when resolving references that haven't been evaluated (#37484) 2025-08-26 09:20:37 +02:00
Ricard Bejarano
4ac49bad2b
terraform test: fix regression when running with no tests (#37475) (#37477)
* terraform test: fix regression when running with no tests (#37475)

* added changelog entry

* move changelog entry from v1.14 to v1.13

* Return moduletest.Error instead of suite.Status if test operation is cancelled

* Add "terraform test" test with no tests

Yes, that's right. It's OK if you need to read it again.
2025-08-26 08:37:14 +02:00
Daniel Schmidt
3b12eb0866 actions: serialize trigger event in hooks 2025-08-25 15:01:31 +02:00
Daniel Schmidt
47994b5542 don't omit action lifecycle indexes 2025-08-25 15:01:31 +02:00
Daniel Schmidt
871d3ce64f support sensitive values in action configuration 2025-08-25 15:00:34 +02:00
Daniel Schmidt
14c83aa7ee allow reporting action invocations as deferred 2025-08-25 14:02:30 +02:00
Daniel Schmidt
0313b1471d jsonplan: move action invocation marshalling to separate function 2025-08-25 14:02:30 +02:00
Kristin Laemmert
76a9aa288b
fix: move parsing action reference expressions into terraform (#37458)
* properly parse actions during configuration loading
* parse action expression during ActionPlanTransformer transform
* fix: properly parse action expressions (not traversals)

Previously, we were storing action and linkedResource expressions as Traversals during config loading. This PR replaces those fields with hcl.Expression, moves some validation around to account for the fact we don't have fully evaluated traversals yet (some checks have been removed entirely and will be replaced in a follow up PR, I wanted to get this right first), and finally moves the actual evaluation into the terraform graph build phase.

 I added a permissive parsing of the ActionExpression during ActionPlanTransformer.transformSingle (to get the config action) and store the action expression inside the nodeActionTriggerPlanExpand.lifecycleActionTrigger so it can be fully evaluated (with access to the resource's repetition data, which is necessary if the action in the resource's lifecycle block uses count.index or for_each.key) during nodeActionTriggerPlanExpand.DynamicExpand
2025-08-22 11:23:55 -04:00
Daniel Schmidt
90bdc053f2 add SRO message for planned action invocation 2025-08-22 10:38:47 +02:00
Sarah French
62b3ba590a
Update backend.Backend interface to return diagnostics from Workspaces and DeleteWorkspace methods (#37430)
* Update Backend interface to use diagnostics for `DeleteWorkspace` and `Workspaces` methods

* Update testing helpers in backend package

* Update pluggable package to match interface changes

* Update builtin terraform provider package to match interface changes

* Update code in Meta-related files in command package; update error check logic

* Update workspace commands; update error check logic

* Update Local backend package to match interface changes

* Update Cloud backend to match interface changes

* Update Remote backend to match interface changes

* Update cos remote-state backend to match interface changes

* Update inmem remote-state backend to match interface changes

* Update pg remote-state backend to match interface changes

* Update http remote-state backend to match interface changes

* Update consul remote-state backend to match interface changes

* Update oss remote-state backend to match interface changes

* Update kubernetes remote-state backend to match interface changes

* Update gcs remote-state backend to match interface changes

* Update s3 remote-state backend to match interface changes

* Update oci remote-state backend to match interface changes

* Update azure remote-state backend to match interface changes

* Allow warnings from Workspaces and DeleteWorkspace methods to be logged or returned to calling code

* Fix defect in inmem backend test

* Change how warnings from workspace-related methods are output to view/ui
2025-08-18 19:03:31 +01:00
Samsondeen
1ce7d800c0
fix flaky test TestJSONHook_EphemeralOp_progress (#37451) 2025-08-18 16:39:49 +02:00
Daniel Schmidt
219c31f4eb action: move action trigger into nested struct
this prepares the work on CLI / flag-driven invocations
2025-08-18 13:53:09 +02:00
Sarah French
da76dba3dc
PSS: Add alternative, experimental version of init command that downloads providers in two stages (#37350)
* Add forked version of `run` logic that's only used if experiments are enabled

* Reorder actions in experimental init - load in full config before configuring the backend.

* Add getProvidersFromConfig method, initially as an exact copy of getProviders

* Make getProvidersFromConfig not use state to get providers

* Add `appendLockedDependencies` method to `Meta` to allow multi-phase saving to the dep locks file

* Update experimental init to use new getProvidersFromConfig method

* Add new getProvidersFromState method that only accepts state information as input for getting providers. Use in experimental init and append values to existing deps lock file

* Update messages sent to view about provider download phases

* Change init to save updates to the deps lock file only once

* Make Terraform output report that a lock file _will_ be made after providers are determined from config

* Remove use of `ProviderDownloadOutcome`s

* Move repeated code into separate method

* Change provider download approach: determine if locks changed at point of attempting to update the lockfile, keep record of incomplete providers inside init command struct

* Refactor `mergeLockedDependencies` and update test

* Add comments to provider download methods

* Fix issue where incorrect message ouput to view when downloading providers

* Update `mergeLockedDependencies` method to be more generic

* Update `getProvidersFromState` method to receive in-progress config locks and merge those with any locks on file. This allows re-use of providers downloaded by `getProvidersFromConfig` in the same init command

* Fix config for `TestInit_stateStoreBlockIsExperimental`

* Improve testing of mergeLockedDependencies; state locks are always missing version constraints

* Add tests for 2 phase provider download

* Add test case to cover use of the `-upgrade` flag

* Change the message shown when a provider is reused during the second provider download step.

When downloading providers described only in the state then the provider may already be downloaded from a previous init (i.e. is recorded in the deps lock file) or downloaded during step 1 of provider download. The message here needs to cover both potential scenarios.

* Update mergeLockedDependencies comment

* fix: completely remove use of upgrade flag in getProvidersFromState

* Fix: avoid nil pointer errors by returning an empty collection of locks when there is no state

* Fix: use state store data only in diagnostic

* Change how we make PSS experimental - avoid relying on a package level variable that causes tests to interact.

* Remove full-stop in view message, update tests

* Update span names to be unique

* Re-add lost early returns

* Remove unused view messages

* Add comments to new view messages
2025-08-18 11:20:18 +01:00
Sarah French
1c143de7c9
Update help output to consistently call out -state and -state-out flags as legacy and related to the local backend. (#37446) 2025-08-14 09:57:43 +01:00
Daniel Schmidt
3cf76a7d45 make wording more consistent 2025-08-13 16:47:28 +02:00
Daniel Schmidt
ecfbdaf18d add number of action invocations to change summary 2025-08-13 16:47:28 +02:00
Radek Simko
3b55d61ffa
command/views: Document and divide JSON message types (#37426) 2025-08-12 07:07:47 +01:00
Daniel Schmidt
102a561e3d add actions to the planfile config 2025-08-06 10:38:21 +02:00
Daniel Banck
dcb0486c44
Update query complete message to a struct (#37395) 2025-08-04 15:47:28 +02:00
Samsondeen
3f7d043566
Append warning in CLI output when query result is empty (#37379) 2025-08-01 16:39:58 +02:00
Daniel Schmidt
8a88bbbff3 use constants 2025-07-31 16:07:38 +02:00
Daniel Schmidt
fb0445faf2 allow language experiments for terraform show 2025-07-31 16:07:38 +02:00
Daniel Schmidt
ccd89c58b2 fail on marked values in action config
this will be supported, but we skip this right now to keep the PR size more manageable
2025-07-31 16:07:38 +02:00
Daniel Schmidt
4fb4c3f056 render action config values 2025-07-31 16:07:38 +02:00
Daniel Schmidt
dd86671056 marshal action schemas into json provider representation 2025-07-31 16:07:38 +02:00
Daniel Schmidt
eb26b72d55 display lifecycle triggered actions aside their triggering resources 2025-07-31 16:07:38 +02:00
Daniel Schmidt
7d8b79a596 add a simple first rendering of action invocations to be run 2025-07-31 16:07:38 +02:00
Daniel Schmidt
5e288f56e2 add new planfile fields to terraform show -json 2025-07-31 16:07:38 +02: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
Mark DeCrane
14d378f9ce Ignore cmd arg parsing errors, we can expect these to happen 2025-07-29 11:39:43 -04:00
Sarah French
7b28a5d842
PSS: Allow backend or state_store config to be passed via BackendOpts into method for initialising the operations backend for a command (#37346)
* Allow backend or state_store config to be passed via BackendOpts from calling code

* Update messages sent to view: make message specific to state storage mechanism in use

* Add nil pointer check

* Fix typos

* Pivot to `Len` method approach of nil check

* Pivot to the point of pirouetting
2025-07-29 10:03:57 +01:00
Liam Cervante
84c2e2f9e5
terraform test: override prevent_destroy meta attribute (#37364) 2025-07-25 13:54:56 +02:00
Samsondeen
36836fd456
Tests for query command outputs (#37343) 2025-07-24 12:16:39 +02:00
Daniel Schmidt
c2b35e7ee7 remove duplicate place to store action invocations from plan 2025-07-24 11:28:29 +02:00
Daniel Schmidt
834665e332 use better hook identity 2025-07-24 11:28:29 +02:00
Liam Cervante
160b6b35b0
terraform test: include expected diagnostics in verbose mode (#37362) 2025-07-24 11:02:37 +02:00
Daniel Banck
c177897320
Improve list result output (#37344) 2025-07-23 16:52:37 +02:00
Daniel Banck
3607089016
Support tfquery files in terraform fmt (#37347) 2025-07-23 16:52:19 +02:00
Liam Cervante
0a7701f19a
terraform test: refactor graph edge calculation (#37357)
* terraform test: refactor graph edge calculation

* remove unused attribute
2025-07-23 16:09:45 +02:00
Sarah French
d1e412fcf0
PSS: Add initial (incomplete) version of code changes to the init command for using pluggable state storage (#37321)
* Store the FQN of the provider used in PSS in representations of the parsed config.

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.

* Update affected tests, improve error diagnostic

* Begin enabling method to return a backend.Backend made using state_store config.

State store config can now be received via BackendOpts and there is rough validation of whether the config makes sense (does the provider offer a store with the given name?).

* Update code's logic to include possibility of a state store being in use

At this point there are no cases that actually handle the state store scenarios though!

* Add empty cases for handle all broad init scenarios involving PSS

* Update default case's error to report state store variables

* Improve how we resolve the builtin terraform provider's address

* Add test that hits the code path for adding a state store to a new (or implied local) project

* Add test for use of `-reconfigure` flag; show that it hits the code path for adding a state store for the first time

* Add test that hits the code path for removing use of a state store, migrating to (implied) local backend

* Add test that hits the code path for changing a state store's configuration

* Update existing test names to be backend-specific

* Add tests that hits the code path for migrating between PSS and backends

* Consolidate PSS-related tests at end of the file

* Fix log text

* Add test showing that using variables is disallowed with state_store and nested provider blocks

* Update test name

* Fix test cases

* Add TODOs so we remember to remove experiments from tests

* Update state store-related tests to use 	t.Cleanup

* Remove use of `testChdir`
2025-07-18 14:08:18 +01:00
Kristin Laemmert
9256074c43
Actions in plan/changes (#37320)
* Add actions to the plans and change
* jsonplan - ignoring LinkedResources for now, those are not in the MVP
* pausing here: we'll work on the plan rendering later
2025-07-17 08:19:57 -04:00
Sarah French
7199fbd2bb
Update use of testChdir to standard library's t.Chdir, remove testChdir function from codebase (#37334)
* Replace use of `testChdir` with `t.Chdir`

* Update tests to use temporary directories with copied content, instead of using directories in the repo directly.

* Remove stacks copy of testChdir function

This has been replaced with t.Chdir from the standard library

* Replace remaining simple usage of testChdir

* Update guidance for using `tempWorkingDir`

* Replace use of testChdir in a function reused in a single test

* Update comments to no longer recommend using testChdir

* Remove testChdir function!
2025-07-16 16:04:10 +01:00
Sarah French
e79b5a1628
Replace custom testCwd function with standard testing library (#37335)
* Replace custom testCwd function with standard `testing` library

* Update comments that reference testCwd function
2025-07-16 10:41:51 +00:00
Sarah French
15840b3eae
Replace use of defer with t.Cleanup in majority of command package tests, update testChdir to work with t.Cleanup (#37326)
* Replace use of `defer` with `t.Cleanup` in tests

* Fix test failures by making cleanup function permissive of the temp dir being already deleted.
2025-07-16 10:24:56 +01:00
Sarah French
7a27366b39
PSS: Add ability to create hashes of the state_store block and of its nested provider block (#37278)
* Add the ability to make a hash of state store config

* Add test demonstrating that the provider block doesn't impact the hash of a state_store block

* Make sure test asserts what would happen if the schema DID include the provider block

* Update the Hash method to return diagnostics, ignore nested provider blocks, and validate incoming schema and config

* Update tests to use more representative config, fix code under test as a result

* Update Hash method to return hashes for both the state_store and provider blocks

* Add test cases to cover how required fields are tolerated when making the hash

This is because ENVs may supply those values.

* Fix inaccurate comments

* Add test to show that hashes are consistent and exclude the provider block

* Update backend state file to contain hash of provider block's config

* Fix test to expect a hash for the provider config block.

* Fix bug in DeepCopy method, update test to have better error messages when diffs are detected

* Update test to explicitly check hash values

* Try make test intention clearer

* Improve user feedback when state store schema contains the protected word "provider"

* Update tests

* Update test to test the Hash method in a more true-to-life way

Copy of 04a1201878cd1f6f117c43c43c1ee9d0fc17cec1 by Radek Simko

* Update test to use new approach

* Fix `TestInit_stateStoreBlockIsExperimental` test failure
2025-07-14 13:52:27 +01:00
Sarah French
145e152a57
Clarify usage of BackendOpts, rename field in struct to enable usage with PSS in future (#37085)
* Update comments to distinguish between operations and state-storage backends more clearly

* Rename `BackendOpts` field `Config` to more specific `BackendConfig`
2025-07-11 11:08:56 +01:00
Radek Simko
5437cd7c8a
Prepare main branch for 1.14 development (cleanup) (#37312)
* Prepare main branch for 1.14 development (cleanup)

* fix version-dependent tests

* update PR template
2025-07-09 17:42:04 +01:00
Samsondeen
0f7a690d25
Skip query e2e test when we cannot build at runtime (#37307) 2025-07-09 13:51:16 +01:00
Samsondeen
870bf99593
List implementation for simple provider and e2e tests (#37297) 2025-07-09 12:19:26 +02:00
Sarah French
677e5ea276
Add test coverage for Meta's determineInitReason method, fix error in diagnostic (#37303)
* Add test coverage for Meta's determineInitReason method, fix error in diagnostic when migrating away from HCP Terraform

* Add godoc comment to determineInitReason method
2025-07-08 16:34:43 +01:00
Sarah French
d02a1ed1b7
PSS: Make the state storage provider's config stateful (backend state, planfiles) (#37286) 2025-07-08 15:32:27 +01:00
Daniel Schmidt
8649eae35d rename ActionInvocation for clarity 2025-07-08 16:24:38 +02:00
Daniel Schmidt
8c657163b2 add hooks for action invocation lifecycle 2025-07-08 16:24:38 +02:00
Samsondeen
a1332299a5
Test run Parallelism of 1 should not result in deadlock (#37292) 2025-07-07 09:44:32 +02:00
Samsondeen
8d8b2bb694
Generate config for list results (#37173) 2025-07-04 11:35:39 +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
Mark DeCrane
577f8f02ae
Merge pull request #37283 from hashicorp/TF-26979/central-binary-download-tf-stacks-cli
Move `stacksplugin` cache to `.terraform.d`
2025-07-02 07:00:21 -04:00
Mark DeCrane
1529739017 remove the cache override arg from the args passed to the plugin 2025-07-01 19:31:22 -04:00
Mark DeCrane
60dbc8b12f Move stacksplugin cache to .terraform.d, allow for overriding of cache dir location 2025-07-01 19:04:01 -04:00
Sarah French
2349481b23
Update data stored in plan files to enable using PSS with saved plans (#37246)
* Implement `ForPlan` method on `StateStoreConfigState`, add `Planner` interface

* Rename `ForPlan` method to `Plan`

* Allow plan files to contain information about state stores

* Add code needed for representing a state store in the Plan struct, which is used when handling plan files

* Add ability to read/write either a backend or state store's data in a plan file. Add some test coverage.

* Update plan's `ProviderAddrs` method to include the provider used for PSS, if present

* Split interfaces

* Apply feedback from code review

* Refactor `SetVersion` to use appropriate constructor

* Split `ProviderAddrs` method test into two

* Fix method call after rename

* Fix test

* Remove change to `(p *Plan) ProviderAddrs()`

We may re-add this when we implement PSS for use during apply commands with plan files

* Remove changes to test, now that the plan doesn't report the provider used for PSS anymore.
2025-06-30 11:39:15 +01:00
Daniel Banck
ab04e5cfec
Include list resource schemas in provider json schemas (TF-25497) (#37163)
* Include list schemas in provider json schemas

* Only include list schemas in experimental builds
2025-06-30 10:59:19 +02:00
Sarah French
38e2ed42c4
Make the workspace command explicitly protect the default workspace, instead of relying on backend implementations (#37256)
* Add test showing that users cannot delete the default workspace

Note: in the test this validation is being returned from the local backend's `DeleteWorkspace` method, not the command itself.

* Make the `workspace delete` command return early if the user is trying to delete the default workspace. Update test.

* Clean up redundant parts of test
2025-06-27 19:17:43 +01:00
Sarah French
d3b02a8469
Refactor code to use backend config state's SetConfig method, protect against nil receiver (#37254)
* Add protection against nil receivers to SetConfig

* Refactor code to use SetConfig method instead of setting ConfigRaw directly
2025-06-27 19:16:44 +01:00
Sarah French
a91d3aafa8
Fix bug in DeepCopy of backend state data that causes loss of StateStore data (#37276) 2025-06-26 21:38:45 +01:00
Sarah French
3617b909c1
Make workspace delete command reject empty string arguments (#37275)
* Disallow "" as the argument to workspaces delete command

* Add change file
2025-06-26 15:36:29 +01:00
Sarah French
9212a2efdd
Make Terraform reject empty strings as invalid workspace names (#37267)
* Add tests defining what are valid workspace names

* Update workspace name validation to mark an empty string as not valid

* Add change file

* Add command-level test showing the "" workspace cannot be created or selected

* Update invalid name error text to include empty string as invalid.
2025-06-26 12:26:58 +01:00
Matej Risek
a9b67a6cdc
stacks: Don't require built-in providers to be listed under required providers. (#37234) 2025-06-18 17:02:27 +02:00
Samsondeen
f57642d1a6
tf test: parallelize teardown operations (#37220) 2025-06-13 10:12:26 +02:00
Sarah French
2559f0a3db
Update backend state file so it can describe PSS state (#37179)
* Split code for backend state file vs backend state

* Rename BackendState to BackendConfigState

* Spelling error

* Add `StateStorageConfigState` struct as new implementation of new `ConfigState[T any]` interface.

* Split tests for backend state file vs backend config state structs

* Rename StateStorageConfigState to StateStoreConfigState

* Clarify test name, add comments

* Add tests for StateStoreConfigState methods

* Add test showing state_store in JSON is parsed correctly

* Add detection of malformed backend state files that contain both backend and state_store fields

* Add validation that stops a backend state file being written if it will contain state for both backend and state_store blocks

* Rename `state_storage` to `state_store`

* Rename `state_storage` to `state_store` in filenames

* Move`ConfigState` to its own file

* Fix test name, remove whitespace

* Update `StateStoreConfigState` comment using review suggestion

* Update error message to no longer allude to the environment TF is being run in

* Update the state_store state to use `version.Version` and an adapted version of `tfaddr.Provider` for marshalling version and source data

* Update test helper so it doesn't accidentally supply validation in tests

* Add protection against saving an empty backend state file

* Remove direct testing of (s *Source) MarshalText() and UnmarshalText() methods

* Add Validate method to StateStoreConfigState, use in backend state encoding logic

* Refactor to use new features in registry dependency
2025-06-11 14:10:26 +00: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
Liam Cervante
f3489c0480
deferred actions: should still be experimental (#37167) 2025-05-26 09:16:13 +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
Mark DeCrane
ffca158061
Merge pull request #37015 from hashicorp/TF-25893/handle-stacks-plugin-interupts
Handle stacks plugin interrupts
2025-05-19 09:58:02 -04:00
Daniel Banck
8213714929
Include identity in import apply UI output (#37044)
* Include identity in import apply UI output

* Add logging to hook ui errors
2025-05-16 15:24:24 +02:00
Radek Simko
4e00e1ecdb
fix: Avoid crash on test failure in BinaryOpExpr in function call (#37071)
* fix: Avoid crash on test failure in BinaryOpExpr in function call

* add changelog entry
2025-05-16 10:49:31 +00:00
Liam Cervante
c5445d4568
stacks: move the RPCAPI and deferred actions out of experimental (#37067)
* stacks: move the RPCAPI and deferred actions out of experimental

* add PR number
2025-05-16 11:11:55 +02:00
Mark DeCrane
5b33d74641 Handle the propagation of interrupt signals to stacks plugin 2025-05-14 15:19:24 -04:00
UKEME BASSEY
f7cb9097da
Merge pull request #36931 from hashicorp/TF-25178-add-stacks-plugin-proto
Add stacks plugin functionality: terraform stacks cmd
2025-05-14 12:15:55 -04:00
drewmullen
09cff2be39
include help entry for -replace (#36780)
* include help entry for -replace

* add to website docs as well

* Update internal/command/apply.go

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>

* Update website/docs/cli/commands/apply.mdx

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>

---------

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>
2025-05-14 12:03:47 -04:00
Sarah French
5cc7479e0e
Update test to tolerate durations in scientific notation (very short test durations) (#37041)
It's not valid to force integer values for `time`, so this is a case where the test needs to be updated and not the code under test.
2025-05-13 16:53:41 +01:00
UKEME BASSEY
a732b606a1 make hostname and token optional, read token from cli file 2025-05-12 17:10:40 -04:00
UKEME BASSEY
3bc13593f9 add proto files gen for stacks plugin, & regenerate protofiles
add tests

update changelog
2025-05-05 16:06:49 -04:00
UKEME BASSEY
b12984470b Merge remote-tracking branch 'origin/main' into TF-25178-add-stacks-plugin-proto 2025-04-30 12:32:09 -04:00
Daniel Banck
0aa4ce972d
Add resource identities to plan file and JSON output (#36903) 2025-04-30 14:43:23 +02:00
UKEME BASSEY
509be4ea1b add stacks plugin 2025-04-28 12:57:14 -04:00
UKEME BASSEY
91b1dd3cc3 extend existing cloud plugin to accomodate new plugin 2025-04-28 12:54:23 -04:00
Sarah French
8d2dffedb3
Fix defects where done is called before the command's Run method is invoked (#36852)
* Fix defects where `done` is called before the command's `Run` method is invoked

We're attempting to reading output from a command that hasn't been executed yet!

* Another one
2025-04-14 09:47:03 +01:00
Radek Simko
36fb64f297
grpcwrap+provider-simple: Test ephemeral resource schemas in v5 protocol (#36878)
* grpcwrap+provider-simple: Test ephemeral resource schemas in v5 protocol

* Update internal/command/e2etest/providers_schema_test.go

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>

---------

Co-authored-by: Daniel Banck <dbanck@users.noreply.github.com>
2025-04-11 09:36:47 +01:00
Sarah French
ea767aa7ad
Add comments about use of ResourceStores with TestProviders (#36856) 2025-04-08 15:24:19 -05:00
Sarah French
884fc64618
Remove unused test fixture "push-backend-new" (#36842) 2025-04-03 17:21:02 +01:00
Samsondeen
c0a7ff235b
Apply some new go collection features (#36818) 2025-04-02 16:20:16 +02: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
Daniel Banck
6917e69d12
Config-driven importing through identity (TF-23179) (#36703)
* configschema: Add identity attribute to import block

* Mark import target ID as legacy

* Add test with import identity

* Use ID or identity when importing via configuration

* Add plan import tests

* Review Feedback

* Make sure to copy identity for ResourceInstanceObjects

* Add helper for converting cty.Objects to string

* Replace getProvider calls

* Improve unknown object check
2025-04-02 13:39:16 +02:00
Sarah French
371e625ea9
Update URLs from www.terraform.io to developer.hashicorp.com (#36792)
* Update URLs from www.terraform.io to developer.hashicorp.com

* More updates to URLs linking to documentation in documentation and user-facing warnings/errors

* More updates to URLs linking to documentation, in docs, code, test fixtures

* Replace www.terraform.io/community with link to Community Forum

* Apply suggestions from code review

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>

---------

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>
2025-04-01 09:37:12 +01:00
Sarah French
2d6eda2877
Update comments about backend interfaces, enhanced vs operations, and fix copy-paste inaccuracies (#36716)
* Fix copy-pasta

* Update some comments clarifying backend-related interfaces and "enhanced" versus "operations"

* Fix more comments that refer to types and interfaces that have moved into the backendrun package
2025-03-20 16:52:00 +00:00
Samsondeen
595cd80666
CLI command for listing state identities (#36705) 2025-03-18 18:13:06 +01:00
Daniel Banck
1210d68836
Output resource identities in State JSON (TF-23753) (#36615)
* jsonstate: Marshal identity values

* jsonstate: Test identity marshalling

* Add identity to prepareStateV4

* Check identity schema version when marshaling state

* Marshal identity for deposed resources

* Marshal identity version if `0`

* Check for missing resource identity schema
2025-03-14 11:15:03 +01:00
Daniel Banck
cd433fa6d9
Marshall resource identity schemas in jsonprovider (#36675) 2025-03-12 09:53:03 +01:00
Daniel Schmidt
fec6e4b552 send resource identities to provider calls 2025-03-12 09:18:55 +01:00
Daniel Banck
b2b42c0fb4
Store resource identities in state (TF-23255) (#36464)
* Persist resource identity in Terraform state

* make syncdeps

* Move identity schema merging closer to the protocol

* mock GetResourceIdentitySchemas

* Fix identity refresh tests

* Add more tests

* Change grcpwrap upgrade identity

* Review feedback

* Remove unnecessary version conversion

* Check if GetResourceIdentitySchemas RPC call is implemented

* Update function signature docs

* Adapt protocol changes

* Check unimplemented error for identities in GetSchema
2025-03-11 20:58:44 +01:00
Guilherme Faria de Souza
d845df938d
Enhance elapsed time display in UI Hook with minutes and seconds (#36618)
* Feat: Enhance elapsed time display in UI hook with minutes and seconds format

* changelog: improve elapsed time display in UI Hook (#36368)

* update test output to use zero-padded elapsed time format
2025-03-05 10:40:57 +00:00
Liam Cervante
aaf617d6d7
Add test case to ensure no regression of already fixed crash (#36583) 2025-03-05 11:24:53 +01:00
Daniel Banck
10c9b64007
Rename schema.Block to Body (#36629) 2025-03-04 16:33:43 +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
Liam Cervante
0acd732911
Fix flaky test in test_test.go (#36566) 2025-02-25 14:11:17 +01:00
Samsondeen
85db2264db
skip flaky test (#36540) 2025-02-20 09:40:13 +01: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
018110c012
No state to cleaup when it is empty (#36526) 2025-02-18 19:33:41 +01:00
Radek Simko
289a3568da
Address go vet 1.24 failures (#36485)
* address go vet failures

* avoid unnecessary .Error()
2025-02-12 16:51:53 +00: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
Samsondeen
86295f518c
Don't set default parallelism for cloud runs (#36441) 2025-02-06 08:54:08 +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
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
Bruno Schaatsbergen
61acb0cb3a
tfdiags: add Warnings method (#36392)
Adds a new method to the tfdiags API: Warnings() returns a new Diagnostics list containing only diagnostics with a severity of Warning.
2025-01-23 12:59:46 +00: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
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
Sarah French
39224976a8
Make test fail if JUnit feature is experimental (#36348) 2025-01-16 13:21:56 +00: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
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
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
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
Sarah French
43f31c43b0
Add start time timestamps to <testcase>/Run data in JUnit XML output from terraform test (#36295)
* Record metadata about the start timestamp for a Run/test case

* Add RFC3339 format timestamp attributes to `<testcase>` elements in JUnit XML output

* Ensure timestamps are saved as and rendered as UTC timestamps
2025-01-10 10:25:32 +00:00
Samsondeen
aec7c3cc89
terraform test: allow computed/mocked values override during planning (#36227) 2025-01-08 12:39:03 +01:00
Daniel Schmidt
276662f754 ephemeral: add test case for block rendering 2025-01-07 10:19:51 +01:00
Liam Cervante
672cd816d5 don't precompute actions 2025-01-07 10:19:51 +01:00
Daniel Schmidt
0e6a3ac994 ephemeral: render write-only attributes in plan UI 2025-01-07 10:19:51 +01:00
Radek Simko
908828be8a
cmd/modules: Ensure modules are sorted by reference key (#36268) 2025-01-06 15:25:24 +00:00
Liam Cervante
a4e1e60a01
logging: add trace statements when changes are ignored (#36259)
* logging: add trace statements when changes are ignored

* copywrite headers
2025-01-03 11:28:19 +01:00
Radek Simko
1d2d35b0b4
command: Update test to aid debugging of failures (#36255) 2025-01-02 15:40:06 +00: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
f41ce87644 update comments 2024-12-11 09:04:14 +01:00
James Bardin
a003a6ecaf
Merge pull request #36180 from hashicorp/jbardin/var-file-apply
Don't validate apply variables from auto files
2024-12-10 10:14:14 -05:00
Samsondeen Dare
b3cb17dead only ignore validation if -draw-cycles is enabled 2024-12-10 16:02:53 +01:00
Samsondeen Dare
d213d45cc5 pass the option via context 2024-12-10 14:53:17 +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
Radek Simko
bfa011e88b
command/views: Fix flaky hook tests (#36104) 2024-12-09 10:23:55 +00:00
Mark DeCrane
9a3cedb499 align modules cmd with formating seen in providers cmd 2024-12-05 12:12:18 -06: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
Liam Cervante
f1bd8df9b0
jsonplan: sort the relevant attributes in the correct plan (#36093) 2024-11-25 16:49:18 +01:00
Liam Cervante
36d7e8706f
jsonplan: deterministic relevant attribute order (#36076)
* jsonplan: deterministic relevant attribute order

* simplify sort function
2024-11-25 14:26:34 +01:00
Mark DeCrane
b2a90cf587 Testing updates 2024-11-21 12:54:29 -05:00
Mark DeCrane
8d0db63571 Add human view for modules cmd 2024-11-21 12:54:24 -05:00
James Bardin
16fe12ef0b synchronize schema and test fixture 2024-11-18 10:17:18 -05:00
James Bardin
c1f8152f10 undeclared variables must be allowed during apply
Plan allows undeclared config variables with only warnings, and that
behavior need to be carried forward to apply now that ephemeral
variables can be passed in at apply time.
2024-11-18 09:30:06 -05:00
Bruno Schaatsbergen
a5d8673a41
Revert "Merge pull request #35929 from bschaatsbergen/b/fix-retry-messages-in-cloud-backend-json"
This reverts commit f8cb25a246, reversing
changes made to a25831d6ef.
2024-11-13 18:22:26 -07:00
Bruno Schaatsbergen
247302f47d
Merge branch 'main' into b/fix-retry-messages-in-cloud-backend-json 2024-11-13 02:50:22 +01:00
Bruno Schaatsbergen
6b0ba4d20d
refactor: gracefully handle marshalling error with empty output 2024-11-12 18:46:53 -07:00
Bruno Schaatsbergen
b358e333ee
refactor: make methods private 2024-11-12 18:36:43 -07:00
Daniel Schmidt
6f58dbe75c
write-only attributes: emit structural data on schema rendering 2024-11-12 16:42:05 +01:00
Bruno Schaatsbergen
515897a125
copyright: add missing header
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-11 08:26:13 -07:00
Bruno Schaatsbergen
45c38a6469
Merge branch 'main' into b/fix-retry-messages-in-cloud-backend-json 2024-11-08 14:04:13 -06:00
Bruno Schaatsbergen
ae661f3568
views: add comments for clarity
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-08 14:03:28 -06:00
Bruno Schaatsbergen
f1428b3388
backend/cloud: expose View to enable reuse in a (cloud) backend
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-08 13:51:20 -06:00
Daniel Schmidt
90973698bf
Merge branch 'main' into pass-ephemeral-variables-to-terraform-apply 2024-11-07 17:33:39 +01:00