Commit Graph

1093 Commits

Author SHA1 Message Date
James Bardin
553b8c6de5 expand module subdir globs 2022-08-17 16:27:58 -04:00
Alisdair McDiarmid
4960e6aeba
Merge pull request #31634 from hashicorp/alisdair/optional-object-attribute-explicit-null
typeexpr: Replace null attr values with defaults
2022-08-17 08:54:21 -04:00
kmoe
56a1e0d1c6
allow cross-package move statements (#31556) 2022-08-16 16:52:57 +02:00
Alisdair McDiarmid
27966044ba
Merge pull request #28191 from zimbatm/terraform-fmt-manyargs
command/fmt: support formatting multiple files
2022-08-12 13:53:23 -04:00
Alisdair McDiarmid
c85ae29419 typeexpr: Replace null attr values with defaults
Previously, when applying defaults to an input variable's given value
before type conversion, we would permit `null` attribute values to
override a specified default. This behaviour is inconsistent with the
intent of the type system underlying Terraform, and represented a
divergence from the treatment of `null` as equivalent to unset which
exists in resources. The same behaviour exists in top-level variable
definitions with `nullable = false`, and we consider this to be the
preferred behaviour here too.

This commit slightly changes default value application such that an
explicit `null` attribute value is treated as equivalent to the
attribute being missing. Default values for attributes will now replace
explicit nulls.
2022-08-12 10:26:36 -04:00
James Bardin
893a5336d8 don't lose warnings from static validation
Warnings were dropped from static reference validation if there weren't
also errors in the configuration.
2022-08-09 16:15:56 -04:00
James Bardin
8354bc46cf
Merge pull request #31576 from hashicorp/jbardin/validate-deprecated-computed
validate deprecated attributes from static traversals
2022-08-09 11:10:13 -04:00
James Bardin
1a5e403329
Merge pull request #31532 from hashicorp/jbardin/static-validate-nested-types
Account for `NestedType` in static traversal validation
2022-08-09 11:08:17 -04:00
kmoe
621af43c04
fix missing output for applyable refresh plans (#31469) 2022-08-09 16:03:59 +01:00
James Bardin
25f5a81048 validate deprecated attrs from static traversals
We can't validate that data from deprecated nested attributes is used in
the configuration, but we can at least catch the simple case where a
deprecated attribute is referenced directly.
2022-08-08 09:58:11 -04:00
zimbatm
7a9ccc03b2
command/fmt: support formatting multiple files
All the code infrastructure was there to support formatting multiple
files already.

This makes `terraform fmt` more flexible and also compliant with the
[treefmt formatter
spec](https://numtide.github.io/treefmt/docs/formatters-spec.html)
2022-08-07 15:02:55 +02:00
Radek Simko
fc62afb6dc
fix: validate implied provider names in submodules (#31573) 2022-08-05 20:44:52 +01:00
James Bardin
fd76846d35 two more locations where Attribute.Type was used 2022-08-04 17:17:00 -04:00
James Bardin
43100fbe39 handle nested types in StaticValidateTraversal
The StaticValidateTraversal code was not taking into account nested
structural types. Rather than create more special cases for checking
Type vs NestedType, we move the ImpliedType method up to the Attribute
to ensure both are used to generate the final type spec.
2022-08-04 17:17:00 -04:00
kmoe
c4a00664d7
do not create delete change for nonexistent output (#31471)
If there are outputs in configuration, a destroy plan will always contain a "delete" change for each of these outputs.

This leads to meaningless delete changes being present for outputs which were not present in state and therefore cannot be deleted. Since there is a change in the plan, this plan will then be considered applyable, and the user will be presented with text instructing them to apply a plan in which there are no actual changes.

This commit stops the above from happening in the case of root module outputs.
2022-08-03 17:45:13 +01:00
sebhcp
1ad649c446 goimports on providers.go only 2022-08-01 16:38:03 -05:00
sebhcp
e029e7b699 revert "run goimports"
This reverts commit 301174a3df.
2022-08-01 16:26:26 -05:00
sebhcp
301174a3df run goimports 2022-08-01 16:26:07 -05:00
sebhcp
4d799ab30f normalize [dir] to [DIR] 2022-08-01 16:26:07 -05:00
Radek Simko
c1fc7fd744
providercache: include host in provider installation error (#31524) 2022-07-29 10:50:05 +01:00
Radek Simko
b82eee6c9f
getproviders: account for occasionally missing Host header in errors (#31542) 2022-07-29 10:23:50 +01:00
Brandon Croft
c62e20c78f
Merge pull request #31507 from hashicorp/brandonc/output_cloud_reads
`terraform output` should adhere to Terraform Cloud authorization
2022-07-28 11:53:55 -06:00
Brandon Croft
50d48c635e
remove unused error and fix output authorization detection 2022-07-28 11:44:16 -06:00
Brandon Croft
0139e75a1a
feature: fall back to reading entire state when detailed-type is not available 2022-07-25 17:17:24 -06:00
Brandon Croft
e1fa690879
style: goimports fixes 2022-07-25 14:51:34 -06:00
Brandon Croft
166d21b20b
refactor: extract cloud state ctyValue conversion function 2022-07-25 14:48:32 -06:00
James Bardin
a6a08fe84a AssertPlanValid for computed with config value
Return early from AssertPlanValid for any attribute which is only
computed. We currently fail if there's a config value, but that could
only happen because of core, not because of the provider.
2022-07-25 16:07:58 -04:00
Brandon Croft
e794efc31e
better errors from terraform output when cloud is configured 2022-07-25 10:05:20 -06:00
Brandon Croft
c33c8b013f
fix: have terraform output adhere to authorization w/ cloud
Normally, `terraform output` refreshes and reads the entire state in the command package before pulling output values out of it. This doesn't give Terraform Cloud the opportunity to apply the read state outputs org permission and instead applies the read state versions permission.

I decided to expand the state manager interface to provide a separate GetRootOutputValues function in order to give the cloud backend a more nuanced opportunity to fetch just the outputs. This required moving state Refresh/Read code that was previously in the command into the shared backend state as well as the filesystem state packages.
2022-07-25 10:04:43 -06:00
Martin Atkins
72dd14ca5c core: Do everything except the actual action for plans.NoOp
Previously we tried to early-exit before doing anything at all for any
no-op changes, but that means we also skip some ancillary steps like
evaluating any preconditions/postconditions.

Now we'll skip only the main action itself for plans.NoOp, and still run
through all of the other side-steps.

Since one of those other steps is emitting events through the hooks
interface, this means that now no-op actions are visible to hooks, whereas
before we always filtered them out before calling. I therefore added some
additional logic to the hooks to filter them out at the UI layer instead;
the decision for whether or not to report that we visited a particular
object and found no action required seems defensible as a UI-level concern
anyway.
2022-07-22 15:27:15 -07:00
Martin Atkins
9e277033bc core: Create apply graph nodes even for no-op "changes"
We previously would optimize away the graph nodes for any resource
instance without a real change pending, but that means we don't get an
opportunity to re-check any invariants associated with the instance, such
as preconditions and postconditions.

Other upstream changes during apply can potentially decide the outcome of
a condition even if the instance itself isn't being changed, so we do
still need to revisit these during apply or else we might skip running
certain checks altogether, if they yielded unknown results during planning
and then don't get run during apply.
2022-07-22 15:27:15 -07:00
Martin Atkins
3cd069900b core: Use DynamicExpand even for root module outputs
We previously had a special case in the graph transformer for output
values where it would directly create an individual output value node
instead of an "expand" node as we would do for output values in nested
modules.

While it's true that we do always know that expanding a root module
output value will always produce exactly one instance, treating this case
as special creates the risk of those two codepaths diverging in other
ways.

Instead, we'll let the expand node also deal with root modules and
minimize the special case only to how we look up any changes for the
output values, since the design of plans.Changes is a bit awkward and
requires us to ask the question differently for root module output values.
Otherwise, the behavior will now be consistent across all output values
regardless of module.
2022-07-22 15:25:22 -07:00
Brandon Croft
74ee19b864
Merge pull request #31466 from hashicorp/aw/send-jsonstateoutputs
Include JSONStateOutputs
2022-07-22 14:49:09 -06:00
James Bardin
8b1b05f50f
Merge pull request #31499 from hashicorp/jbardin/dag-walks
topological sorting for refactoring
2022-07-22 15:41:37 -04:00
Brandon Croft
7892cb6b5a
reformat imports using goimports 2022-07-22 12:03:03 -06:00
James Bardin
e3ca4be4b9 goimports 2022-07-22 13:57:16 -04:00
James Bardin
dc9d7108dd use TopologicalOrder for evaluating moves
The dag package did not previously provide a topological walk of a given
graph. While the existing combination of a transitive reduction with a
depth-first walk appeared to accomplish this, depth-first is only
equivalent with a simple tree. If there are multiple paths to a node, a
depth-first approach will skip dependencies from alternate paths.
2022-07-22 13:57:16 -04:00
James Bardin
ca272b2107 Add methods for topological sorts
A topological walk was previously only done in Terraform via the
concurrent method used for walking the primary dependency graph in core.
Sometime however we want a dependency ordering without the overhead of
instantiating the concurrent walk with the channel-based edges.

Add TopologicalOrder and ReverseTopologicalOrder to obtain a list of
nodes which can be used to visit each while ensuring that all
dependencies are satisfied.
2022-07-22 13:57:16 -04:00
Brandon Croft
0b9bd2fc36
make cloud backend_state error messages more conventional 2022-07-22 11:31:48 -06:00
Brandon Croft
01d510f3cb
test(cloud): ensure state version is created when saving state 2022-07-22 11:26:28 -06:00
Anna Winkler
d72911a640 Save detailed type outputs to JSONStateOutputs 2022-07-22 10:28:20 -06:00
James Bardin
95019e3d02 Implement breadth-first walks and add tests
Make DAG walks test-able, and add tests for more complex graph ordering.
We also add breadth-first for comparison, though it's not used currently
in Terraform.
2022-07-22 11:01:29 -04:00
Martin Atkins
69aa0a2b1f states/remote: use t.Run in table-based tests
These tests were originally written long before Go supported subtests
explicitly, but now that we have t.Run we can avoid the prior problem
that one test failing would mask all of the others that followed it.

Now we'll always run all of them, potentially collecting more errors in
a single run so we can have more context to debug with and potentially
fix them all in a single step rather than one by one.
2022-07-21 13:40:56 -07:00
Liam Cervante
ad5ac89461
Fix tests failing on main (#31481) 2022-07-20 14:10:48 +01:00
Liam Cervante
9f0d1d0630
terraform init: add link to documentation when a checksum is missing from the lock file (#31408)
* terraform init: add suggested fix for when a checksum is missing from the lock file

* improve error message

* add link to the documentation

* cleanup leftovers from previous attempt

* fix tests

* s/,/;

* fix imports
2022-07-20 13:28:16 +01:00
Liam Cervante
83e84e5477
terraform init: add warning and guidance when lock file is incomplete (#31399)
* terraform init: add warning and guidance when lock file is incomplete

* make the provider list in the warning deterministic

* create installer event for tracking provider lock hashes (#31406)

* create installer event for tracking provider lock hashes

* address comments

* fix tests

* improve error message

* Update internal/command/init.go

Co-authored-by: Martin Atkins <mart@degeneration.co.uk>

Co-authored-by: Martin Atkins <mart@degeneration.co.uk>
2022-07-20 13:28:04 +01:00
Liam Cervante
224728879d
Ignore existing package hashes for providers lock command (#31389)
* Ignore existing package hashes for  command

* missing new line

* Fix incorrect logic when deciding change message

* fix imports
2022-07-20 13:27:24 +01:00
kmoe
7b4a5513a9
command: fix panic on show when state file is invalid or unavailable (#31444) 2022-07-15 17:31:56 +01:00
hellertang
0dbf0711a0
cos backend support accelerate (#31425) 2022-07-15 17:07:41 +01:00
Alisdair McDiarmid
d3284bdc4e
Merge pull request #31220 from FooBartn/string-starts-ends-with-funcs
feat: add startswith and endswith funcs
2022-07-14 13:13:04 -04:00