Commit Graph

2570 Commits

Author SHA1 Message Date
Martin Atkins
56df3bf115 provisioner/local-exec: Make "stop" test actually useful on Windows
The changes in the previous commit confirmed that this test was passing
only as a false-positive when running on Windows, because the test was
previously only checking that the provisioner was stopped shortly after
asking it to stop, but that wasn't accounting for the possibility that it
stopped due to an unrelated error.

Windows Command Interpreter does not support semicolon as a command
separator, so on Windows we need to use an ampersand instead.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-08 18:07:39 -07:00
Martin Atkins
594755b765 provisioners/local-exec: Detect errors in "stop" test
Previously this test was just assuming that the provisioner run would
succeed and only requiring that it run for more than 50ms before exiting.
That meant that it could potentially false-positive succeed if the
provisioner happened to return an error but take more than 50ms to do so.

Now we'll test for failure before we ask the provisioner to stop, which
narrows the false-positive window. This still isn't completely robust
because we don't have any way to test whether the provisioner failed due
to being canceled or for some other reason. The error message returned on
cancellation varies depending on what state the provisioner was in when
it got the cancellation message, so it's not currently feasible to write
a robust check that would definitely distinguish between the expected error
vs. unexpected errors.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-08 17:17:50 -07:00
Martin Atkins
27e6565701 Use the latest protobuf tools and libraries throughout
Previously we were using a mixture of old and new, with our code generation
using the plugin from the old github.com/golang/protobuf library but
our callers using the modern google.golang.org/protobuf . We were also
using pretty ancient version of protoc.

This brings us up to the current latest releases and consistently using
the new Go protobuf library. There have been some notable changes to these
tools in the meantime:

Previously the protoc-gen-go plugin handled grpc by having its own
additional level of Go-specific "plugins" of which the gRPC codegen was
an example.

Now the protobuf generator and the gRPC generator are separate plugins
handled directly by protoc, which means the command line arguments are
a different shape and the gRPC stubs get generated in a separate file
from the main protobuf messages, rather than all being in one .pb.go file
as before.The results are otherwise similar, though.

The grpc codegen now also defaults to requiring that implementations embed
the generated "unimplemented" server, which is an implementation of each
service where the methods just immediately return the "unimplemented"
error. This is not super important for us because we maintain the generated
interfaces and their implementations together in the same repository
anyway, but adding the "unimplemented" server embeds was not a big change
and so seems better to follow the prevailing convention.

Using these new versions means that we could in principle now switch to
using protobuf edition 2024 and the new "sealed" style for Go code
generation, but this commit does not include any such changes and focuses
only on getting things upgraded with as few other changes as possible. We
can discuss using different codegen style later and deal with that in
separate commits.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-08 07:43:40 -07:00
Christian Mesh
bbf7b1254d Document -force-copy option in -migrate-state error message
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-10-07 08:36:30 -04:00
Martin Atkins
8e7dfdf478 dependencies: Stop using github.com/apparentlymart/go-dump
This upstream library (which I wrote, independently of my work on OpenTofu)
came about because "go-spew" tended to produce unreadable representations
of certain types commonly used in OpenTofu, whereas "go-dump" is really
just a pretty-printer for whatever a type might produce when formatted
using the %#v verb in package fmt.

Over time the uses of this seem to have decreased only to some leftover
situations where we wanted to pretty-print a cty.Value in a test, but
we already depend on go-cty-debug that has a more specialized
implementation of that behavior and so switching the few remaining callers
over to that allows us to remove one dependency.

