Commit Graph

371 Commits

Author SHA1 Message Date
Liam Cervante
15ecdb66c8
Fix no-op outputs causing the plan renderer to skip the 'no changes' message (#32820)
* Fix no-op outputs causing the plan renderer to skip the 'no changes' message

* fix imports
2023-03-10 16:19:33 +01: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
Reda Khaled
100c44b6c3
bugfix: issue-28274, terraform providers mirror command should honor terraform lock file 2023-02-25 00:16:46 +01:00
Martin Atkins
a86cef4d50 cliconfig: Allow breaking the dependency lock file using the environment
Since it's already possible to activate the dependency lock file using an
environment variable, we should allow opting in to it having broken
behavior using the environment too.

It's kinda odd in retrospect that TF_PLUGIN_CACHE_DIR is the only setting
we allow to be configured both in the environment and the CLI
configuration. That means that the infrastructure for dealing with that
situation was relatively immature here and so I did some light refactoring
to make it unit-testable without actually modifying the test program's
environment.
2023-02-22 12:23:56 -08:00
CJ Horton
3c54e42080
Merge pull request #32695 from hashicorp/radditude/init-config-warning
keep errors friendly when init encounters syntax problems
2023-02-21 16:09:05 -08:00
kmoe
b435b4ccde
cliconfig: more provider_installation err detail (#32722) 2023-02-21 18:18:57 +00:00
Sebastian Rivera
6d0a191ec4 Handle provisioner log types in renderer 2023-02-16 10:54:58 -05:00
CJ Horton
30f8b014f8 keep the friendly error message whenever possible 2023-02-15 21:40:46 -08: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
Daniel Banck
4fa77727b5
Introduce metadata functions command (#32487)
* Add metadata functions command skeleton

* Export functions as JSON via cli command

* Add metadata command

* Add tests to jsonfunction package

* WIP: Add metadata functions test

* Change return_type & type in JSON to json.RawMessage

This enables easier deserialisation of types when parsing the JSON.

* Skip is_nullable when false

* Update cli docs with metadata command

* Use tfdiags to report function marshal errors

* Ignore map, list and type functions

* Test Marshal function with diags

* Test metadata functions command output

* Simplify type marshaling by using cty.Type

* Add static function signatures for can and try

* Update internal/command/jsonfunction/function_test.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

---------

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-02-14 14:08:47 +00:00
Liam Cervante
d212a72d1d
structured run output: impose canonical ordering on jsonstate and jsonplan packages (#32649) 2023-02-13 15:40:17 +01: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
Liam Cervante
4fa7cd0a68
structured renderer: fix closing json tags when rendering with no symbols (#32642) 2023-02-08 16:47:12 +01:00
Liam Cervante
d818d7850d
Structured Renderer: use the new renderer when rendering the state in addition to the plan (#32629)
* Use the new renderer when rendering the state

* remove confusing and unneeded comment
2023-02-07 09:14:14 +01:00
zetHannes
c70244426a
Fix for no json output of state locking actions for --json flag (#32451)
* Add viewType to Meta object and use it at the call sites

* Assign viewType passed from flags to state-locking cli commands

* Remove temp files

* Set correct mode for statelocker depending on json flag passed to commands

* Add StateLocker interface conformation check for StateLockerJSON

* Remove empty line at end of comment

* Pass correct ViewType to StateLocker from Backend call chain

* Pass viewType to backend migration and initialization functions

* Remove json processing info in process comment

* Restore documentation style of backendMigrateOpts
2023-02-07 09:06:12 +01:00
Brandon Croft
9fd76e56cd
Factor out terraform-config-inspect/tfconfig during init
As explained by the deleted comments, this package was used to identify situations where the `terraform 0.12upgrade` command can help migrate 0.11 syntax. Current versions of terraform don't include this command, and it's not likely that users are attempting upgrades from 0.11 to 1.4+

The replacement init swaps the order of the module and backend initialization in order to prepare for the next commit.

Config initialization now takes the following approach:
1. Load the root module, but withhold diagnostic errors until after version check
2. Initialize the backend, but withhold diagnostic errors until after version check
3. Get modules
4. Load all config (root and modules)
5. Check terraform version requirements (this can be defined by nested modules) and display any errors. It's important to show these first because prior errors could be the result of a newer terraform version syntax
6. Finally, show any errors related to backed init or config loading
2023-01-30 17:21:23 -07:00
Sheridan C Rawlins
75e5ae27a2
[fixes 31700] Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert. (#31699)
* Add mTLS support for http backend by way of client cert & key, as well as enterprise cacert.

* Fix style.

* Skip cert validation to be sure error is related to missing client cert; not untrusted server cert.

* Remove misplaced err check.

* Fix the size of test using http backend.

* Just for correctness, include all certs in the pem encoded cert - sometimes certs come with a chain of their signers.

* Adjusted names as recommended in PR comments.

* Adjusted names to be full-length and more descriptive.

* Added full-fledged testing with mTLS http server

* Fix goimports.

* Fix the names of the backend config.

* Exclusive lock for write and delete.

* Revert "Fix goimports."

This reverts commit 7d40f6099fbbb675fb2e25e35ee40aeafe3d0a22.

* goimports just for server test.

* Added the go:generation for the mock.

* Move the TLS configuration out to make it more readable - don't replace the HTTPClient as the retryablehttp already creates one - just configure its TLS.

* Just switch the client/data params - felt more natural this way.

* Update internal/backend/remote-state/http/backend.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/backend/remote-state/http/testdata/gencerts.sh

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/backend/remote-state/http/backend.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/backend/remote-state/http/backend.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/backend/remote-state/http/backend.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* Update internal/backend/remote-state/http/backend.go

Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>

* the location of the file name is not sensitive.

* Added error if only one of client_certificate_pem and client_private_key_pem are set.

* Remove testify from test cases; use t.Error* for assert and t.Fatal* for require.

* Fixed import consistency

* Just use default openssl.

* Since file(...) is so trivial to use, changed the client cert, key, and ca cert to be the data.

See also https://github.com/hashicorp/terraform-provider-http/pull/211

Co-authored-by: Sheridan C Rawlins <scr@ouryahoo.com>
Co-authored-by: kmoe <5575356+kmoe@users.noreply.github.com>
2023-01-26 14:08:07 +00:00
Martin Atkins
e2380b1038 cliconfig: Allow forcing use of the plugin cache despite the lock file
Currently Terraform will use an entry from the global plugin cache only if
it matches a checksum already recorded in the dependency lock file. This
allows Terraform to produce a complete lock file entry on the first
encounter with a new provider, whereas using the cache in that case would
cause the lock file to only cover the single package in the cache and
thereefore be unusable on any other operating system or CPU architecture.

This temporary CLI config option is a pragmatic exception to support those
who cannot currently correctly use the dependency lock file but who still
want to benefit from the plugin cache. With this setting enabled,
Terraform has permission to produce a dependency lock file that is only
suitable for the current system if that would allow use of an existing
entry in the plugin cache.

We are introducing this option to resolve a conflict between the needs of
folks who are using the dependency lock file as expected and the needs of
folks who cannot use the dependency lock file for some reason. The hope
then is to give respite to those who need this exception in the meantime
while we understand better why they cannot use the dependency lock file
and improve its design so that everyone will be able to use it
successfully in a future version of Terraform. This option will become a
silent no-op in a future version of Terraform, once the dependency lock
file behavior is sufficient for all supported Terraform development
workflows.
2023-01-25 08:23:01 -08:00
Liam Cervante
7d1ea52077
Structured Plan Renderer: another round of fixes after more equivalence testing (#32537)
* Structured Plan Renderer: another round of fixes after more equivalence testing

* fix sort function

* use new constants
2023-01-20 09:24:22 +01:00
Liam Cervante
6dc49150b7
Structured Plan Renderer: Read the data source schemas from the right place (#32532)
* read the data source schemas from the right place

* address comments and add test
2023-01-19 15:37:02 +01:00
Liam Cervante
8d61c5bfc4
Use the new structured renderer in place of the old diffs package (#32520)
* Use the new structured renderer in place of the old diffs package

* remove old plan tests

* refresh only plans should show moved resources in the refresh section
2023-01-18 10:14:54 +01:00
Liam Cervante
99823e4a15
Structured Plan Renderer: Fix minor bugs causing diffs in the equivalence tests. (#32519)
* remove attributes that do not match the relevant attributes filter

* fix formatting

* fix renderer function, don't drop irrelevant attributes just mark them as no-ops

* fix imports

* fix bugs in the renderer exposed by the equivalence tests

* imports

* gofmt
2023-01-17 09:31:29 +01:00
Liam Cervante
e015b15f12
Structured Plan Renderer: Remove attributes that do not match the relevant attributes filter (#32509)
* remove attributes that do not match the relevant attributes filter

* fix formatting

* fix renderer function, don't drop irrelevant attributes just mark them as no-ops

* fix imports
2023-01-16 15:18:38 +01:00
Liam Cervante
95782f2491
Structured plan renderer: Implement the main functionality for the renderer (#32496)
* raw unmodified broken tests

* tests execute, no panics

* fix whitespace differences

* fix all the tests

* fix tests

* actually fix tests

* add missing plan metadata into the renderer

* address comments

* complete merge

* remove TODO raising questions about outputs, they are fixed

* missing bold on plan
2023-01-12 17:59:07 +01:00
Liam Cervante
af0ff90d6e
Remove outputs from the jsonplan that are not from the root module (#32503) 2023-01-12 17:02:29 +01:00
Liam Cervante
c125397da1
push the colorize actions as locally as possible (#32502) 2023-01-12 16:47:06 +01:00
James Bardin
96b1318167 remove deprecated condition_results from plan 2023-01-11 16:03:32 -05:00
Liam Cervante
f6d625103c
Structured plan renderer: refactor replace paths logic (#32489)
* change -> diff, value -> change

* also update readme#

* structured plan renderer: refactor replace paths logic

* goimports

* goimports

* address comments

* fix compile error
2023-01-11 10:20:24 +01:00
Liam Cervante
38afb41787
Structured plan renderer: Introduce support for multiline and JSON strings (#32488)
* pause implementation

* change -> diff, value -> change

* add support for json and multiline strings to the primitive renderer

* goimports

* remove unused function

* go fmt

* address comments
2023-01-11 09:35:36 +01:00
Liam Cervante
8330b7295b
Structured plan renderer: Add support for map blocks and sensitive blocks. (#32491)
* change -> diff, value -> change

* also update readme#

* pause

* Update internal/command/jsonformat/computed/diff.go

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>

* add interface assertions for diff renderers

* Add support for different kinds of blocks, and for sensitive blocks

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2023-01-11 09:04:26 +01:00
Liam Cervante
21bb677db7
Structured Plan Renderer: Naming and package structure refactor (#32486)
* change -> diff, value -> change

* also update readme#

* Update internal/command/jsonformat/computed/diff.go

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>

* add interface assertions for diff renderers

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2023-01-10 17:24:48 +01:00
Liam Cervante
a086453783
Structured Plan Renderer: Refactor Primitive and Sensitive value processing (#32476)
* refactor sensitive and primitive values to match patterns used elsewhere

* goimports

* address comments

* fix tests

* also use %q for map keys
2023-01-09 20:38:25 +01:00
Liam Cervante
46ab53d651
Structured Plan Renderer: Escape object and block keys that don't match HCL syntax (#32483)
* Escape object and block keys that don't match HCL syntax

* address comments
2023-01-09 20:22:59 +01:00
Liam Cervante
7a3fc48b70
Structured Plan Renderer: Add tests validating behaviour of dynamic types (#32482)
* add support for dynamic types into attribute processing

* fix names

* add tests
2023-01-09 20:08:08 +01:00
Liam Cervante
d31631675b
Add support for Tuples into the structured plan renderer (#32479)
* add support for tuples to the structured plan renderer

* update after latest main changes
2023-01-09 17:39:13 +01:00
Liam Cervante
2d66eee872
Structured Plan Renderer: Address comments raised in previous PRs (#32478)
* Address comments raised in previous PRs

* add doc comments for public types
2023-01-09 17:15:17 +01:00
Liam Cervante
1332d315b6
Structured Plan Renderer: Remove generic interface{} entry point (#32477)
* Remove the single generic point of entry into the differ package

* goimports

* add comment explaining generic function
2023-01-09 16:49:35 +01:00
Liam Cervante
9bc5ded27a
Add support for outputs in the structured renderer (#32426)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer

* Add support for maps in the structured renderer

* Add support for lists in the structured renderer

* goimports

* Add support for sets in the structured renderer

* goimports

* Add support for blocks in the structured renderer

* goimports

* Add support for outputs in the structured renderer

* fix ordering of blocks

* remove unused test stub

* fix typo
2023-01-09 14:45:35 +01:00
Liam Cervante
05f1764a0d
Add support for blocks in the structured renderer (#32422)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer

* Add support for maps in the structured renderer

* Add support for lists in the structured renderer

* goimports

* Add support for sets in the structured renderer

* goimports

* Add support for blocks in the structured renderer

* goimports

* fix ordering of blocks

* remove unused test stub
2023-01-09 14:33:01 +01:00
Liam Cervante
69cce3597f
Add support for sets in the structured renderer (#32409)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer

* Add support for maps in the structured renderer

* Add support for lists in the structured renderer

* goimports

* Add support for sets in the structured renderer

* goimports
2023-01-09 14:17:30 +01:00
Liam Cervante
aff94591c1
Add support for lists in the structured renderer (#32401)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer

* Add support for maps in the structured renderer

* Add support for lists in the structured renderer

* goimports

* add additional comments explaining
2023-01-09 14:06:38 +01:00
Liam Cervante
8975eebf84
Add support for maps in the structured renderer (#32397)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer

* Add support for maps in the structured renderer
2023-01-09 12:41:24 +01:00
Liam Cervante
b097d8873d
Add support for the replace paths data in the structured renderer (#32392)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports

* Add support for the replace paths data in the structured renderer
2023-01-09 12:27:36 +01:00
Liam Cervante
1eebcf875f
Add support for object attributes in the structured renderer (#32391)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests

* Add support for object attributes in the structured renderer

* goimports
2023-01-09 12:15:38 +01:00
Liam Cervante
b8b1a8d430
Add support for unknown/computed values in the structured renderer (#32378)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer

* Add support for unknown/computed values in the structured renderer

* delete missing unit tests
2023-01-09 11:55:55 +01:00
Liam Cervante
6ab277f6ba
Add support for sensitive values in the structured renderer (#32375)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* Add support for parsing and rendering sensitive values in the renderer
2023-01-09 11:40:47 +01:00
Liam Cervante
71daef058f
Add rendering functionality for primitives to the structured renderer (#32373)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add rendering functionality for primitives to the structured renderer

* add test case for override

* goimports
2023-01-09 11:24:01 +01:00
Liam Cervante
aff7d360e1
Add skeleton functions and API for refactored renderer (#32368)
* prep for processing the structured run output

* undo unwanted change to a json key

* Add skeleton functions and API for refactored renderer

* goimports

* Fix documentation of the RenderOpts struct

* Add README explaining implementation details for renderer and plans for future expansion

* Update internal/command/jsonformat/README.md

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>

* address comments

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2023-01-09 11:05:25 +01:00
Liam Cervante
b917154a97
Make required JSON structured output structures public for processing (#32367)
* prep for processing the structured run output

* undo unwanted change to a json key
2023-01-09 10:48:23 +01:00
James Bardin
721df0e68d
Merge pull request #32395 from hashicorp/jbardin/plan-output-on-error
Always show and store planned actions and checks even when planning fails
2023-01-04 12:44:52 -05:00