Commit Graph

1453 Commits

Author SHA1 Message Date
Roberto Hidalgo
1b7f772f8b
fix breaking code
this is what i get for submitting PRs late at night
2023-04-27 10:13:38 -06:00
Roberto Hidalgo
0dda1d5c61
Return debuggeble CAS errors on consul state put
ran into this error while running terraform on a container and saving state to Consul. I suspect my policy needs tweaking but it's impossible to tell with an error like this:

```
╷
│ Error: Failed to save state
│ 
│ Error saving state: consul CAS failed with transaction errors:
│ [0xc0006e93c8]
╵
```

This PR makes the will include the error messaage in the details so I can continue debugging
2023-04-26 23:44:39 -06:00
Zac Clifton
3bb6a5896b
Feat: Add strcontains function and documentation (#33069)
* add strcontains function and documentation
2023-04-26 20:41:32 +01:00
Alisdair McDiarmid
0ffdd07980 Fix goimports discrepancies 2023-04-26 14:33:13 -04:00
kmoe
c6400fabb1
configs: add import block (#33081) 2023-04-26 16:28:11 +01:00
kmoe
531efd303b
add types for plannable import (#33080) 2023-04-25 15:19:48 +01:00
Lauren
50c3f53595 add resource_drift logtype 2023-04-24 15:08:33 -04:00
James Bardin
d47d475a03
Merge pull request #33079 from hashicorp/jbardin/destroy-plan-faster-providers
skip inter-provider cycle check in destroy plan
2023-04-24 12:29:05 -04:00
James Bardin
583350a5c4 skip inter-provider cycle check in destroy plan
Just like in the destroy apply, we can skip the inter-provider cycle
check when creating the destroy plan, which can be expensive when there
are a lot of resource instances with dependencies from another provider.
2023-04-24 12:12:40 -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
14123e277c
Include sensitive metadata from the schema when building the json state output (#33059)
* include sensitive metadata from the schema when building the json state output

* found another test case
2023-04-24 10:52:44 +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
Liam Cervante
aae6990d38
Add native plantimestamp function to Terraform (#32980)
* add plantimestamp function

* documentation

* add missing links

* fix typo
2023-04-21 09:47:28 +02:00
Rémi Lapeyre
af571b2642
Improve environment variable support for the pg backend (#33045)
* Improve environment variable support for the pg backend

This patch does two things:
  - it adds environment variable support to the parameters that did
    not have it (and uses `PG_CONN_STR` instead of `PGDATABASE` which is
    actually more appropriate to match the behavior of other PostgreSQL
    utilities)
  - better documents how to give the connection parameters as environment
    variables for the ones that were already supported based on the
	recommendation of @bsouth00

I will prepare a backport of the documentation part of this once it is
merged.

Closes https://github.com/hashicorp/terraform/issues/33024

* Remove global variable in test of the PG backend
2023-04-21 08:39:19 +02:00
Glenn Sarti
7e2e834aff
Emit warnings for certain run events in cloud backend (#33020)
The cloud backend, which communicates with TFC like APIs, can create
runs which may have one more configuration parameters altered. These
alterations are emitted as run-events on the run so that API clients
can consume and display them to users. This commit adds a step in
plan operation to query the run-events once a run is created and then
emit specific run-event descriptions to the console as warnings for
the user.
2023-04-17 08:53:47 -07: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
Sebastian Rivera
5634ae3e18 Unit tests to ensure renderer is appropriately called 2023-04-13 18:30:56 -04:00
Sebastian Rivera
b23cfaefe8 Refactor SRO check to prevent duplicate plan output 2023-04-13 18:30:56 -04:00
Liam Cervante
9c87006c34
checks: hide check diagnostics during plans that will not wait for approval (#32938)
* checks: filter out check diagnostics during certain plans

* wrap diagnostics produced by check blocks in a dedicated check block diagnostic

* address comments
2023-04-11 10:54:30 +02:00
James Bardin
acbcbcb311
Merge pull request #32988 from hashicorp/jbardin/destroy-plan-null-type
the destroy plan should use correct type
2023-04-06 09:53:55 -04:00
janaurka
1f603b1a7f
backend/pg: Accept connection string in PGDATABASE environment variable 2023-04-05 15:42:44 -07:00
James Bardin
c872cd6d96 the destroy plan should use correct type
When we plan to destroy an instance, the change recorded should use the
correct type for the resource rather than `DynamicPseudoType`. Most of
the time this is hidden when the change is encoded in the plan, because
any `null` is always encoded to the same value, and when decoded it will
be converted to the schema type. However when apply requires creating a
second plan for an instance's replacement that value is not going to be
encoded, and remains a dynamic value which is sent to the provider.

Most providers won't see that either, as the grpc request also encodes
and decodes the value to conform with the correct schema. The builtin
terraform provider does get the raw cty value though, and when that
dynamic value is returned validation fails when the type does not match.
2023-04-05 10:19:26 -04:00
Liam Cervante
84dc498b90
checks: always reference the nested data source from the check graph node (#32946)
* checks: always reference the nested data source from the check block graph node

* goimports
2023-04-05 08:48:42 +02:00
James Bardin
81b74cdb22 don't compare plan marks for missing values
If a resource has a change in marks from the prior state, we need to
notify the user that an update is going to be necessary to at least
store that new value in the state. If the provider however returns the
prior state value in lieu of a new config value, we need to be sure to
filter any new marks for comparison as well. The comparison of the prior
marks and new marks must take into account whether those new marks could
even be applied, because if the value is unchanged the new marks may be
completely irrelevant.
2023-03-28 15:55:15 -04:00
James Bardin
a4e92f3fca
Merge pull request #32876 from hashicorp/jbardin/state-serialize-plan-error
Remove planned data source objects from state on error
2023-03-28 15:50:59 -04:00
James Bardin
fdb00b9a46
Merge pull request #32900 from hashicorp/jbardin/target-drift-upgrade
External changes report can fail with schema migrations and `-target`
2023-03-28 15:50:38 -04:00
Liam Cervante
c06db2aadd
checks: don't iterate through all the nodes when there is nothing to search for (#32927) 2023-03-28 18:14:27 +02:00
Liam Cervante
5f97f88025
ensure checks are reported before executed (#32925) 2023-03-28 15:20:54 +02: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
Liam Cervante
3827120c25
Checks: Add configuration for check blocks (#32734)
* Add support for scoped resources

* refactor existing checks addrs and add check block addr

* Add configuration for check blocks

* address comments
2023-03-23 09:12:53 +01:00
Liam Cervante
87c457781d
Checks: Refactor existing check addrs and add new check block addr (#32733)
* Add support for scoped resources

* refactor existing checks addrs and add check block addr

* address comments
2023-03-23 09:04:21 +01:00
James Bardin
240e345b45 test for untargeted schema mismatch 2023-03-21 12:55:26 -04:00
James Bardin
b10c4c54d9 prevent errors with -target and provider upgrades
In the case where a provider has been upgraded, and there are external
changes to resources outside of terraform, and -target is being used,
and resources which are not targeted require a schema migration; the
untargeted resources will not have been migrated and cannot be decoded for the
external changes report.

Since there is no way to decode the resources which have been excluded
via -target, we can only skip over them when inspecting
driftedResources. Return warnings for now to indicate that these
resources could not be decoded to help indicate that users will need to
eventually apply these changes.
2023-03-21 12:49:59 -04:00
James Bardin
defd7f0cde test that module outputs maintain sensitive marks 2023-03-20 14:22:08 -04:00
James Bardin
d33e627514 remove old comments 2023-03-20 14:22:08 -04:00
James Bardin
425c6bead2 store non-root sensitive outputs in state
Module outputs are evaluated from state, so in order to have detailed
information about sensitivity from non-root module outputs, we need to
store the value along with all sensitive marks. This aligns with the
usage of state being the in-memory store for other temporary values like
locals and variables.
2023-03-20 13:27:53 -04:00
James Bardin
1ca631bda0 remove planned objects from state on error
When planning encounters an error we were returning early without
cleaning out any planed data sources which cannot be serialized. Move
the cleanup to the common walkPlan method where the PriorState is
assigned so that it cannot be missed.
2023-03-17 08:45:42 -04:00
Martin Atkins
9f827f57ae go.mod: Revert cty minor version v1.13 upgrade
We inadvertently incorporated the new minor release of cty into the 1.4
branch, and that's introduced some more refined handling of unknown values
that is too much of a change to introduce in a patch release.

Therefore this reverts back to the previous minor release for the v1.4
series, and then we'll separately get the main branch ready to work
correctly with the new cty before Terraform v1.5.

This reverts just the upgrade and the corresponding test changes from
#32775, while retaining the HCL upgrade and the new test case it
introduced for that bug it was trying to fix. That new test is still
passing so it seems that the cty upgrade is not crucial to that fix.
2023-03-16 11:48:41 -04:00
Martin Atkins
4e6e0bc47b core: Fix test flake in TestContext2Apply_stop
This test was previously not taking into account the fact that the
"Stopping" hook gets sent in the goroutine that calls ctx.Stop, whereas
all of the others get called from inside ctx.Apply, and so there are no
ordering guarantees for that event in relation to the others.

We now handle the stopping event as a special case that is allowed to
appear anywhere in the sequence as long as it appears. The other events
are still strongly ordered because their ordering is important for
correctness of Terraform Core's own behavior.

As some extra insurance we also now check whether the provider's
ApplyResourceChange and Stop functions both ran and reached a suitable
point of execution related to the stop request, which help to ensure not
only that something called Stop but that Terraform Core correctly
interacted with the provider to handle the stop.
2023-03-15 13:44:33 -07:00
James Bardin
86c0c3bf80
Merge pull request #32846 from hashicorp/fix-32793
emit a warning msg if invalid CLI configuration file location
2023-03-14 14:58:47 -04:00
Reda Khaled
bf723bd65a fix(init_test.go): in TestInitProvidersLocalOnly tst, set TF_CLI_CONFIG_FILE env var to an empty val 2023-03-14 14:47:43 -04:00
Reda Khaled
fa9d044c58 bugfix(cliconfig.go): emit a warning msg if bad CLI config file path 2023-03-14 14:47:43 -04:00
James Bardin
06f1ceb026 add some output values to the show state test 2023-03-14 10:04:37 -04: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
James Bardin
843befff29
Merge pull request #32818 from hashicorp/jbardin/nil-plan
return early from opPlan when the plan is nil
2023-03-10 09:46:55 -05:00
James Bardin
c02e7e8754 return early from opPlan when the plan is nil
While the returned plan is checked for nil in most cases, there was
a single point where the plan was dereferenced which could panic. Rather
than always guarding the dereferences, return early when the plan is
nil.
2023-03-10 09:34:47 -05:00