(And, FWIW, that upstream dependency is effectively unmaintained; I don't
know of any callers of it other than OpenTofu itself, and after merging
this even OpenTofu won't depend on it anymore.)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-06 12:47:32 -07:00
Diogenes Fernandes
b2b6e84940 Meta-arguments validation source snippet
Previously, the source snippet was only showing the last defined
meta-argument. To have a better context of which meta-arguments
are being used, we start to show from the first one defined
until the last one.

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Diogenes Fernandes
8736787762 Add module validation of for_each, enabled and count
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Diogenes Fernandes
22594c8afe Add tests for module lifecycle enabled
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Diogenes Fernandes
732623f604 Module expander for enabled field
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Diogenes Fernandes
ca53b2521d Add lifecycle block schema to ModuleCall
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-03 13:17:47 -03:00
Diógenes Fernandes
a18063df8e fix: typo on the function's comment (#3324)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-10-02 12:36:01 -03:00
Diógenes Fernandes
e5e9bcd163 fix TestApply_plan_backup test on Windows by using garbage collection (#3320)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-30 15:49:55 -03:00
Diógenes Fernandes
bdcf1f5e6e fix: internal/initwd tests on Windows (#3291) 2025-09-30 15:07:43 -03:00
Larry Bordowitz
bcbfebce3d Implement the Azure Key Provider
This uses the same auth package as the newly-rewritten Azure State
Backend, so many of the properties and environment variables are the
same. I have put this through both the compliance test as well as built
the binary and run some end-to-end tests, and found that it
appropriately uses the Azure key as expected.

Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-09-29 06:19:02 -04:00
Martin Atkins
9895f54ed0 lint: Include more source context in unused attribute diagnostics
From some more practical testing of this I realized that usually the first
thing I want to know after seeing this warning is what the object literal
was being assigned to and what else was also defined inside it, and so
this sets the diagnostic's "context" to include the whole containing
object literal so that the source snippet in the diagnostic message is more
immediately useful, without having to cross-reference to the source code
in a separate text editor.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-26 09:08:31 -07:00
Martin Atkins
0fb0a4b707 lint: DiscardedObjectConstructorAttrs
This generalizes the previously-added lint-like check for when an object
constructor is used to define an input variable and it contains a
definition for an attribute that isn't part of the target type, so that
now it also works for various nested structures that commonly arise in
real-world configurations.

Because this is now considerably more complicated I factored it out into
a new package called "lint" which could potentially grow to include other
similar "technically valid but probably a mistake" situations in future,
but for now it just introduced an opportunity to produce similar warning
messages for ignored attribute definitions in the default value for an
input variable.

It seems to me that there is actually no useful reason to include an
unexpected attribute definition in either of these two cases: that
attribute will never appear as part of any expression that any other part
of the configuration can use. Therefore I considered making these be
treated as errors rather than warnings, but turning something that was
previously valid into an error is risky so I'm suggesting that we start
with these as warnings and then consider upgrading them to errors in a
later release if we don't hear of anyone reporting a false-positive that
was _somehow_ actually useful. (I find that very unlikely, but still...)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-26 09:08:31 -07:00
Martin Atkins
d7c4487172 tofu: Warn if object literal includes unused attribute for input variable
We intentionally allow assigning object types with a superset of the
attributes included in an input variable's object type constraints because
it makes it possible to assign a whole object for which only some of the
attributes are relevant for one input variable but a different subset might
be relevant when the object value is used in a different part of the
configuration.

However, when the variable is defined using an object literal expression
there is no possible way an unexpected attribute could be useful in a
different part of the configuration, and so that's very very likely to be
a mistake rather than intentional. Therefore we'll generate a "linter-like"
warning in that case to help the author notice their mistake without
introducing any new "strict-mode" language features, or other complexity
that would be harder to maintain and evolve over time.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-26 09:08:31 -07:00
Diogenes Fernandes
b0704680c0 Better handling of the enabled types on the tofu/evaluate (#3042)
Co-Authored-by: Martin Atkins <mart@degeneration.co.uk>
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
774224a2dd Early return when having errors and additional tests (#3042)
Co-authored-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
1c90ca87f8 Implement validation on ephemeral and data resources (#3042)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
85ea2a4fa5 Improve eval_lifecycle_enabled diagnostic context for errors (#3042)
Co-Authored-By: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
f439baaf01 Fix variable context expansion on resources (#3042)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diogenes Fernandes
0eb18fb49c Add conditional enabled field on managed and data resources (#3042)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diógenes Fernandes
1b90a1889e Evaluate expressions for enabled meta-argument (#3250)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-26 08:44:39 -03:00
Diógenes Fernandes
4c7122ba19 fix internal/backend/local tests by closing file handle properly (#3284)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-22 11:24:42 -03:00
Andrei Ciobanu
7ef6251591 Plan now renders write-only attributes that require replace (#3296)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2025-09-22 17:15:20 +03:00
James Humphries
1e8ccb8d96 fix: Prevent nil panic in marshalProviderConfigs when inSingleModuleMode (#3294)
Signed-off-by: James Humphries <james@james-humphries.co.uk>
2025-09-22 13:40:48 +01:00
Andrei Ciobanu
cf971eb3b6 Rework the way ephemeral variables are used when given on tofu apply command (#3192)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-22 09:31:19 +03:00
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
2d5ea98257 skip timeout lock tests on windows (#3288)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-17 16:56: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
Diógenes Fernandes
eaa5b5c160 fix internal/getprovider tests on Windows using lf line breaks (#3281)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-17 09:06:44 -03:00
Diógenes Fernandes
167fd0d263 fix internal/configs/ on Windows (#3276)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 16:14:31 -03:00
Diógenes Fernandes
3a8506b14e fix: TestPlan_generatedConfigPath on Windows by standardizing line breaks (#3274)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 16:11:52 -03:00
Diógenes Fernandes
9b14212207 fix: internal/getprovider tests on Windows (#3275)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 15:29:31 -03:00
Diógenes Fernandes
f5ef40c37c fix: TestEnsureProviders using the wrong line breaks and PackageDir separator (#3273)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 13:27:35 -03:00
Diógenes Fernandes
d280ab1d6b fix: TestExecutable on Windows - expected error message is wrong (#3272)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 13:27:18 -03:00
Diógenes Fernandes
189c4535f1 Using forward slashes in PackageDir to fix providercache tests in Windows (#3233)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 09:38:04 -03:00
Diógenes Fernandes
e1dd6c3625 Normalize paths at internal/lang/funcs tests (#3223)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-16 09:17:02 -03:00
Larry Bordowitz
0090e8a18c Add new configuration to AzureRM Backend (#3251)
Signed-off-by: Larry Bordowitz <laurence.bordowitz@gmail.com>
2025-09-15 19:22:17 +01: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
Martin Atkins
2d2b08517e cliconfig: Registry protocol retry count and timeout settings
These were previously settable only via environment variables. These are
now handled as part of CLI Configuration and so also settable in a new
"registry_protocols" block in a CLI configuration file, with the
environment variables now treated as if they are an additional virtual
configuration file containing the corresponding settings.

This handles our settings in our modern style where package cliconfig is
responsible for deciding the configuration and then package main reacts
to that configuration without being aware of how it is decided.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-09-10 11:45:38 -07:00
Diógenes Fernandes
e76a772102 fix: ephemeral end-to-end tests on Windows (#3259)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-09-10 12:07:24 -03:00
Christian Mesh
c8b58e949b Address review comments
Co-authored-by: James Humphries <James@james-humphries.co.uk>
Co-authored-by: Ilia Gogotchuri <ilia.gogotchuri0@gmail.com>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Andrei Ciobanu
1bab9aff46 Ephemeral todos handling (#3177)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Andrei Ciobanu
ccfeb83889 Renderer keys validation - remove the else branch since does not make sense anymore (#3176)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Andrei Ciobanu
7f76707dd0 Ephemeral write only attributes (#3171)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Christian Mesh
cbe16d3a5d Forbid usage of tofu.applying during static eval
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Christian Mesh
6437bfe01f Add tofu.applying (and terraform.applying) (#3170)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00
Christian Mesh
4ad9dfa716 Address ephemeralasnull comments/TODOs (#3169)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-09-10 07:45:23 -04:00