Commit Graph

1407 Commits

Author SHA1 Message Date
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
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
Liam Cervante
af05cbb645
Add support for scoped resources (#32732) 2023-03-10 11:11:10 +01:00
Liam Cervante
32f151f20b
Update HCL to handle type mismatches when applying defaults (#32775)
* add test reproducing terraform crash

* pull latest hcl

* add missing go.sum file

* also fix tests broken by go-cty update
2023-03-09 14:29:58 +01:00
Eugene Dementyev
36aac6b498
Fixes depends_on when overriding modules (#32796)
Fixes #32795
2023-03-09 11:53:13 +01:00
Alisdair McDiarmid
b088c67c60
Merge pull request #32781 from hashicorp/alisdair/rip-earlyconfig
initwd: Port from `earlyconfig` to `configs`
2023-03-06 15:02:06 -05:00
Alisdair McDiarmid
584811b829 initwd: Add fake range for fake root module
This isn't currently used anywhere downstream, but it easily could be in
the future, so populating the range with some zero-ish data is more
robust.
2023-03-06 14:35:06 -05:00
Alisdair McDiarmid
ca53ca00f4 Remove failing DNS query in cloud tests
This test case was making a real DNS call in a non-acceptance test, and
since it was intended to fail it would introduce a several second delay.
This commit replaces the test with a similar one which uses the mocked
disco services for a non-TFE host.

Also restructure the test to use t.Run for clarity.
2023-03-06 09:32:03 -05:00
Alisdair McDiarmid
19e635bfc8 Remove polling delays in run tasks test
These delays are not relevant to the test and result in increased test
execution time.
2023-03-06 09:14:59 -05:00
Alisdair McDiarmid
d9eae48a75 Remove redundant CheckCoreVersionRequirements 2023-03-06 09:14:28 -05:00
Alisdair McDiarmid
60ea68edc7 Remove earlyconfig 2023-03-06 09:14:28 -05: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
kmoe
76b34e891c
remove unused actionforchange (#32759) 2023-03-01 14:15:26 +00: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
Brandon Croft
3d1a58d5b5
Merge pull request #32708 from mrinalirao/mr/taskStage-race
Bug Fix where CLI exits if run is not confirmable.
2023-02-21 18:17:51 -07: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
Brandon Croft
ec4f62078a
Merge pull request #32666 from hashicorp/sebasslash/fix-credentials-sourcing-backend
Fix SRO authorization bug when token is fetched from cloud config
2023-02-21 16:40:53 -07:00
kmoe
b435b4ccde
cliconfig: more provider_installation err detail (#32722) 2023-02-21 18:18:57 +00:00
Sebastian Rivera
3f23a9e70a
Merge pull request #32696 from hashicorp/sebasslash/sro-provisioner-logs
Handle provisioner log types when rendering structured logs
2023-02-21 11:44:16 -05:00
Daniel Banck
f29156cdef
Replace HTML entities in function descriptions (#32710) 2023-02-20 14:11:06 +00:00
Mrinali Rao
afc9235f17
Update internal/cloud/backend_taskStages.go
Co-authored-by: Glenn Sarti <glennsarti@users.noreply.github.com>
2023-02-20 18:35:58 +11:00
mrinalirao
3104811c7d add test to see if override continues to poll on success 2023-02-20 17:50:25 +11:00
mrinalirao
190858b9e4 Bug Fix where CLI exits if run is not confirmable. 2023-02-20 17:18:13 +11:00
James Bardin
014a425d0e
Merge pull request #32683 from hashicorp/jbardin/import-terraform-data
allow terraform_data to import
2023-02-17 09:51:02 -05: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
Martin Atkins
f0de9b60c1 backend/local: Periodically persist intermediate state snapshots
Terraform Core emits a hook event every time it writes a change into the
in-memory state. Previously the local backend would just copy that into
the transient storage of the state manager, but for most state storage
implementations that doesn't really do anything useful because it just
makes another copy of the state in memory.

We originally added this hook mechanism with the intent of making
Terraform _persist_ the state each time, but we backed that out after
finding that it was a bit too aggressive and was making the state snapshot
history much harder to use in storage systems that can preserve historical
snapshots.

However, sometimes Terraform gets killed mid-apply for whatever reason and
in our previous implementation that meant always losing that transient
state, forcing the user to edit the state manually (or use "import") to
recover a useful state.

In an attempt at finding a sweet spot between these extremes, here we
change the rule so that if an apply runs for longer than 20 seconds then
we'll try to persist the state to the backend in an update that arrives
at least 20 seconds after the first update, and then again for each
additional 20 second period as long as Terraform keeps announcing new
state snapshots.

This also introduces a special interruption mode where if the apply phase
gets interrupted by SIGINT (or equivalent) then the local backend will
try to persist the state immediately in anticipation of a
possibly-imminent SIGKILL, and will then immediately persist any
subsequent state update that arrives until the apply phase is complete.
After interruption Terraform will not start any new operations and will
instead just let any already-running operations run to completion, and so
this will persist the state once per resource instance that is able to
complete before being killed.

This does mean that now long-running applies will generate intermediate
state snapshots where they wouldn't before, but there should still be
considerably fewer snapshots than were created when we were persisting
for each individual state change. We can adjust the 20 second interval
in future commits if we find that this spot isn't as sweet as first
assumed.
2023-02-14 15:17:56 -08:00
James Bardin
3b953d3bd8 allow terraform_data to import
The terraform provider was panicking on import, because it didn't
previously have a resource type which could be imported at all. Add a
stub import function for terraform_data as a placeholder to allow the
call to complete successfully. While there's no need to actually import
a terraform_data resource, users will inevitably use this to construct
examples of import actions for learning purposes or bug reports.

This still isn't very useful even for examples however, because the
state-only nature of the terraform_data resource type means that we
can't fill in the state from only the import ID. This means that any
value in `trigger_replace` or `input` will cause a change in the next
plan. Once configuration data is available during import we can extend
this to create a logical final state based on config.
2023-02-14 09:37:21 -05: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
yokomotod
a62f4f0763
sort modules.json for stable order (#32618) 2023-02-13 18:26:16 +01:00
Alisdair McDiarmid
b7042e818f
Merge pull request #32664 from hashicorp/alisdair/do-not-add-orphan-nodes-for-deposed-instances
Do not add orphan nodes for deposed instances
2023-02-13 09:50:48 -05:00
Alisdair McDiarmid
12d00e6571
Merge pull request #32663 from hashicorp/alisdair/read-resource-instance-state-nil-checks
Fix panic when planning orphaned deposed instances
2023-02-13 09:50:28 -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
Yin Luo
e9b066f514
Support assume role for cos backend (#32631)
* go get github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts/v20180813@v1.0.588

* feat:support assume_role for COS backend

* update go.mod and go.sum

* change secret_id and secret_key from required to optional

* update cos doc

* update logic by comments

* rm sensitive info in log
2023-02-13 10:25:58 +01:00
Brandon Croft
26e85685d1
Merge pull request #32647 from hashicorp/TF-4390-backport-initial-remote-state-serial-fix
Begin cloud remote state with serial > 0
2023-02-10 15:35:37 -07:00
Sebastian Rivera
71dac9bf5e Add token field to cloud backend 2023-02-10 16:58:14 -05:00
Alisdair McDiarmid
7ecb0b8ffb Do not add orphan nodes for deposed instances
Resource instances with no current object in state should not have
orphan nodes added to the graph, as deposed objects are handled
separately. This was previously handled correctly for the non-expanded
case, but expanded resources were missing the appropriate check for a
current object.

Also update the comment in the non-expanded case to hopefully clarify
that we're checking for the presence of a current object, not the
absence of any deposed objects. An instance may have both a current
object and zero or more deposed objects in some circumstances, and if
so, we still want an orphan node to be added if the instance is not in
configuration.
2023-02-10 16:25:11 -05:00
Alisdair McDiarmid
8997e5b8c6 Fix panic when planning orphaned deposed instances 2023-02-10 15:31:21 -05:00
megan07
d7d8a2262c
Merge pull request #32557 from bharathkkb/gcs-backend-impersonate-envvar
Add a GCS backend specific env var for impersonation
2023-02-09 09:28:26 -06: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
Brandon Croft
de7304cacb
Begin cloud remote state with serial > 0 2023-02-08 14:43:57 -07:00
Liam Cervante
4fa7cd0a68
structured renderer: fix closing json tags when rendering with no symbols (#32642) 2023-02-08 16:47:12 +01:00
James Bardin
1307317457
Merge pull request #32614 from yardbirdsax/fix/30670
make remote state initial behavior the same as local state
2023-02-07 17:43:28 -05:00
James Bardin
2d9e3da983
Update internal/states/remote/state.go
Fix from review

Co-authored-by: Nathan Mische <nmische@gmail.com>
2023-02-07 17:35:56 -05: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