Commit graph

72 commits

Author SHA1 Message Date
James Bardin
bdd5a2cd33 try to render some empty string -> null changes
Changes between empty strings and `null` were hidden in the CLI output,
because the SDK could not reliably detect the difference and may return
either value depending on the situation.

This legacy behavior can be confusing for authors of new provider which
can correctly handle `null`, and it would be preferable to be able to
render those changes in the CLI.

While we don't have enough information to detect when the legacy
behavior is required, we can detect a number of cases where it's
certain that we are not dealing with a legacy schema and should output
the full diff.
2024-02-27 16:59:06 -05:00
Liam Cervante
82361afd73
plan rendering: fix truncation of very large numbers (#34702) 2024-02-20 09:48:11 +01:00
Daniel Schmidt
adf008d489
adjust tests to new implementation 2024-02-16 11:49:24 +01:00
Daniel Schmidt
19f9bdac14
handle multi-line string diffs correctly 2024-02-16 11:20:56 +01:00
Daniel Schmidt
a64df71152
fix comment 2024-02-16 11:20:56 +01:00
Daniel Schmidt
1531fee472
clarify comment 2024-02-16 11:20:56 +01:00
Daniel Schmidt
2a625b75a4
handle reordering explicitly 2024-02-16 11:20:56 +01:00
Daniel Schmidt
31bd2b5be0
plan: compare individual elements if list is same length
Closes #33779
2024-02-16 11:20:55 +01:00
Liam Cervante
f0b61090a2
Move the testing MockProvider into a dedicated shared package (#34681)
* move the testing MockProvider into a dedicated shared package

* address comments

* fix new changes
2024-02-16 10:35:29 +01:00
kmoe
8f3aa0e099
jsonformat: render forget-only attr changes as no-op (#34403)
* jsonplan: document forget actions

* jsonformat: format forget changes as no-op

Previous to this commit, forget-only actions (i.e. "forget", not "create then forget") would be rendered using the forget action symbol for the top-level resource, and the delete action symbol for each resource attribute, with a new value of "null". This attribute rendering is identical to that for resource deletion, which might suggest to some users that Terraform plans to delete the resource, not just remove it from state.
This commit tweaks the renderer so forget-only changes render as no-ops but with the forget action symbol and resource change comment.
2023-12-12 20:02:38 +00:00
Martin Atkins
17f420102f states: Local values no longer live in state
Back when we added local values (a long time ago now!) we put their
results in state mainly just because it was the only suitable shared data
structure to keep them in. They are a bit ideosyncratic there because we
intentionally discard them when serializing state to a snapshot, and
that's just fine because they never need to be retained between runs
anyway.

We now have namedvals.State for all of our named value result storage
needs, so we can remove the local-value-related fields of states.Module
and use the relevant map inside the local value state instead.

As of this commit, states.State now tracks only the data that we
actually persist between runs in state snapshots, which will hopefully
avoid future bugs resulting from the former difference in fidelity
between a freshly-created in-memory state vs. one loaded from a
snapshot.
2023-12-07 09:56:36 -08:00
Martin Atkins
b0b8d4aa6f states: Only track root module output values
For a very long time we've had an annoying discrepancy between the
in-memory state model and our state snapshot format where the in-memory
format stores output values for all modules whereas the snapshot format
only tracks the root module output values because those are all we
actually need to preserve between runs.

That design wart was a result of us using the state both as an internal
and an external artifact, due to having nowhere else to store the
transient values of non-root module output values while Terraform Core
does its work.

We now have namedvals.State to internally track all of the throwaway
results from named values that don't need to persist between runs, so now
we'll use that for our internal work instead and reserve the states.State
model only for the data that we will preserve between runs in state
snapshots.

The namedvals internal model isn't really designed to support enumerating
all of the output values for a particular module call, but our expression
evaluator currently depends on being able to do that and so we have a
temporary inefficient implementation of that which just scans the entire
table of values as a stopgap just to avoid this commit growing even larger
than it already is. In a future commit we'll rework the evaluator to
support the PartialEval mode and at the same time move the responsiblity
for enumerating all of the output values into the evaluator itself, since
it should be able to determine what it's expecting by analyzing the
configuration rather than just by trusting that earlier evaluation has
completed correctly.

Because our legacy state string serialization previously included output
values for all modules, some of our context tests were accidentally
depending on the implementation detail of how those got stored internally.
Those tests are updated here to test only the data that is a real part
of Terraform Core's result, by ensuring that the relevant data appears
somewhere either in a root output value or in a resource attribute.
2023-12-07 09:56:36 -08:00
kmoe
a718f70f85
Add removed block (#34251)
* terraform: remove redundant code

NodeDestroyResourceInstance is never instantiated with a DeposedKey of anything other than states.NotDeposed, so the deleted code is never run. Deposed objects get a NodeDestroyDeposedResourceInstanceObject instead.

* tfdiags: add helper func

* configs: introduce removed block type

* terraform: add forget action

* renderer: render forget actions

* terraform: deposed objects can be forgotten

Deposed objects encountered during planning spawn
NodePlanDeposedResourceInstanceObject, which previously generated a
destroy change. Now it will generate a forget change if the deposed
object is a forget target, and a destroy change otherwise.

The apply graph gains a new node type,
NodeForgetDeposedResourceInstanceObject, whose execution simply removes
the object from the state.

* configs: add RemoveTarget address type

* terraform: modules can be forgotten

* terraform: error if removed obj still in config

* tests: better error on restore state fail

* Update CHANGELOG.md
2023-11-29 11:58:28 +00:00
Liam Cervante
01c0480e77
Test framework will produce regular updates in -json mode (#33953)
* Test framework will produce regular updates in -json mode

* add tests

* docs

* docs tweaking
2023-10-02 09:14:20 +02:00
Liam Cervante
ffbcaf8bef
Implement TFC integration for private module registry test runs (#33710)
* implement module testing via TFC

* ready for review

* fix static checks

* licence headers
2023-09-14 09:01:25 +02:00
Liam Cervante
487eeda94e
[testing framework] Add documentation (#33454)
* [terraform test] add docs

* Apply suggestions from code review

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>

* polish remaining comments

* Apply suggestions from code review

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>

* address remaining comments

* typo

* update verbose machine readable docs

* standardise new JSON field names

---------

Co-authored-by: Rose M Koron <32436232+rkoron007@users.noreply.github.com>
2023-08-31 11:45:52 +02:00
Liam Cervante
2ea141b3f4
Embed the schemas directly in the testing framework JSON verbose outputs (#33755) 2023-08-28 10:25:29 +02:00
hashicorp-copywrite[bot]
53c34ff49c
Update copyright file headers to BUSL-1.1 2023-08-10 23:43:27 +01:00
Nick Fagerlund
0df3c143bb New plans.Quality type for display-relevant facts about a plan
This commit replaces the existing jsonformat.PlanRendererOpt type with a new
type with identical semantics, located in the plans package.

We needed to be able to exchange the facts represented by
`jsonformat.PlanRendererOpt` across some package boundaries, but the jsonformat
package is implicated in too many dependency chains to be safe for that purpose!
So, we had to make a new one. The plans package seems safe to import from all
the places that must emit or accept this info, and already contains plans.Mode,
which is effectively a sibling of this type.
2023-07-24 14:12:44 -04:00
James Bardin
cf5ebaf685 s/Schemas/ProviderSchema/ 2023-07-06 10:37:35 -04:00
James Bardin
36d34135ad replace remaining types in tests 2023-07-06 10:37:35 -04:00
Liam Cervante
3613e972c5
Plan renderer: Support users indexing integer paths with stringified numbers (#33475) 2023-07-05 11:11:02 +02:00
kmoe
b4d1146f58
plannable import: improve gen config human plan output (#33194)
* renderer: remove hard-coded config gen path

* mention config gen file in plan next steps
2023-05-15 15:21:41 +01:00
Liam Cervante
4d837df546
Plannable import: Add generated config to JSON and human-readable plan output (#33154)
* command: keep our promises

* remove some nil config checks

Remove some of the safety checks that ensure plan nodes have config attached at the appropriate time.

* add GeneratedConfig to plan changes objects

Add a new GeneratedConfig field alongside Importing in plan changes.

* add config generation package

The genconfig package implements HCL config generation from provider state values.

Thanks to @mildwonkey whose implementation of terraform add is the basis for this package.

* generate config during plan

If a resource is being imported and does not already have config, attempt to generate that config during planning. The config is generated from the state as an HCL string, and then parsed back into an hcl.Body to attach to the plan graph node.

The generated config string is attached to the change emitted by the plan.

* complete config generation prototype, and add tests

* Plannable import: Add generated config to json and human-readable plan output

---------

Co-authored-by: Katy Moe <katy@katy.moe>
2023-05-11 08:50:03 +02:00
hashicorp-copywrite[bot]
bb36298b21 [COMPLIANCE] Add Copyright and License Headers 2023-05-08 15:47:42 -07:00
Liam Cervante
77f10c4f68
Imports should come before Adds in change summaries (#33147) 2023-05-04 15:06:48 +02:00
Liam Cervante
54c1c1162f
[Plannable Import] Implement human-readable plan rendering (#33113)
* [plannable import] embed the resource id within the changes

* add the plannable imports to the json and human plans

* latest importing struct
2023-05-03 18:50:04 +02:00
hashicorp-copywrite[bot]
325d18262e [COMPLIANCE] Add Copyright and License Headers 2023-05-02 15:33:06 +00:00
Liam Cervante
b5576159da
Migrate 'state show' command to new renderer (#33116)
* Migrate 'state show' command to new renderer

* handle error
2023-05-02 15:27:59 +02:00
Lauren
50c3f53595 add resource_drift logtype 2023-04-24 15:08:33 -04:00
Liam Cervante
b54668f44c
make the unknown attribute renderer consider the force replacement metadata (#33065) 2023-04-24 11:02:32 +02:00
Liam Cervante
519a18aedf
Propagate unknown and sensitive metadata to dynamic attributes (#33057)
* propagate unknown and sensitive metadata to dynamic attributes

* update goimports and add some comments
2023-04-24 10:28:21 +02:00
Liam Cervante
357012a2f3
Refactor of differ to make code reuse easier (#33054)
* refactor of differ to make code reuse easier

* fix imports
2023-04-21 09:51:55 +02:00
Sebastian Rivera
e6c3aab6c5
Merge pull request #33018 from hashicorp/tf-5529-sro-tfe-version-check 2023-04-14 11:55:12 -04:00
Liam Cervante
2c624acea1
Fix rendering unknown values in map and null string primitives (#33029)
* fix rendering unknown values in map and null string primitives

* Update map.go

* fix code consistency checks
2023-04-14 09:56:32 +02:00
Sebastian Rivera
300a60f393 Fix typo in format version check 2023-04-13 18:30:56 -04:00
Liam Cervante
978263efe9
Checks: Introduce check blocks into the terraform node and transform graph (#32735)
* Add support for scoped resources

* refactor existing checks addrs and add check block addr

* Add configuration for check blocks

* introduce check blocks into the terraform node and transform  graph

* address comments

* address comments

* don't execute checks during destroy operations

* don't even include check nodes for destroy operations
2023-03-23 16:07:31 +01:00
James Bardin
5ed7f2a798 always use the RenderHuman constructor 2023-03-14 10:04:28 -04:00
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
Sebastian Rivera
6d0a191ec4 Handle provisioner log types in renderer 2023-02-16 10:54:58 -05: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
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