Commit Graph

32469 Commits

Author SHA1 Message Date
Martin Atkins
0e1fcb1bf7 main: Try to expand arguments starting with "@" from files on disk
This is a GCC-like behavior where we preproces the argument vector by
trying to treat any argument starting with "@" as a placeholder for
arguments loaded from a given filename.

As with GCC, if the remainder of the string cannot be used as a filename
to open and read, the original argument is retained literally. However,
if it _is_ possible to open and read a file of the given name then we
take that as sufficient evidence of the operator's intent to read from
that file and will fail with an error message if the file contents are not
acceptable syntax.

This uses the same upstream library as we've already been using for the
TF_CLI_ARGS... environment variables. Since main.go was quite overcrowded
with various different concerns, the handling of those environment
variables also moves into the new arguments.go file here, since the two
share an upstream dependency and both involve simplistic substitutions and
insertions into the argument vector. The observable behavior of the
environment variable handling should not be changed in any way by this
commit.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-29 17:25:55 -08:00
Haider Bari
6614782e6d
Improved error messages for lock-related problems in the s3 backend (#2410)
Signed-off-by: Bari, Haider <haider.bari@fmr.com>
Co-authored-by: Bari, Haider <haider.bari@fmr.com>
2025-01-29 11:20:28 -05:00
AbstractionFactory
4083fe2cc4
Adding missing PR link to changelog (#2452)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-29 14:23:16 +01:00
Andrei Ciobanu
f00c10ac28
Add changelog entry for 2394 (#2447)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
2025-01-29 11:05:26 +02:00
Andrei Ciobanu
ab9a7f4d72
Fix error message when default value of variable is of wrong type (#2444)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
2025-01-29 10:50:45 +02:00
AbstractionFactory
77c19fab1e
Bumping Go version to address CVE-2024-45336 and CVE-2024-45341 (#2438)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-28 21:40:13 +01:00
Andrei Ciobanu
089687061b
Fix: When a RequiredProvider is having syntax errors, return an empty one to allow further validations to generate their diags (#2408)
Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
Co-authored-by: yottta <andpectech@gmail.com>
2025-01-28 15:47:17 +02:00
AbstractionFactory
cc4ed538bd
Adding warning to the release documentation (#2434)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-28 13:11:09 +01:00
Andrei Ciobanu
8fe739dc83
MakeStaticTimestampFunc now returns unknown value if the given time.Time is zero (#2413)
Signed-off-by: yottta <andpectech@gmail.com>
Co-authored-by: yottta <andpectech@gmail.com>
2025-01-27 17:07:40 +02:00
Martin Atkins
f5eac16b00 providercache: Factor out installation from the global cache dir
This is another step towards breaking the huge functions in this package
into smaller parts that have a clearer set of inputs and outputs.

For the moment the goal is to modify the existing code as little as
possible to make this easier to review, and so the new function
tryInstallPackageFromCacheDir has an unfortunately-large number of
arguments. Future refactoring can hopefully improve on this further.

One significant change to the structure of this code is that because it's
now in a separate function working on only one provider at a time we can
rely on early return for error handling, letting the caller be responsible
for collecting any errors into the "errs" map, and so we don't need quite
as much nesting as the previous code had.

This should not change the observable behavior in any way, which is
reinforced by there being no changes to any tests in this commit.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-24 15:11:05 -08:00
Martin Atkins
eb3e21853e providercache: Decompose Installer.EnsureProviderVersions
This function has grown very large over time as the provider installation
requirements got more complicated. This is a first level of decomposition
of the three main steps into one separate function each.

The "ensureProviderVersionsInstall" method remains too large itself, but
for now that has just acquired a nolint directive so that we can approach
this gradually in the interests of making it easier to review.

This should not change the observable behavior of the provider installer
in any way, which is reinforced by the fact that there are no test changes
in this commit.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-24 15:11:05 -08:00
Christian Mesh
de5f273390
Use import provider instead of guess (#2336)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-01-24 17:18:08 -05:00
Ludovico Magnocavallo
e7f130a490
Add example on supporting both OpenTofu and Terraform versions to version-constraints.mdx (#2302)
Signed-off-by: Ludovico Magnocavallo <ludo@qix.it>
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2025-01-24 12:48:11 -05:00
AbstractionFactory
1b00b465da
Switch to native Linux/ARM64 runners (#2387)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-24 10:43:47 -05:00
Christian Mesh
87cd9227dc
Fix S3 acceptance test panic, introduced in 1.7 encryption (#2420)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-01-24 09:59:43 -05:00
Haider Bari
be72380cdb
"force-unlock" support for the HTTP backend (#2381)
Signed-off-by: Bari, Haider <haider.bari@fmr.com>
Co-authored-by: Bari, Haider <haider.bari@fmr.com>
2025-01-22 19:05:57 -05:00
dependabot[bot]
ebc900bec9 build(deps): bump github.com/hashicorp/go-slug from 0.15.0 to 0.16.3
Bumps [github.com/hashicorp/go-slug](https://github.com/hashicorp/go-slug) from 0.15.0 to 0.16.3.
- [Release notes](https://github.com/hashicorp/go-slug/releases)
- [Commits](https://github.com/hashicorp/go-slug/compare/v0.15.0...v0.16.3)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/go-slug
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-22 13:16:27 -08:00
Nik Stuckenbrock
8f616d41fd
Fix custom docker image instructions by adding gpg-agent package (#2405)
Signed-off-by: Nik Stuckenbrock <35262568+nikstuckenbrock@users.noreply.github.com>
2025-01-21 21:37:50 +01:00
Diógenes Fernandes
ff18b87337
Update .devcontainer.json go's version to 1.22 (#2385)
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
2025-01-17 15:45:56 +01:00
Martin Atkins
4936a89321 go.mod: Upgrade go-cty to v1.16.1
This includes a number of small enhancements and bug fixes compared to
version v1.14.4 that we were previously using, as described in this
commit's CHANGELOG update.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-15 07:56:27 -08:00
AbstractionFactory
f254cbc673
Fixes #2356: Minimal base image (#2375)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-15 13:46:34 +01:00
Martin Atkins
2848ed054e
rfc: Update README.md to discuss RFC Tracking Issues (#2377)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-15 07:36:54 -05:00
Martin Atkins
0576d07397 RFC: Naming convention for internal variables representing "contexts"
This is a lightweight RFC proposing that we adopt some cross-cutting naming
conventions for variables of various different types whose names all
include the noun "context", both to gradually improve existing confusion
and inconsistency in the codebase and in particular to un-squat the name
"ctx" that has emerged as the idiomatic name for a context.Context
elsewhere in the Go ecosystem.

This proposal does not call for any immediate code changes. It is only an
attempt to agree on some conventions to follow in future work on other
projects.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-14 14:39:29 -08:00
Martin Atkins
6bd681e98f Process RFC: RFC Tracking Issues
Proposal for creating a separate "tracking issue" for each accepted RFC,
which represents the implementation of the features described in that RFC
separately from the potentially-many feature request issues it aims to
address.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-14 14:33:04 -08:00
Oleksandr Levchenkov
d7af2c4d39
update tofu console docs for non-interactive use-case (#2369)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Oleksandr Levchenkov <ollevche@gmail.com>
Co-authored-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-14 19:03:30 +02:00
AbstractionFactory
174f1d5784
Fixed broken links in encryption docs (#2366)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-13 16:00:48 +01:00
AbstractionFactory
b036e534b2
Fixing incorrect keyprovider-external.tofu (#2365)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-13 15:53:05 +01:00
Christian Mesh
52816a96dc
Run make generate protobufs (#2360)
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
2025-01-10 11:34:33 -05:00
Martin Atkins
3cbedd3817 plans/objchange: Split assertNestedBlockCompatibleMap into two parts
Unlike the other nesting modes, we need to use some quite different code
for comparing object-backed vs. map-backed blocks, which are both possible
interpretations of the NestingMap mode depending on whether the inner
block type has any dynamically-typed attributes.

Therefore we split that case into two parts depending on what type kind
we find, so that each of the parts can then be shaped more like the other
type-specific variants of assertNestedBlockCompatible. (This also removes
one level of if nesting to placate the nestif linter.)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:29:58 -08:00
Martin Atkins
5b59d869bf plans/objchange: Decompose type-specific part of assertValueCompatible
This function starts with a general part that deals with conditions that
are common to all types, but then dispatches into different codepaths
depending on the type kind.

To keep the main function shorter, here we decompose the type-kind-specific
handling into separate functions, making assertValueCompatible now end
with a simpler dispatch table.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:29:58 -08:00
Martin Atkins
d49f997b65 plans/objchange: Decompose assertNestedBlockCompatible
The main function is now just a jump table into a separate function for
each nesting mode. The observable behavior is unchanged.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:29:58 -08:00
Martin Atkins
55ff663aff plans/objchange: Decompose assertObjectCompatible a little
This splits out the handling of individual attributes and individual nested
block types into separate functions, thereby reducing the length and
complexity of the top-level function.

As of this commit, assertNestedBlockCompatible is still too long to pass
our current function length linting limit, but we'll address that in a
later commit to avoid changing too much at once.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:29:58 -08:00
Martin Atkins
e70913a609 plans/objchange: Fix go vet warnings
Passing the result of fmt.Sprintf as the format string to path.NewErrorf
is redundant. It can also potentially cause problems if the result would
also contain formatting verbs, although in this case the input is under
this function's full control so this was just a waste of time rather than
a behavior problem.

Go error strings also conventionally start with lowercase letters and act
as sentence fragments rather than full sentences, so the prefix used for
a zero-length path is now "root object" instead of "Root object".

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:29:58 -08:00
James Humphries
c1f1008723
Replace mock module with go.uber.org/mock (#1673)
Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
Signed-off-by: James Humphries <james@james-humphries.co.uk>
Co-authored-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
2025-01-10 08:29:20 -05:00
Martin Atkins
7435a49e4a
plans/objchange: Decompose normalizeObjectFromLegacySDK a little (#2353)
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-10 08:28:13 -05:00
AbstractionFactory
09403c7328
Docs prep for 1.10 (#2357)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-10 11:40:17 +01:00
Martin Atkins
d0d35d2dcd tfplugin5+tfplugin6: Update to latest protocol schema
This commit adds the definitions of provider protocol 5.6, 5.7, 6.6, and
6.7 to our archive of the historical protocol versions and then adopts
5.7 as the current version of major version 5 and 6.7 as the current
version of major version 6.

These MPL-licensed schema definitions are from the plugin protocol server
implementation in this repository, copyright HashiCorp:
    https://github.com/hashicorp/terraform-plugin-go

The only modifications made are to change the "option go_package" directive
to match where the stubs need to be generated for OpenTofu, and to claim
copyright for that change and thus make the copyright header consistent
with what our pre-commit rules require.

The regeneration of the Go API stubs for the two major protocol versions
introduces some new fields and messages that OpenTofu does not yet support
but will happily ignore. Future work might make some use of these new
additions, but that's out of scope of this change that is intended only
to synchronize our protocol definition with what new plugin server releases
are likely to be linked against.

This commit continues the existing precedent of having the stubs for the
newly-added interface methods in package grpcwrap being just a panicking
stub, which is how they will remain until a future project begins using
those methods in a way which requires them to be implemented, since
implementing the wrappers would require a deeper understanding of the
desired behavior of those methods.

It appears that we previously accepted a pull request to correct a typo
that originated in the older versions of the upstream protocol definitions,
but I have intentionally not forward-ported that here because it seems
clearer to keep these definitions as close as possible to their source
of truth from upstream, given that our current intention is to follow the
protocol as documented and not to change it.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-09 16:16:58 -08:00
Marcin Wyszynski
f83849e95a
Catch invalid name in provider_meta before it causes a crash (#2347)
Signed-off-by: Marcin Wyszynski <marcin.pixie@gmail.com>
2025-01-09 14:36:56 +00:00
Oleksandr Levchenkov
76d388b340
fix: provider not initialized in some cases (mostly, deposed) (#2335)
Signed-off-by: ollevche <ollevche@gmail.com>
Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-08 12:34:52 -05:00
AbstractionFactory
5a6d2d3e98
Fixes #2022: Running external commands as a key provider (#2023)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2025-01-08 12:08:30 -05:00
zcxsythenew
ec20752054
Add option "-json" in help text of apply command and plan command. (#2340)
Signed-off-by: Guozhang Wu <30565051+zcxsythenew@users.noreply.github.com>
2025-01-08 14:58:32 +02:00
Oleksandr Levchenkov
8139ae6005
update MAINTAINERS file (#2341)
Signed-off-by: ollevche <ollevche@gmail.com>
2025-01-08 10:52:42 +01:00
AbstractionFactory
3033dba76a
OpenTofu 1.10: Disable usage of ghcr.io image as a base image (#1994)
Signed-off-by: Janos <179820029+abstractionfactory@users.noreply.github.com>
Signed-off-by: abstractionfactory <179820029+abstractionfactory@users.noreply.github.com>
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
2025-01-07 10:08:23 -05:00
Jon Johnson
7ba6e61c69
Fix quadratic marshalPlannedValues (#2324)
Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
Signed-off-by: Jon Johnson <jonjohnsonjr@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2025-01-06 16:20:41 -05:00
Martin Atkins
45131c4c0c lang: Split enhanceFunctionDiags loop body into separate function
This function was previously failing the nestif lint rule. Factoring the
loop body out into a separate function avoids that problem and also
subjectively makes this easier to follow by separating the functional-style
enhanceFunctionDiag from the mutation of the backing array of the caller's
diags slice.

This also transforms enhanceFunctionDiags into a package-level function
rather than a method of Scope, since in practice it doesn't actually use
anything from Scope.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:39:01 -08:00
Martin Atkins
972324e5ea lang: Factor out the base function table
Whichever function were responsible for instantiating this map would
inevitably end up scaling in length based on the number of funtions and
thus violate the function length linter.

As a compromise, we'll factor out the function table into its own function
that is exempt from that linter but focused only on constructing the base
function table, and then Scope.Functions can be shorter by dealing only
with the scope-specific customizations of the returned table.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:39:01 -08:00
Martin Atkins
69bf43dd56 repl: Various lint-related updates
This is an assortment of small changes to fix all of the remaining lint
failures in this package, based on our current golangci-lint configuration.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:38:44 -08:00
Martin Atkins
da8a2ecfce repl: break typeString into some smaller functions
This function was too long for our function length linting rule, so we'll
split each of the type kinds with special handling into their own function
and thus the main typeString function is just a straightforward dispatch
table with only one statement per case.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:38:44 -08:00
Martin Atkins
6cc3fc6a07 repl: FormatValue factor out printing of null values
This value was too long for our function length lint rule, and factoring
out the printing of null values makes this more balanced with how we're
already handling unknown values and sensitive values so that the main
body of FormatValue is focused on the normal value printing case.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:38:44 -08:00
Martin Atkins
547bb32cee statefile: old version upgrades exempt from linters
The functions in these files are for handling older state snapshot formats
that current OpenTofu versions never generate, and so it's highly unlikely
that we'll ever make substantial changes to these functions.

Therefore it's unjustified to risk reworking it to pass linting rules, and
so we'll add nolint comments instead. Our priority is to make as few
changes as possible to these functions, to minimize the risk of regressing
a upgrade paths that are exercised very infrequently.

(For context, state version 4 has been current ever since Terraform
v0.12.0, and so the earlier versions are long obsolete.)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-01-06 08:38:15 -08:00