Commit graph

72 commits

Author SHA1 Message Date
Daniel Schmidt
a9756b273c move initwd config loading into terraform
otherwise we run into cyclic references
2026-03-06 11:59:59 +01:00
Daniel Banck
4ef9684188 Rework most of the configuration loading
We previously used a loader -> BuildConfig flow to load configuration.
This commit changes most (but not all yet) flows to use the new
graph-based approach. Instead of simply recursively loading the modules,
we now need to take a stepped approach:

1. Load the root module
2. Collect the variables and their values
3. Build the configuration with the graph-based approach

Because this approach relies on different parts from different packages,
it can't easliy be done within the `configload` package. So, now we do
most of in the backend or command.
2026-03-04 11:45:59 +01:00
Daniel Schmidt
2424cf6423 make test case more robust to developer environments
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
2026-02-24 18:22:54 +01:00
Daniel Schmidt
026c935961 move UnparsedVariableValue from backendrun to arguments
This prevents a cyclic dependency and also makes sense semantically.
The arguments package will collect the unparsed variable values and
the backendrun helpers will work to collect the values and transform
them into terraform.InputValue.
2026-02-18 12:47:12 +01:00
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Sarah French
508234892c
Update remote.Client interface's methods to return diagnostics instead of primitive errors (#37502)
* Update remote package's Client interface to use diagnostics instead of errors

