Commit graph

44 commits

Author SHA1 Message Date
Sarah French
c37cf1c0f5
test: Enable assertions about prompt text shown to users (#38212)
* test: Update `testInputMap` and `(*UIInput) Input` to allow making assertions about what prompts a user has been shown. Make cleanup happen inside the helper.

* test: Update test to assert about prompt contents, showing how changes to `testInputMap` can be used

* docs: update godoc for testInputMap
2026-02-26 14:57:42 +00:00
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Sarah French
02a4ddce1b
fix: Fail an apply command if the plan file was generated for a workspace that isn't the selected workspace (#37955)
* fix: Fail apply command if the plan file was generated for a workspace that isn't the selected workspace.

* Add change file

* test: Update test helper to include Workspace name in plan representation

* fix: Make error message more generic, so is applicable to backend and cloud blocks.

* fix: Make error message specific to backend or cloud block

* test: Add separate tests for backend/cloud usage

* test: Update remaining tests to include a value for Workspace in mocked plans

* Apply suggestions from code review

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

* fix: Panic when a plan file has missing workspace data

* test: Update test to match changes in error text

---------

Co-authored-by: Radek Simko <radeksimko@users.noreply.github.com>
2026-02-03 15:29:58 +00:00
Sarah French
fd7f25120b
PSS: Allow pluggable state store configuration to be read from a plan file (#37957)
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: Allow reading state store configuration from a planfile and using it to prepare a Local backend that uses the state store

* test: Assert that we can get and use state store configuration from a plan file

* test: Add integration test showing that an apply command can use a plan file to configure and use a state store

* test: Add E2E test showing pluggable state storage being used with the full init-plan-apply workflow

* feat: A plan file will report the state storage provider among its required providers, if PSS is in use.

See the code comment added in this commit. This addition does not impact an apply command as the missing provider will be detected before this code is executed. However I'm making this change so that the method is still accurate is being able to return a complete list of providers needed by the plan.

* fix: Include error messages when there is a problem parsing provider or state store config when getting a backend from a planfile

* feat: Add trace logs to BackendForLocalPlan indicating when the provider is launched and the state store is configured

* chore: Small grammar change in error diagnostic

* refactor: Remove suggestions when the plan's state store doesn't match the implementations in the provider

* test: Add test coverage of what happens when the contents of a plan file using PSS doesn't match the resources available in the project
2025-12-18 11:49:31 +00:00
Sarah French
9fb91c2229
PSS: Refactor Plan struct to reference Backend and StateStore via pointers, update calling code (#37946)
Some checks failed
build / Build for freebsd_amd64 (push) Has been cancelled
build / Build for linux_amd64 (push) Has been cancelled
build / Build for openbsd_amd64 (push) Has been cancelled
build / Build for solaris_amd64 (push) Has been cancelled
build / Build for windows_amd64 (push) Has been cancelled
build / Build for freebsd_arm (push) Has been cancelled
build / Build for linux_arm (push) Has been cancelled
build / Build for darwin_arm64 (push) Has been cancelled
build / Build for linux_arm64 (push) Has been cancelled
build / Build for windows_arm64 (push) Has been cancelled
build / Build Docker image for linux_386 (push) Has been cancelled
build / Build Docker image for linux_amd64 (push) Has been cancelled
build / Build Docker image for linux_arm (push) Has been cancelled
build / Build Docker image for linux_arm64 (push) Has been cancelled
build / Build e2etest for linux_386 (push) Has been cancelled
build / Build e2etest for windows_386 (push) Has been cancelled
build / Build e2etest for darwin_amd64 (push) Has been cancelled
build / Build e2etest for linux_amd64 (push) Has been cancelled
build / Build e2etest for windows_amd64 (push) Has been cancelled
build / Build e2etest for linux_arm (push) Has been cancelled
build / Build e2etest for darwin_arm64 (push) Has been cancelled
build / Build e2etest for linux_arm64 (push) Has been cancelled
build / Run e2e test for linux_386 (push) Has been cancelled
build / Run e2e test for windows_386 (push) Has been cancelled
build / Run e2e test for darwin_amd64 (push) Has been cancelled
build / Run e2e test for linux_amd64 (push) Has been cancelled
build / Run e2e test for windows_amd64 (push) Has been cancelled
build / Run e2e test for linux_arm (push) Has been cancelled
build / Run e2e test for linux_arm64 (push) Has been cancelled
build / Run terraform-exec test for linux amd64 (push) Has been cancelled
* refactor: Update Plan struct's Backend field to be a pointer

* fix: Add some refactorings or protections against nil pointers when accessing the Backend field on a Plan struct

* refactor: Update Plan struct's StateStore field to be a pointer, update a nil check in calling code.
2025-11-28 16:12:46 +00:00
James Bardin
4ce205da74 provider eval scope test 2025-10-31 13:07:04 -04: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
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
Daniel Banck
10c9b64007
Rename schema.Block to Body (#36629) 2025-03-04 16:33:43 +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
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
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
Daniel Schmidt
90973698bf
Merge branch 'main' into pass-ephemeral-variables-to-terraform-apply 2024-11-07 17:33:39 +01:00
Liam Cervante
eeacced8f0
Add go vet as a check to the Github commit actions (#31461)
* Add go vet as a check to the Github commit actions

* deliberately break to test

* fix after successful test

* Use  directly

* fix more errors
2024-11-07 17:29:58 +01:00
Daniel Schmidt
eccf39aa45
ephemeral: support interactive variable input for ephemeral values 2024-11-07 11:48:55 +01: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
Daniel Schmidt
3207836729
ephemeral: tests for setting unplanned vars during apply 2024-11-04 15:35:22 +01:00
Daniel Schmidt
0e632aae86
ephemeral: allow setting non-ephemeral values during apply to same value as in plan 2024-11-04 15:35:22 +01:00
Daniel Schmidt
0a71f24453
disable interactive prompt test for now 2024-11-04 15:35:22 +01:00
Daniel Schmidt
a87b36a1a8
restructure tests 2024-11-04 15:35:22 +01:00
Daniel Schmidt
756a1a74ad
ephemeral: add apply tests 2024-11-04 15:35:22 +01:00
Daniel Schmidt
f4ff263d24
restructure existing test 2024-11-04 15:35:21 +01: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
James Bardin
0b8fbfe323 ignore unexported state field in comparison
and unify the options used to compare changes in tests
2024-08-22 09:39:37 -04:00
James Bardin
16231373a4 update changes in command pkgs 2024-08-22 09:39:37 -04:00
Martin Atkins
9dd16a7fba command: "terraform apply" accepts variable values with saved plan
To support ephemeral values we need a more complicated set of rules about
what input variables can and must be set when applying a saved plan. The
command itself does not have enough information to implement those rules
itself, so we'll let them pass through and check this in the local
backend's apply phase instead.

The local backend's apply phase already had basic support for dealing with
apply-time variable values, but it'll now also be responsible for
rejecting attempts to set variables when the experiment isn't enabled,
to keep all of this logic in roughly the same place.
2024-06-05 09:09:30 -07:00
Liam Cervante
f0b61090a2
Move the testing MockProvider into a dedicated shared package (#34681)
* move the testing MockProvider into a dedicated shared package

* address comments

* fix new changes
2024-02-16 10:35:29 +01:00
Jamie Finnigan
05b0bdac99
adopt hashicorp/cli fork of mitchellh/cli (#34429) 2023-12-20 11:04:10 +00:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Sheridan C Rawlins
75e5ae27a2
[fixes 31700] Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert. (#31699)
* Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert.

* Fix style.

* Skip cert validation to be sure error is related to missing client cert; not untrusted server cert.

* Remove misplaced err check.

* Fix the size of test using http backend.

* Just for correctness, include all certs in the pem encoded cert - sometimes certs come with a chain of their signers.

* Adjusted names as recommended in PR comments.

* Adjusted names to be full-length and more descriptive.

* Added full-fledged testing with mTLS http server

* Fix goimports.

* Fix the names of the backend config.

* Exclusive lock for write and delete.

* Revert "Fix goimports."

This reverts commit 7d40f6099fbbb675fb2e25e35ee40aeafe3d0a22.

* goimports just for server test.

* Added the go:generation for the mock.

* Move the TLS configuration out to make it more readable - don't replace the HTTPClient as the retryablehttp already creates one - just configure its TLS.

* Just switch the client/data params - felt more natural this way.

* Update internal/backend/remote-state/http/backend.go

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

* Update internal/backend/remote-state/http/testdata/gencerts.sh

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

* Update internal/backend/remote-state/http/backend.go

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

* Update internal/backend/remote-state/http/backend.go

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

* Update internal/backend/remote-state/http/backend.go

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

* Update internal/backend/remote-state/http/backend.go

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

* the location of the file name is not sensitive.

* Added error if only one of client_certificate_pem and client_private_key_pem are set.

* Remove testify from test cases; use t.Error* for assert and t.Fatal* for require.

* Fixed import consistency

* Just use default openssl.

* Since file(...) is so trivial to use, changed the client cert, key, and ca cert to be the data.

See also https://github.com/hashicorp/terraform-provider-http/pull/211

Co-authored-by: Sheridan C Rawlins <scr@ouryahoo.com>
Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-01-26 14:08:07 +00:00
Jeff Bonhag
f30738d965
Add golden reference test for JSON plan (#31362)
* Add golden JSON test for Terraform plan

* Add data source to golden JSON plan

* Move output comparison code into shared helper function

* Add note for maintainer to contact TFC when UI changes

UI changes may potentially impact the behavior of structured run output
on TFC.

* Add test_data_source to other mock providers
2022-07-12 17:00:36 -04:00
Eng Zer Jun
fedd315275
test: use T.TempDir to create temporary test directory (#30803)
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-04-08 17:34:16 +01:00
James Bardin
9c80574417 test planfile may need to have a specific lineage
In order to test applying a plan from an existing state, we need to be
able to inject the state meta into the planfile.
2021-10-13 17:28:14 -04:00
James Bardin
863963e7a6 de-linting 2021-09-01 11:36:21 -04:00
Martin Atkins
36d0a50427 Move terraform/ to internal/terraform/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Martin Atkins
f40800b3a4 Move states/ to internal/states/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Martin Atkins
034e944070 Move plans/ to internal/plans/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Martin Atkins
31349a9c3a Move configs/ to internal/configs/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Martin Atkins
ffe056bacb Move command/ to internal/command/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00
Renamed from command/apply_test.go (Browse further)