Commit graph

92 commits

Author SHA1 Message Date
Radek Simko
0fe906fa8c make copyrightfix 2026-02-17 13:56:34 +00:00
Daniel Banck
cc30a8cf1d
Fix crash when showing a cloud plan without having a cloud backend (#37751)
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
* Fix crash when showing a cloud plan without a cloud backend

* Add changelog
2025-10-10 10:51:00 +02:00
Daniel Banck
1ac8497994
Add support for Terraform Search in the cloud backend (TF-25935) (#37479) 2025-09-15 13:21:05 +02: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
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
Affinito Alessandro
71093fd195
Update backend.go minor wording fix (#37054) 2025-05-15 08:30:18 +00:00
UKEME BASSEY
a732b606a1 make hostname and token optional, read token from cli file 2025-05-12 17:10:40 -04:00
UKEME BASSEY
509be4ea1b add stacks plugin 2025-04-28 12:57:14 -04: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
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
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
45c38a6469
Merge branch 'main' into b/fix-retry-messages-in-cloud-backend-json 2024-11-08 14:04:13 -06:00
Brandon Croft
f41d5a5954
Fix typo 2024-11-08 10:40:52 -07:00
Brandon Croft
ad96f4161c
Prefer kv tags when tags defined as set
This will prevent duplicate workspace tags from being created when set tags are matched using kv bindings, or vice-versa.
2024-11-08 10:40:52 -07:00
Bruno Schaatsbergen
1e80cd8e10
cloud: clarify reason for guard statement
Added a comment to explain the rationale behind the guard statement, which prevents potential nil errors during backend initialization and retryLogHook call.

Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-04 18:04:08 +01:00
Bruno Schaatsbergen
09ddfc039f
docs: add a comment to the View field
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-04 16:31:05 +01:00
Bruno Schaatsbergen
d8bfe7a80b
cloud: Initialize a new cloud view in the backend to render messages based on view type.
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-01 16:18:26 +01:00
Bruno Schaatsbergen
a90930427a
chore: remove the retrylog hook from the init view
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-01 12:45:02 +01:00
Bruno Schaatsbergen
f9797595e3
chore: initialize new view in meta backend
Signed-off-by: Bruno Schaatsbergen <git@bschaatsbergen.com>
2024-11-01 11:44:32 +01:00
Brandon Croft
9d0133a541
Fix non-string elements in tags schema 2024-10-29 06:47:21 -06:00
Brandon Croft
e87335a972
cloud: Allows object tag schema for selecting kv tagged workspaces
When key-value tags are enabled and used in the workspace, users may
define the tags attribute as a map of strings in the cloud block in order
to more precicely match workspaces using those tags.
2024-10-26 08:04:09 -06:00
Sebastian Rivera
fb06df80fc Refactor generalError to use appName
In order to inject the value of TFP-AppName, we will need a backend.Cloud ref available
to use. This change modifies generalError as a receiver method for backend.Cloud types.
We also duplicate this method as a receiver for TestSuiteRunner, since TestSuiteRunner does
not have a backend.Cloud ref.
2024-04-23 16:12:59 -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
Nick Fagerlund
c02533c889 Cloud backend: Cache service discovery in public ServicesHost field
Most of the time, the Cloud backend is the only thing that needs to read the
results of this discovery, and the only thing it cares about is the URL to the
TFE v2 API service. However:

- Other things might need to know about services that your TFC instance
  provides, including services other than the TFE v2 API.

- There's a lot of complexity involved in determining which TFC instance you
  should be talking to (as well as the credentials for contacting it, the
  default org/workspace/project you're interested in, etc.), and it makes sense
  to leave the Cloud backend as the owner of that complexity rather than
  re-implement it in other potential consumers!

So, since other TFC consumers will likely be configuring a Cloud backend to get
their information anyway, might as well cache the known services so we don't
have to repeat the discovery request.

As part of this commit, note that I removed some code that swallowed a
particular error during discovery. This was vestigial behavior that came over
from the `remote` backend, but we were no longer performing the second part of
the process (i.e. producing a more descriptive error in place of the one we
swallowed). See https://github.com/hashicorp/terraform/pull/19659 for discussion
about the original intent.
2024-01-04 14:42:36 -08:00
Nick Fagerlund
054fdf93cf Publicize Cloud's token and organization fields
Sorry... I need them.
2024-01-04 14:42:36 -08:00
Jamie Finnigan
05b0bdac99
adopt hashicorp/cli fork of mitchellh/cli (#34429) 2023-12-20 11:04:10 +00:00
Nick Fagerlund
1ae8643201 Refactor (*Cloud).Configure, and fix TF_WORKSPACE bug
This fixes issue #33976, introduced in https://github.com/hashicorp/terraform/pull/33489,
which broke the intended behavior of specifying the active workspace via the
TF_WORKSPACE variable when using a tag-based workspace mapping.

Now that all the default and fallback value behaviors are cleanly isolated in a
function, this whole flow can be a bit simpler.

- Remove `setConfigurationFields`. Instead, `Configure` can just trade its Cty
  `obj` for a dumb struct and set a couple fields from it. The
  `TF_FORCE_LOCAL_BACKEND` handling can just join the relevant section of
  Configure directly.
- Radically chop down PrepareConfig. It turns out we were violating the interface
  contract, which says PrepareConfig shouldn't trouble itself with the shell
  environment and fallback values... So, don't do that.
2023-10-06 16:58:30 -07:00
Nick Fagerlund
8e1b65ebc3 Add resolveCloudConfig function
This will be the central location for everything involving combining environment
variables with a `cloud` config block to obtain a final cloud config. It returns
a plain Go value (so that nothing downstream of it ever needs to mess with Cty
types), and doesn't mutate any fields on the backend, so it has a nice firm
boundary of responsibilities.

Also, it's quite a bit more pedantic and explicit about HOW the environment
variables get consulted, in the hope of reducing future misunderstandings about
our UI-level expectations.
2023-10-06 16:55:43 -07:00
Radek Simko
1d1dcc4b8b
cloud: Fix typo & align 'project' field description (#33946) 2023-10-03 16:10:35 +01:00
Liam Cervante
ffbcaf8bef
Implement TFC integration for private module registry test runs (#33710)
* implement module testing via TFC

* ready for review

* fix static checks

* licence headers
2023-09-14 09:01:25 +02:00
Brandon Croft
6500b7c740
change visibility of cloud.Backend Hostname field 2023-08-14 14:07:20 -06:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
Karl Kirch
d7e07e66fc
Add ability to specify Terraform Cloud Project in cloud block (#33489)
* Add ability to specify Terraform Cloud Project in cloud block

Adds project configuration to the workspaces section of the cloud block.
Also configurable via the `TF_CLOUD_PROJECT` environment variable.
When a project is configured, the following behaviors will occur:
- `terraform init` with workspaces.name configured will create the workspace in the given project
- `terraform workspace new <name>` with workspaces.tags configured will create workspaces in the given project
- `terraform workspace list` will list workspaces only from the given project

The following behaviors are NOT affected by project configuration
- `terraform workspace delete <name>` does not validate the workspace's inclusion in the given project
- When initializing a workspace that already exists in Terraform Cloud, the workspace's parent project is NOT validated against the given project

Adds tests for cloud block configuration of project
Update changelog

* Update cloud block docs

* Fix typos and changelog entry

* Add speculative project lookup early in the cloud initialize process to capture inability to find a configured project

* Add project config for alias test
2023-08-01 13:43:07 -07: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
Brandon Croft
86eed095b3
Rename disableIntermediateSnapshots > enableIntermediateSnapshots 2023-05-30 12:35:23 -06:00
Sebastian Rivera
d03fd37ee6 Add interval header check to enable snapshots 2023-05-26 15:01:05 -04:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Sebastian Rivera
71dac9bf5e Add token field to cloud backend 2023-02-10 16:58:14 -05:00
Sebastian Rivera
de574ae6d4
Initial implementation of structured logging in cloud backend (#32504)
* Implementation of structured logging.

These are the changes that enable the cloud backend to consume
structured logs and make use of the new plan renderer. This will enable
CLI-driven runs to view the structured output in the Terraform Cloud UI.

* Cloud structured logging unit tests

* Remove deferred logs logic, fix minor issues

Color formatting fixes, log type stop lists, default behavior for logs
that are unknown

* Use service disco path in redacted plan url
2023-02-09 13:35:48 +01:00
Brandon Croft
81a4e5ae44
Backport support for generic hostname to backend/remote 2023-01-31 15:10:53 -07:00
Brandon Croft
2fe3a23094
Add generic hostname (localterraform.com) support to cloud backend
Aliases the backend hostname config as "localterraform.com" and duplicates any existing auth credentials during cloud backend configuration.
2023-01-30 17:21:24 -07:00
Anna Winkler
3cc7e55465
Expand error when discovery document request fails (#32394)
* Expand error when discovery document request fails.
* Use error type from svchost library
* Use svchost v0.0.1
2023-01-24 15:19:12 -07:00
Jarrett Spiker
c16d726f2c Succeed cloud workspace deletion if the workspace does not exist 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
Megan Bang
dbf99f17b1 add test and removed backend state from cloud 2022-08-29 16:26:06 -05:00
Megan Bang
bddf6a9b34 updating to use the latest version of cloud/state.go and just pass schemas along to PersistState in the remote state 2022-08-29 14:13:18 -05:00
Megan Bang
021f1f69e9 updates to cloud state 2022-08-26 14:18:34 -05:00
Martin Atkins
783a07d9e8 build: Use Go 1.19
Go 1.19's "fmt" has some awareness of the new doc comment formatting
conventions and adjusts the presentation of the source comments to make
it clearer how godoc would interpret them. Therefore this commit includes
various updates made by "go fmt" to acheve that.

In line with our usual convention that we make stylistic/grammar/spelling
tweaks typically only when we're "in the area" changing something else
anyway, I also took this opportunity to review most of the comments that
this updated to see if there were any other opportunities to improve them.
2022-08-22 10:59:12 -07:00
Brandon Croft
e1fa690879
style: goimports fixes 2022-07-25 14:51:34 -06:00