* Update all implementations of Client interface to match changes, update calling code (incl. tests) to use diags.
2025-09-05 11:04:47 +01: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
Amartya Majumdar
54af16eab9
[IPL-7725] Updating Calls to the Remote HCP Terraform API to Retrieve All Workspace Variables (#37241)
* [IPL-7725] Resolving merge conflicts

* [IPL-7725] Updating go.sum files

---------

Co-authored-by: Amartya Majumdar <a.majumdar1041@gmail.com>
2025-09-03 15:26:07 +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
Rémi Lapeyre
5a8de9d70d
Add TRACE logs when uploading to the cloud and remote backends (#36757)
Co-authored-by: Liam Cervante <liam.cervante@hashicorp.com>
2025-03-27 06:42:46 +00: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
Mark DeCrane
a1b5ed3a4c
Merge pull request #36655 from hashicorp/IPL-7753/wait-for-post-plan-tasks-remote-backend
Add polling to wait for post plan tasks to complete in remote backend
2025-03-12 10:10:06 -04:00
Mark DeCrane
0c155929c6 Add polling to wait for post plan tasks to complete in remote backend 2025-03-11 11:23:33 -04:00
Daniel Banck
10c9b64007
Rename schema.Block to Body (#36629) 2025-03-04 16:33:43 +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
Shweta
bb940cbfd6
Fix error reading remote workspace with version constraint (#36356)
* Update backend.go

* remove comments

* Change error string

* Add to changelog

* add yaml to changelog

* Change yaml format

* generate changelog with changie instead of manually

* Add new test

* Change issue to PR number

* Update .changes/unreleased/BUG FIXES-20250123-135228.yaml

Co-authored-by: Sebastian Rivera <sebastian.rivera@hashicorp.com>

* Update backend_test.go

* Update backend_test.go

* Update backend_test.go

* Update backend_test.go

* Update internal/backend/remote/backend_test.go

Co-authored-by: Sebastian Rivera <sebastian.rivera@hashicorp.com>

---------

Co-authored-by: Sebastian Rivera <sebastian.rivera@hashicorp.com>
2025-02-04 11:46:53 -08:00
Brandon Croft
e5a435ab0f
remote: retry workspace unlock on retryable errors (#36191) 2024-12-11 10:21:41 +00:00
Sarah French
0daf6e8f01
Update comments about Backend interface implementation, add implementation assertion (#36168)
* Update comments to reflect that the backend.Enhanced interface no longer exists

* Add compile-time check that Local backend implements backendrun.OperationsBackend
2024-12-06 17:05:38 +00:00
James Bardin
2cbb6bf92f udpate code which was failing staticckeck
Some updates to staticcheck were catching more errors. Most of these
were format functions without a format string, but rather than adding
more exceptions I just fixed them all. This did also catch some
incorrectly wrapped errors.
2024-09-11 14:09:12 -04:00
Sebastian Rivera
015f795ff0 Rebrand Terraform Cloud to HCP Terraform 2024-04-23 16:12:59 -04:00
Martin Atkins
88cb4aeea3 backendrun: Separate the types/etc for backends that support operations
We previously had all of the types and helpers for all kinds of backends
together in package backend. That kept things relatively simple, but it
also meant that the majority of backends that only deal with remote state
storage ended up still indirectly depending on the entire Terraform modules
runtime, configuration loader, etc, etc, which brings into scope a bunch
of external dependencies that the remote state backends don't really need.

Since backends that support operations are a rare exception, we'll move the
types and helpers for those into a separate package "backendrun", and
then the main package backend can have a much more modest set of types and,
more importantly, a modest set of dependencies on other packages in this
codebase.

This is part of an ongoing effort to reduce the exposure of Terraform Core
and CLI code to the remote backends and vice-versa, so that in the long
run we can more often treat them as separate for dependency maintenance
purposes.
2024-03-12 08:44:17 -07:00
Lauren
6d9b3b2cd7 call Colorize() on CLI output 2024-01-17 17:18:42 -05:00
Jamie Finnigan
05b0bdac99
adopt hashicorp/cli fork of mitchellh/cli (#34429) 2023-12-20 11:04:10 +00:00
Martin Atkins
b0b8d4aa6f states: Only track root module output values
For a very long time we've had an annoying discrepancy between the
in-memory state model and our state snapshot format where the in-memory
format stores output values for all modules whereas the snapshot format
only tracks the root module output values because those are all we
actually need to preserve between runs.

That design wart was a result of us using the state both as an internal
and an external artifact, due to having nowhere else to store the
transient values of non-root module output values while Terraform Core
does its work.

We now have namedvals.State to internally track all of the throwaway
results from named values that don't need to persist between runs, so now
we'll use that for our internal work instead and reserve the states.State
model only for the data that we will preserve between runs in state
snapshots.

The namedvals internal model isn't really designed to support enumerating
all of the output values for a particular module call, but our expression
evaluator currently depends on being able to do that and so we have a
temporary inefficient implementation of that which just scans the entire
table of values as a stopgap just to avoid this commit growing even larger
than it already is. In a future commit we'll rework the evaluator to
support the PartialEval mode and at the same time move the responsiblity
for enumerating all of the output values into the evaluator itself, since
it should be able to determine what it's expecting by analyzing the
configuration rather than just by trusting that earlier evaluation has
completed correctly.

Because our legacy state string serialization previously included output
values for all modules, some of our context tests were accidentally
depending on the implementation detail of how those got stored internally.
Those tests are updated here to test only the data that is a real part
of Terraform Core's result, by ensuring that the relevant data appears
somewhere either in a root output value or in a resource attribute.
2023-12-07 09:56:36 -08:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
Nick Fagerlund
f9d937a4dd Apply a confirmable run when given a saved cloud plan (#33270)
It displays a run header with link to web UI, like starting a new plan does, then confirms the run
and streams the apply logs. If you can't apply the run (it's from a different workspace, is in an
unconfirmable state, etc. etc.), it displays an error instead.

Notable points along the way:

* Implement `WrappedPlanFile` sum type, and update planfile consumers to use it instead of a plain `planfile.Reader`.

* Enable applying a saved cloud plan

* Update TFC mocks — add org name to workspace, and minimal support for includes on MockRuns.ReadWithOptions.
2023-07-24 14:12:40 -04:00
Brandon Croft
c1a730314d
Relocate localterraform.com aliasing to backend configurators
Previously, remote and cloud backends would automatically alias localterraform.com as the configured hostname during configuration. This turned out to be an issue with how backends could potentially be used within the builtin terraform_remote_state data source. Those data sources each configure the same service discovery with different targets for localterraform.com, and do so simultaneously, creating an occasional concurrent map read & write panic when multiple data sources are defined.

localterraform.com is obviously not useful for every backend configuration. Therefore, I relocated the alias configuration to the callers, so they may specify when to use it. The modified design adds a new method to backend.Enhanced to allow configurators to ask which aliases should be defined.
2023-07-21 09:55:41 -06:00
Liam Cervante
6882dd9530
testing framework: introduce test command optional flags (#33504)
* testing framework: introduce test command optional flags

* address consistency checks
2023-07-19 10:07:46 +02:00
James Bardin
cf5ebaf685 s/Schemas/ProviderSchema/ 2023-07-06 10:37:35 -04:00
James Bardin
36d34135ad replace remaining types in tests 2023-07-06 10:37:35 -04:00
Brandon Croft
19b17ad0a2
remote: when saving state, create a pending state version then upload 2023-06-21 12:30:33 -06:00
CJ Horton
8a3f4e903b generating configuration is not allowed with the remote backend 2023-05-31 11:51:39 -07:00
Martin Atkins
efdc6e52bc cloud: Skip intermediate state snapshots in Terraform Cloud/Enterprise
We've seen some concern about the additional storage usage implied by
creating intermediate state snapshots for particularly long apply phases
that can arise when managing a large number of resource instances together
in a single workspace.

This is an initial coarse approach to solving that concern, just restoring
the original behavior when running inside Terraform Cloud or Enterprise
for now and not creating snapshots at all.

This is here as a solution of last resort in case we cannot find a better
compromise before the v1.5.0 final release. Hopefully a future commit
will implement a more subtle take on this which still gets some of the
benefits when running in a Terraform Enterprise environment but in a way
that will hopefully be less concerning for Terraform Enterprise
administrators.

This does not affect any other state storage implementation except the
Terraform Cloud integration and the "remote" backend's state storage when
running inside a TFC/TFE-driven remote execution environment.
2023-05-23 15:25:48 -07:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Alisdair McDiarmid
0ffdd07980 Fix goimports discrepancies 2023-04-26 14:33:13 -04:00
Glenn Sarti
7e2e834aff
Emit warnings for certain run events in cloud backend (#33020)
The cloud backend, which communicates with TFC like APIs, can create
runs which may have one more configuration parameters altered. These
alterations are emitted as run-events on the run so that API clients
can consume and display them to users. This commit adds a step in
plan operation to query the run-events once a run is created and then
emit specific run-event descriptions to the console as warnings for
the user.
2023-04-17 08:53:47 -07:00
Brandon Croft
81a4e5ae44
Backport support for generic hostname to backend/remote 2023-01-31 15:10:53 -07:00
Jarrett Spiker
1dafd7c0b1 Fix test compilation errors caused by interface change 2022-11-21 14:35:33 -05:00
Jarrett Spiker
060255a9d5 Use safe or force workspace delete for cloud backend 2022-11-21 14:35:33 -05:00
Anna Winkler
d72911a640 Save detailed type outputs to JSONStateOutputs 2022-07-22 10:28:20 -06:00
Anna Winkler
22c121df86
Bump compatibility version to 1.3.0 for terraform core release (#30988)
* Bump compatibility version to 1.3.0 for terraform core release

Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
2022-05-03 12:28:41 -06:00
Keith Clawson
23dffee568 Always use token in backend config when provided 2022-04-22 14:01:00 -04:00
Luces Huayhuaca
bdc7d8c0a1
Upgrade go-tfe dependency to use 1.0 version. It contains breaking changes, so we are updating method signatures, method names and the type of optional parameters, as needed. (#30626) 2022-03-23 13:58:47 -07:00
Theo Chupp
d15a2bc024
fix: local variables should not be overridden by remote variables during terraform import (#29972)
* fix: local variables should not be overridden by remote variables during `terraform import`

* chore: applied the same fix in the 'internal/cloud' package

* backport changes from cloud package to remote package

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
Co-authored-by: uturunku1 <luces.huayhuaca@gmail.com>
2022-03-15 14:42:11 -07:00
Chris Arcand
779c958fbf cloud: Add streamlined 'remote' backend state migration path
For Terraform Cloud users using the 'remote' backend, the existing
'pattern' prompt should work just fine - but because their workspaces
are already present in TFC, the 'migration' here is really just
realigning their local workspaces with Terraform Cloud. Instead of
forcing users to do the mental gymnastics of what it means to migrate
from 'prefix' - and because their remote workspaces probably already exist and
already conform to Terraform Cloud's naming concerns - streamline the
process for them and calculate the necessary pattern to migrate as-is,
without any user intervention necessary.
2021-11-03 15:07:33 -05:00
James Bardin
81e709d185
Merge pull request #29825 from hashicorp/jbardin/no-panicwrap
Remove the use of panicwrap in the Terraform CLI
2021-10-29 14:41:05 -04:00
Chris Arcand
1791b71196 cloud: TestCloud_backendWithTags
Implementing this test was quite a rabbithole, as in order to satisfy
backendTestBackendStates() the workspaces returned from
backend.Workspaces() must match exactly, and the shortcut taken to test
pagination in 3cc58813f0 created an
impossible circumstance that got plastered over with the fact that
prefix filtering is done clientside, not by the API as it should be.

Tagging does not rely on clientside filtering, and expects that the
request made to the TFC API returns exactly those workspaces with the
given tags.

These changes include a better way to test pagination, wherein we
actually create over a page worth of valid workspaces in the mock client
and implement a simplified pagination behavior to match how the TFC API
actually works.
2021-10-28 19:29:10 -05:00
Chris Arcand
471dd479e8 Update go-tfe to 26689e
These changes include additions to fulfill the interface for the client
mock, plus moving all that logic (which needn't be duplicated across
both the remote and cloud packages) over to the cloud package under a
dedicated mock client file.
2021-10-28 19:29:10 -05:00
James Bardin
d03a037567 insert panic handlers 2021-10-28 11:51:39 -04:00
Martin Atkins
bee7403f3e command/workspace_delete: Allow deleting a workspace with empty husks
Previously we would reject attempts to delete a workspace if its state
contained any resources at all, even if none of the resources had any
resource instance objects associated with it.

Nowadays there isn't any situation where the normal Terraform workflow
will leave behind resource husks, and so this isn't as problematic as it
might've been in the v0.12 era, but nonetheless what we actually care
about for this check is whether there might be any remote objects that
this state is tracking, and for that it's more precise to look for
non-nil resource instance objects, rather than whole resources.

This also includes some adjustments to our error messaging to give more
information about the problem and to use terminology more consistent with
how we currently talk about this situation in our documentation and
elsewhere in the UI.

We were also using the old State.HasResources method as part of some of
our tests. I considered preserving it to avoid changing the behavior of
those tests, but the new check seemed close enough to the intent of those
tests that it wasn't worth maintaining this method that wouldn't be used
in any main code anymore. I've therefore updated those tests to use
the new HasResourceInstanceObjects method instead.
2021-10-13 13:54:11 -07:00