Commit Graph

71 Commits

Author SHA1 Message Date
Andrei Ciobanu
ca3c9f7388 Extract TF_PROVIDER_DOWNLOAD_RETRY env var from the getproviders package (#3338)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-10-13 10:00:19 +03:00
Diógenes Fernandes
197135b4af fix internal/command tests by triggering garbage collection (#3282)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-17 09:06:57 -03:00
Martin Atkins
5fa35c5601 backend+command: Alias names for backend types
This introduces the concept of "backend aliases", which are alternative
names that can be used to refer to a given backend.

Each backend type has one canonical name and zero or more alias names. The
"backend" block in the root module can specify either a canonical backend
type or an alias, but internally OpenTofu will always track the backend
type using its canonical name.

In particular, the following are all true when the configuration specifies
an alias instead of a canonical backend type:
- The "tofu init" output includes a brief extra message saying which
  backend type OpenTofu actually used, because that is the name that we'd
  prioritize in our documentation and so an operator can use the canonical
  type to find the relevant docs when needed.
- The .terraform/terraform.tfstate file that tracks the working directory's
  currently-initialized backend settings always uses the canonical backend
  type, and so it's possible to freely switch between aliases and canonical
  without "tofu init" thinking that a state migration might be needed.
- Plan files similarly use the canonical backend type to track which
  backend was active when the plan was created, which doesn't have any
  significant user-facing purpose, but is consistent with the previous
  point since the settings in the plan file effectively substitute for
  the .terraform/terraform.tfstate file when applying a saved plan.
- The terraform_remote_state data source in the provider
  terraform.io/builtin/terraform accepts both canonical and alias in its
  backend type argument, treating both as equivalent for the purpose of
  fetching the state snapshot for the configured workspace.

The primary motivation for this new facility is to allow the planned
"oracle_oci" backend to have an alias "oci" to allow writing configurations
that are cross-compatible with HashiCorp Terraform, since that software
has chosen to have unqualified OCI mean Oracle's system, whereas OpenTofu
has previously established that unqualified OCI means "Open Container
Initiative" in our ecosystem.

In particular, this design makes it possible in principle to bring an
existing Terraform configuration specifying backend "oci" over to OpenTofu
without modifications, and then to optionally switch it to specifying
backend "oracle-oci" at a later time without a spurious prompt to migrate
state snapshots to the same physical location where they are already
stored.

This commit doesn't actually introduce any aliases and therefore doesn't
have any tests for the new mechanism because our backend system uses a
global table that isn't friendly to mocking for testing purposes. I've
tested this manually using a placeholder alias to have confidence that it
works, and I expect that a subsequent commit introducing the new
"oracle_oci" backend will also introduce its "oci" alias and will include
tests that cover use of the alias and migration from the alias to the
canonical name and vice-versa.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-11 11:33:53 -07:00
Diógenes Fernandes
22910f2b01 Adapt statelocker usage to Windows (#3206)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-06 10:47:17 -03:00
Diógenes Fernandes
4c2b1df36e fix TestApply* and TestInit* on Windows (#3203)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-08-28 19:55:45 -03:00
Martin Atkins
a1ba3e24aa tofu: EvalContext expression evaluation takes context.Context (#2937)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-19 10:46:31 +01:00
Martin Atkins
00dc728aea getproviders: context.Context for source constructor functions
This completes some of the missing connections for contexts in the provider
source codepaths by introducing context.Context parameters and wiring them
through so we can eliminate a few more context.TODO() placeholders.

For consistency's sake this adds context.Context to all four of the
getproviders.Source implementations that directly interact with stuff
outside of OpenTofu (network services or filesystem), even though not
all of them currently make use of it, just because interactions with
outside stuff tends to encourage cross-cutting concerns like logging and
tracing and so this ensures we have contexts propagated in there for such
future uses.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-13 08:22:47 -07:00
Martin Atkins
d2bef1fd47 Adopt OpenTofu's own "svchost" module
Previously we were using a third-party library, but that doesn't have any
support for passing context.Context through its API and so isn't suitable
for our goals of adding OpenTelemetry tracing for all outgoing network
requests.

We now have our own fork that is updated to use context.Context. It also
has a slightly reduced scope no longer including various details that
are tightly-coupled to our cliconfig mechanism and so better placed in the
main OpenTofu codebase so we can evolve it in future without making
lockstep library releases.

The "registry-address" library also uses svchost and uses some of its types
in its public API, so this also incorporates v2 of that library that is
updated to use our own svchost module.

Unfortunately this commit is a mix of mechanical updates to the new
libraries and some new code dealing with the functionality that is removed
in our fork of svchost. The new code is primarily in the "svcauthconfig"
package, which is similar in purpose "ociauthconfig" but for OpenTofu's
own auth mechanism instead of the OCI Distribution protocol's auth
mechanism.

This includes some additional plumbing of context.Context where it was
possible to do so without broad changes to files that would not otherwise
have been included in this commit, but there are a few leftover spots that
are context.TODO() which we'll address separately in later commits.

This removes the temporary workaround from d079da6e9e, since we are now
able to plumb the OpenTelemetry span tree all the way to the service
discovery requests.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-06-12 09:37:59 -07:00
Christian Mesh
aaed9f83e4 Fix linting in internal/command (#2798)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-05-15 07:39:11 -04:00
Martin Atkins
65a0f7a656 registry+getproviders: Registry client policy centralized in main
The primary reason for this change is that registry.NewClient was
originally imposing its own decision about service discovery request
policy on every other user of the shared disco.Disco object by modifying
it directly.

We have been moving towards using a dependency inversion style where
package main is responsible for deciding how everything should be
configured based on global CLI arguments, environment variables, and the
CLI configuration, and so this commit moves to using that model for the
HTTP clients used by the module and provider registry client code.

This also makes explicit what was previously hidden away: that all service
discovery requests are made using the same HTTP client policy as for
requests to module registries, even if the service being discovered is not
a registry. This doesn't seem to have been the intention of the code as
previously written, but was still its ultimate effect: there is only one
disco.Disco object shared across all discovery callers and so changing its
configuration in any way changes it for everyone.

This initial rework is certainly not perfect: these components were not
originally designed to work in this way and there are lots of existing
test cases relying on them working the old way, and so this is a compromise
to get the behavior we now need (using consistent HTTP client settings
across all callers) without disrupting too much existing code.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-12 10:50:17 -07:00
Martin Atkins
47875921a1 httpclient: Add OTel tracing automatically when needed (#2772)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-09 10:16:38 +01:00
James Humphries
6d3aed0e8f [OpenTelemetry] Add module init tracing (#2711)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-05-01 14:15:03 +01:00
Oleksandr Levchenkov
82d71e50e8 add deprecation warnings support for terraform_remote_state (#2679)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-04-25 12:26:28 +03:00
Martin Atkins
1b9b5cea79 Use modern helpers from Go's testing.T API (#2692)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-23 07:48:41 -04:00
Martin Atkins
da1c39260b command: Improve reliability of module install cancel tests
We previously had two tests of how the module installer responds to
cancellation (e.g. SIGINT) which were flakey because they tried to rely
on the cancellation being detected at some arbitrary point before the
module installer attempted to make a request, which isn't guaranteed in
practice because our interrupt mechanism only aims to cause OpenTofu to
exit "soon", with no guarantee about how much ongoing progress it will
make before it does.

To make these tests more robust, we'll now instead tell the module
installer to install from a real HTTP server that is intentionally designed
to stall the client by accepting its request but then just leaving the
connection open without responding.

This means that we can now test the more realistic situation of the cancel
signal being triggered after a slow request is already in progress, and
be sure that we're definitely sending the cancel signal at a moment that
matches that intention.

This is similar to a strategy we previously took to improve the reliability
of the tests for cancellation of the _provider_ installer, in
TestInit_cancelProviders. However, our provider installer version of this
used an intentionally-stalling implementation of getproviders.Source
instead of running a real server because the provider installer is designed
to support configurable installation methods, while the module installer
is not: its policy about what module source types are accepted is
hard-coded in package getproviders, at least for now.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-18 09:11:22 -07:00
Martin Atkins
6ab72535e9 initwd: NewModuleInstaller takes package fetcher as dependency arg
Earlier work started to reshape this API to follow the dependency inversion
style, but didn't go so far as treating the package fetcher as an argument
because so far it hasn't offered any customizable policy anyway.

In future commits we will be introducing some policy arguments for the
package fetcher, and so this is some preparation work where we move the
responsibility for calling getmodules.NewPackageFetcher() out into the
caller of initwd.NewModuleInstaller().

This changes the API consumed by a bunch of unit testing helpers, so
splitting this out into its own commit should hopefully make future
commits more focused. The module installer now explicitly supports being
instantiated without a registry client or a remote package fetcher and
will in that case return an error if it's asked to install from anywhere
other than local relative directories. Most of our existing tests are
comfortable running under that constraint and so will not need any further
work in later commits that will change the signature of
getmodules.NewPackageFetcher.

However, a couple tests in package initwd _itself_ were making use of the
esoteric legacy support for treating an absolute filesystem path as a funny
sort of remote source, and so for now those will instantiate their own
package fetcher. Future commits that change the NewPackageFetcher signature
will need to offer a concession for those two tests.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-16 07:52:51 -07:00
Diógenes Fernandes
832310fb74 fix: remove elapsed_seconds check on the golden reference (#2565)
Signed-off-by: Diógenes Fernandes <diofeher@gmail.com>
2025-03-06 09:03:46 -03:00
Christian Mesh
fd775f0fe3 Implement Provider for_each (#2105)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: ollevche <ollevche@gmail.com>
Co-authored-by: Ronny Orot <ronny.orot@gmail.com>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2024-11-05 18:08:23 -05:00
Nathan Baulch
9b7bec31b4 Another batch of minor typos (#1953)
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
2024-09-09 07:51:39 -04:00
Christian Mesh
8f8e0aa4aa Static Evaluation Base, Module Sources, Backend Config (#1718)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Christian Mesh <cristianmesh1@gmail.com>
Co-authored-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2024-06-24 09:13:07 -04:00
Alex Ott
522a859cf0 Write state using compact JSON representation (#1647)
Signed-off-by: Alex Ott <alexott@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2024-05-21 15:04:10 -04:00
Christian Mesh
2f5dcd5c0a Integrate Encryption into State Backends (#1288)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-04 09:25:14 -05:00
Christian Mesh
ac3ed86617 Integrate encryption into plan serialization (#1292)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2024-03-04 09:00:29 -05:00
namgyalangmo
cb2e9119aa Update copyright notice (#1232)
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
2024-02-08 09:48:59 +00:00
Christian Mesh
abd324ea7c Revert "Fixes #898: Replace hashicorp and terraform references" (#995) 2023-12-11 15:10:03 -05:00
Janos
15bef1428a Fixes #898: Replace hashicorp and terraform references (#973)
Signed-off-by: Janos Bonic <86970079+janosdebugs@users.noreply.github.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-08 08:03:09 -05:00
James Humphries
9c24b6183a Revert PRs that introduced propogating contexts (#835)
Co-authored-by: Dmitry Kisler <admin@dkisler.com>
2023-11-08 21:09:14 +00:00
Marcin Wyszynski
bda32938e4 Make backend.ConfigSchema accept a context (#776)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2023-10-24 13:14:01 +02:00
RLRabinowitz
e0ecd2ebb3 Use registry.opentofu.org as the default registry (#379)
Signed-off-by: RLRabinowitz <rlrabinowitz2@gmail.com>
2023-10-03 10:49:38 +03:00
Lars Lehtonen
23ad929d2f internal/command: wrap formatted test errors (#596) 2023-09-27 11:19:16 +03:00
Dmitry Kisler
a127607a85 Rename terraform to tofu in GoString method and docstrings (#576)
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
2023-09-26 19:09:27 +02:00
Yaron Yarimi
487d9bc6a4 Rename multiple packages to OpenTofu (addrs, backend, command) (#506) 2023-09-21 15:38:46 +03:00
Yaron Yarimi
c6aeb9e836 Rename legacy package to OpenTofu (#493) 2023-09-20 16:10:32 +03:00
Yaron Yarimi
794e3413bb Rename opentf package to tofu (#466) 2023-09-20 15:16:53 +03:00
Yaron Yarimi
c8acedd885 Rename github.com/placeholderplaceholderplaceholder/opentf to github.com/opentofu/opentofu (#461) 2023-09-20 14:35:35 +03:00
Lars Lehtonen
bad4d48f6d internal/command: deprecate ioutil (#318) 2023-09-07 19:53:12 +03:00
RLRabinowitz
90dce4dd3c go fmt, change import order 2023-08-28 14:22:54 +03:00
RLRabinowitz
42e7c5b25c Replace internal/terraform -> internal/opentf 2023-08-28 14:21:34 +03:00
RLRabinowitz
19239936a4 Rename internal/legacy/terraform to internal/legacy/opentf 2023-08-27 15:58:38 +03:00
Marcin Białoń
34b3043be4 Update user-facing references to Terraform in internal/command/views (#88)
* Update `internal/command/views`

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

* fix tests

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

* Fix some tests.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Fix some tests.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* update tests golden files

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

* Fix tests

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

* Fix tests

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

* Fix tests

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>

---------

Signed-off-by: Marcin Białoń <mbialon@spacelift.io>
Signed-off-by: Jakub Martin <kubam@spacelift.io>
Co-authored-by: Jakub Martin <kubam@spacelift.io>
2023-08-23 14:49:37 +02:00
Kuba Martin
ebcf7455eb Rename root module name. (#4)
* Rename module name from "github.com/hashicorp/terraform" to "github.com/placeholderplaceholderplaceholder/opentf".

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Gofmt.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Regenerate protobuf.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Fix comments.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo issue and pull request link changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo comment changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Fix comment.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* Undo some link changes.

Signed-off-by: Jakub Martin <kubam@spacelift.io>

* make generate && make protobuf

Signed-off-by: Jakub Martin <kubam@spacelift.io>

---------

Signed-off-by: Jakub Martin <kubam@spacelift.io>
2023-08-17 14:45:11 +02:00
James Bardin
ea1144995f update callers of InstallModules
Update callers of InstallModules and have `get` return only install
errors.
2023-08-07 15:22:02 -04: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
Liam Cervante
d5fed58fc5 plannable import: write generated config to out flag (#33186)
* plannable import: write generated config to out flag

* Add example command to diagnostic
2023-05-12 23:05:00 +01:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Alisdair McDiarmid
8df065a2fe initwd: Switch from earlyconfig to configs
This is a mostly mechanical refactor with a handful of changes which
are necessary due to the semantic difference between earlyconfig and
configs.

When parsing root and descendant modules in the module installer, we now
check the core version requirements inline. If the Terraform version is
incompatible, we drop any other module loader diagnostics. This ensures
that future language additions don't clutter the output and confuse the
user.

We also add two new checks during the module load process:

* Don't try to load a module with a `nil` source address. This is a
  necessary change due to the move away from earlyconfig.

* Don't try to load a module with a blank name (i.e. `module ""`).
  Because our module loading manifest uses the stringified module path
  as its map key, this causes a collision with the root module, and a
  later panic. This is the bug which triggered this refactor in the
  first place.
2023-03-06 09:14:28 -05:00
Megan Bang
72ba8a869e removes EnableForcePush and other unrelated code 2022-09-02 14:49:25 -05:00
Megan Bang
b504dd1489 update from code consistency checks 2022-08-29 14:29:07 -05:00
Megan Bang
00cc1ea26d refactor getSchemas 2022-08-29 11:10:03 -05:00
Megan Bang
12e3560d21 check for cloud integration mode 2022-08-26 15:32:18 -05:00