63 Commits

Author SHA1 Message Date
Diógenes Fernandes
767dd7a2fa fix: DirFromModule related tests on Windows (#3289)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-20 15:51:29 -03:00
Diógenes Fernandes
e8eeb1334c Adapt TestInit hashes to work on Windows (#3208)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-09 11:59:40 -03: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
Martin Atkins
67a5cd0911 statemgr+remote: context.Context parameters
This extends statemgr.Persistent, statemgr.Locker and remote.Client to
all expect context.Context parameters, and then updates all of the existing
implementations of those interfaces to support them.

All of the calls to statemgr.Persistent and statemgr.Locker methods outside
of tests are consistently context.TODO() for now, because the caller
landscape of these interfaces has some complications:

1. statemgr.Locker is also used by the clistate package for its state
   implementation that was derived from statemgr.Filesystem's predecessor,
   even though what clistate manages is not actually "state" in the sense
   of package statemgr. The callers of that are not yet ready to provide
   real contexts.

   In a future commit we'll either need to plumb context through to all of
   the clistate callers, or continue the effort to separate statemgr from
   clistate by introducing a clistate-specific "locker" API for it
   to use instead.

2. We call statemgr.Persistent and statemgr.Locker methods in situations
   where the active context might have already been cancelled, and so we'll
   need to make sure to ignore cancellation when calling those.

   This is mainly limited to PersistState and Unlock, since both need to
   be able to complete after a cancellation, but there are various
   codepaths that perform a Lock, Refresh, Persist, Unlock sequence and so
   it isn't yet clear where is the best place to enforce the invariant that
   Persist and Unlock must not be called with a cancelable context. We'll
   deal with that more in subsequent commits.

Within the various state manager and remote client implementations the
contexts _are_ wired together as best as possible with how these subsystems
are already laid out, and so once we deal with the problems above and make
callers provide suitable contexts they should be able to reach all of the
leaf API clients that might want to generate OpenTelemetry traces.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-07-10 08:11:39 -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
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
Christian Mesh
11694a6ac0 Alternate approach to linking and locking the global cache (#2708)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-05-08 15:26:46 -04:00
James Humphries
fca652c667 Add context propagation to Command Meta entrypoint methods (#2735)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-04-30 16:28:19 +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
af80d429ab getmodules: NewPackageFetcher now expects an "environment" argument
This continues our work to follow the dependency inversion style for the
"package fetcher" component of the module installer.

Mimicking the existing pattern for providers, package main is now
responsible for instantiating the PackageFetcher and providing it to
the "command" package as a field of command.Meta.

We could potentially go further here and follow dependency inversion style
for _all_ of the special clients needed by the various go-getter getters,
but our primary concern for now is preparing to add a new "getter" for
installation from an OCI Distribution repository, and so we'll leave the
other already-working code unchanged to reduce the risk of this initial
work.

Future commits will actually wire in the implementation details for OCI
Repository access. This commit focuses only on plumbing the necessary
objects through the API layers.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-16 07:52:51 -07:00
Martin Atkins
55855fca70 getproviders: Unify package authentication with hash lock selection
As discussed in opentofu/opentofu#2656, this consolidates the two concerns
of the PackageAuthentication interface into a single function that deals
both with package authentication _and_ with reporting all of the package
hashes that were used to make the authentication decision.

This means that any .zip archive that OpenTofu directly verifies during
installation can now have its hash recorded in the dependency lock file
even if that package didn't come from the provider's origin registry, which
is beneficial when the first installation of a provider comes from a
secondary ("mirror") source because it creates an additional hook by which
that dependency lock file entry can be "upgraded" to be complete in a
future "tofu init" run against the origin registry, or by the
"tofu providers lock" command.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-04-14 08:31:40 -07:00
Sekiranda Hamza
211ec55a30 Skip reading encryption keys on tofu init with -backend=false flag set (#2293)
Signed-off-by: Sekiranda <sekirandahamza@gmail.com>
2024-12-20 10:45:12 +02:00
Andy Hayes
de69070b02 Adds prompt for missing static variables (#2047)
Signed-off-by: Andrew Hayes <andrew.hayes@harness.io>
2024-10-07 18:30:42 +01: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
Burak Şen
7a02fad996 Fix repetitive diagnosis output in init response (#1890)
Signed-off-by: buraksenn <buraksenb@gmail.com>
2024-09-05 07:36:18 -04:00
Nathan Baulch
ea558d9d4b Fix typos (#1905)
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2024-08-29 13:20:33 -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
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
namgyalangmo
cb2e9119aa Update copyright notice (#1232)
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
2024-02-08 09:48:59 +00:00
Jon Johnson
cf0d953dc1 statemgr: Make Filesystem impl "correct" and fast (#579)
Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
2024-01-03 10:28:17 -05:00
Christian Mesh
78464f251a Add a warning when multiple likely forks of a provider are detected (#1009)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-14 12:21:16 -05:00
Christian Mesh
f1a57344bd Improve unclear provider resolver error messages (#1003)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2023-12-12 13:10:16 -05: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
HaojueWang
084c5dfc8b keep init wording consistent in internal/command/init.go (#855)
Signed-off-by: haojue <acewhj@gmail.com>
2023-11-13 10:03:25 -05:00
RLRabinowitz
8967cdcee7 Remove all Terraform Cloud mentions in STDOUTs in the codebase (#703) 2023-10-12 12:07:16 +01: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
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
90f7e5275f Rename multiple packages to OpenTofu (depsfile, genconfig, getmodules) (#499) 2023-09-20 17:05:24 +03:00
Yaron Yarimi
0bac273d1c Rename internal/providercache + internal/refactoring to OpenTofu (#480) 2023-09-20 15:49:50 +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
Kuba Martin
3b5b8ba719 Update internal/command to use OpenTF in user-provided strings. (#87)
* Update `internal/command` to use OpenTF

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

* Fix e2e tests.

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

* Fix e2e tests.

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

* Fix

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

* Rewrite message.

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

---------

Signed-off-by: Jakub Martin <kubam@spacelift.io>
2023-08-24 10:56:05 +02:00
RLRabinowitz
06e4c01f0e Merge pull request #81 from opentffoundation/opentf-user-facing-internal-depsfile
Adapt user-facing usages of terraform in `internal/depsfile`
2023-08-23 13:56:17 +03:00
Marcin Wyszynski
a9a78c000d Adapt user-facing usages of terraform in internal/providercache (#119) 2023-08-23 12:24:02 +02:00
Elbaz
5e83430db2 fix init test 2023-08-23 11:56:26 +03:00
RLRabinowitz
6a2496a075 Fix provider lock tests that rely on the generated text + change some comments 2023-08-23 10:15:49 +03:00
RLRabinowitz
e6007a770f Fix tests in internal/command, relying on the generated text 2023-08-23 10:11:26 +03: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
Liam Cervante
f8b1fe47dd Make config errors more important during init operations (#33628)
* make config errors more important during init operations

* address comments
2023-08-09 11:19:00 +02:00
Liam Cervante
4b34902fab [testing framework] allow tests to define and override providers (#33466)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks

* [testing framework] allow tests to define and override providers
2023-07-10 14:33:15 +01:00
Liam Cervante
5acc95dda7 [Testing Framework] Add module block to test run blocks (#33456)
* [testing framework] prepare for beta phase of development

* [Testing Framework] Add module block to test run blocks
2023-07-10 11:42:05 +01:00
CJ Horton
727e22e762 add tests for init syntax error handling
With the demise of the early config loader, we want to show core
version errors first, followed by backend errors, and only then
show other errors with the configuration.
2023-02-15 21:01:27 -08:00
Liam Cervante
83e84e5477 terraform init: add warning and guidance when lock file is incomplete (#31399)
* terraform init: add warning and guidance when lock file is incomplete

* make the provider list in the warning deterministic

* create installer event for tracking provider lock hashes (#31406)

* create installer event for tracking provider lock hashes

* address comments

* fix tests

* improve error message

* Update internal/command/init.go

Co-authored-by: Martin Atkins <mart@degeneration.co.uk>

Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2022-07-20 13:28:04 +01: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
Martin Atkins
23395a1022 providercache: Discard lock entries for unused providers
Previously we would only ever add new lock entries or update existing
ones. However, it's possible that over time a module may _cease_ using
a particular provider, at which point we ought to remove it from the lock
file so that operations won't fail when seeing that the provider cache
directory is inconsistent with the lock file.

Now the provider installer (EnsureProviderVersions) will remove any lock
file entries that relate to providers not included in the given
requirements, which therefore makes the resulting lock file properly match
the set of packages the installer wrote into the cache.

This does potentially mean that someone could inadvertently defeat the
lock by removing a provider dependency, running "terraform init", then
undoing that removal, and finally running "terraform init" again. However,
that seems relatively unlikely compared to the likelihood of removing
a provider and keeping it removed, and in the event it _did_ happen the
changes to the lock entry for that provider would be visible in the diff
of the provider lock file as usual, and so could be noticed in code
review just as for any other change to dependencies.
2021-12-17 15:30:21 -08:00
Barrett Clark
419676cb69 Cloud integration requires input for migrations
We cannot programmatically migrate workspaces to Terraform Cloud without
prompts, so `-input=false` should not be allowed in those cases.

There are 4 scenarios where we need input from a user to complete
migrating workspaces to Terraform Cloud.

1.) Migrate from a single local workspace to Terraform Cloud

* Terraform config for a local backend. Implicit local (no backend
  specified) is fine.
* `terraform init` and `terraform apply`
* Change the Terraform config to use the cloud block
* `terraform init -input=false`
* You should now see an error message

2.) Migrate from a remote backend with a prefix to Terraform Cloud with
  tags

* Create a workspace in Terraform Cloud manually. The name should
  include a prefix, like "app-one"
* Have the terraform config use `backend "remote"` with a prefix set to
  "app-"
* `terraform init` and `terraform apply`
* Update the Terraform config to use a cloud block with `tags
  = ["app"]`. There should not be a prefix defined in the config now.
* `terraform init -input=false`
* You should now see an error message

3.) Migrate from multiple local workspaces to a single Terraform Cloud
  workspace
* Create one or many local workspaces
* `terraform init` and `terraform apply` in each
* Change the Terraform config to use the cloud block
* `terraform init -input=false`
* You should now see an error message

4.) Migrate to Terraform Cloud and ask for a workspace name
* Create several local workspaces
* `terraform init` and `terraform apply` in each
* Change the Terraform config to use the cloud block with tags
* `terraform init -input=false`
* You should now see an error message
2021-11-23 10:39:42 -06:00