Commit Graph

28362 Commits

Author SHA1 Message Date
Masayuki Morita 31a5aa1878
command/init: Add a new flag `-lockfile=readonly` (#27630)
Fixes #27506

Add a new flag `-lockfile=readonly` to `terraform init`.
It would be useful to allow us to suppress dependency lockfile changes
explicitly.

The type of the `-lockfile` flag is string rather than bool, leaving
room for future extensions to other behavior variants.

The readonly mode suppresses lockfile changes, but should verify
checksums against the information already recorded. It should conflict
with the `-upgrade` flag.

Note: In the original use-case described in #27506, I would like to
suppress adding zh hashes, but a test code here suppresses adding h1
hashes because it's easy for testing.

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
2021-03-09 11:12:00 -05:00
James Bardin e6ab48addf test data source destroy with no provider 2021-03-08 21:43:47 -05:00
James Bardin 58b085f0dc prune unused providers from the graph, again
The provider transformers remove extra provider nodes when they are
initially setup, but it may turn out that they are not used later on.

The pruneUnusedNodesTransformer takes care of removing unused expansion
nodes, which originally required a provider, and hence may cause some
provider nodes to no longer be needed. We can also detect these and
remove them during the pruneUnusedNodesTransformer process.
2021-03-08 21:43:47 -05:00
James Bardin 7674e19d4e data source destroy nodes do not need a provider
Removing a data source is a state-only operation, and the node itself
does not require a provider.
2021-03-08 15:40:31 -05:00
James Bardin 3c6b2a8780 rename attachDataResourceDependsOnTransformer
Clarify the use of this transformer, interface and method which now does
not apply to anything but `depends_on` for data sources,
2021-03-08 15:39:09 -05:00
Alisdair McDiarmid 98899df514
Merge pull request #27979 from hashicorp/alisdair/defaults-fixes
functions: Fix panics in defaults
2021-03-05 14:39:50 -05:00
Alisdair McDiarmid ac8c6c1aa7
Merge pull request #27998 from hashicorp/alisdair/faster-addr-equals
core: Reduce string allocations for addrs Equal
2021-03-05 14:39:39 -05:00
Alisdair McDiarmid a43b035a51 core: Reduce string allocations for addrs Equal
Generating strings and comparing them to implement Equal is a quick and
easy solution. Unfortunately when this code is in the hot path, it
becomes very expensive, so this commit changes some of those instances
to compare the values directly.

Combined with using addr.Equal instead of checking for string equality,
this makes Terraform dramatically faster for some operations, such as
generating large JSON plans.
2021-03-05 13:23:32 -05:00
Alisdair McDiarmid 3d8b43dfe7
Merge pull request #27944 from hashicorp/alisdair/fix-missing-source-in-diags
views: Fix missing source in diagnostic output
2021-03-04 12:28:42 -05:00
Alisdair McDiarmid 66f8d1c1c2 functions: Fix defaults mismatched types fallback
We allow primitive fallback values which have mismatched types, but only
if there is a conversion to the target type. Previously we would allow
unsafe conversions (e.g. string to bool), but later had no capacity to
return an error if the conversion failed due to the value of the
fallback being unable to convert to the target type.

This commit makes the more conservative requirement that default
fallback values must have a safe conversion.
2021-03-04 10:43:09 -05:00
Alisdair McDiarmid 178a9b32d7 functions: Fix defaults null collections panic
When applying default values to collection types, null collections in
the input should result in empty collections in the output.
2021-03-04 10:13:41 -05:00
Omar Ismail e9c7f37b8c
Enable --auto-approve for Policy checks on Remote Backend (Terraform Cloud) (#27804)
* Fix auto-approve for soft-policy
* Update error handling
* update testing string for consistency
2021-03-01 08:54:30 -05:00
Alisdair McDiarmid 86495f93cb views: Fix missing source in diagnostic output
The previous implementation of views was copying and embedding the base
View struct in each individual view. While this allowed for easy access
to the interface of that struct (both in the view and externally), it more
importantly completely broke the ability of the diagnostic printer to
output source code snippets.

This is because the `configSources` field on the base view is lazily set
after the config loader is initialized. In the commands ported to use
views, this happens after the base View struct is copied, so we are
updating the wrong copy of the struct.

This commit fixes this with a simple mechanical refactor: keep a pointer
to the base View struct instead, and update all of the individual views
to explicitly refer to that struct to access its fields and methods.

This is not a particularly satisfying solution, but I can't find
anything clearly better. It might be worth exploring the alternative
approach in the view for the new test command, which explicitly pulls
its dependencies out of the base view, rather than retaining a full
reference. Maybe there's a third way which is better still.
2021-02-26 16:43:03 -05:00
Martin Atkins b5adc33075 configs: Accept and minimally validate a "language" argument
We expect that in order to continue to evolve the language without
breaking existing modules we will at some point need to have a way to mark
when a particular module is expecting a newer interpretation of the
language.

Although it's too early to do any deep preparation for that, this commit
aims to proactively reserve an argument named "language" inside
"terraform" blocks, which currently only accepts the keyword TF2021 that
is intended to represent "the edition of the Terraform language as defined
in 2021".

That argument also defaults to TF2021 if not set, so in practice there's
no real reason to set this today, but this minimal validation today is
intended to give better feedback to users of older Terraform versions in
the event that we introduce a new language edition later and they try to
use an module incompatible with their Terraform version.
2021-02-26 11:43:32 -08:00
Martin Atkins 54cc4dadf6 configs: A better error message for custom variable validation
Our previous message conflated the requirement for a full sentence with
the suggestion to write in a style similar to Terraform's built-in error
messages, which created a sense that the system would actively reject an
error message written in another language.

There's no intent here to block writing error messages in other languages,
but there is a practical consideration that Terraform's UI output is
currently not localized and so consistency with Terraform's other output,
if that's important to a module author, will typically mean writing the
error message in English.
2021-02-26 09:36:42 -08:00
Aaron Lane f172585eaa Fix Kitchen-Terraform language in test experiment
This isn't incredibly important, but Kitchen-Terraform is written in and requires tests to be written in Ruby.
2021-02-25 14:12:00 -08:00
Alisdair McDiarmid 37fff9336a
Merge pull request #27929 from hashicorp/alisdair/command-views-cleanup
Some command views cleanup
2021-02-25 16:26:08 -05:00
Alisdair McDiarmid 7c0ec0107f backend: Replace ShowDiagnostics with view.Diagnostics 2021-02-25 11:26:05 -05:00
James Bardin 1a71cdc132
Merge pull request #27926 from hashicorp/jbardin/apply-plan-config
check errors before using configSnap
2021-02-25 10:10:13 -05:00
James Bardin 936f597ba1 check errors before using configSnap
configSnap may be nil if there are errors loading it from the plan file.
2021-02-25 09:54:02 -05:00
Alisdair McDiarmid 3737ee5081 views: Remove outdated comment 2021-02-25 09:34:32 -05:00
Kristin Laemmert c99d02f326
update arch docs; remove old EvalNode references (#27900)
* update arch docs; remove old EvalNode and EvalTree references
2021-02-24 16:19:55 -05:00
James Bardin a0ca99201c
Merge pull request #27918 from hashicorp/jbardin/go-version
Revert "match terraform-releases expectations"
2021-02-24 16:17:49 -05:00
James Bardin 9ea805f480 Revert "match terraform-releases expectations"
This reverts commit 270de49ef5.
2021-02-24 14:33:24 -05:00
James Bardin 55fb442578
Merge pull request #27913 from hashicorp/jbardin/go-version
match terraform-releases expectations
2021-02-24 14:14:58 -05:00
James Bardin 270de49ef5 match terraform-releases expectations 2021-02-24 14:08:12 -05:00
Kristin Laemmert 106bcd3bf0
update to match new default branch name (#27909) 2021-02-24 13:36:47 -05:00
James Bardin 2b252ac677
Merge pull request #27910 from hashicorp/jbardin/remote-provisioners
remote provisioners require a connection config
2021-02-24 13:35:24 -05:00
James Bardin 47a682141a remote provisioners require a connection config 2021-02-24 13:25:58 -05:00
Martin Atkins 45b795b3fd
Update CHANGELOG.md 2021-02-24 10:09:08 -08:00
Alisdair McDiarmid 6697245c18
Update CHANGELOG.md 2021-02-24 12:45:51 -05:00
James Bardin 8c9083d880
Merge pull request #27903 from hashicorp/jbardin/plan-valid-computed
objchange: catch invalidly planned attributes earlier
2021-02-24 12:44:35 -05:00
Alisdair McDiarmid 326583bb6e
Merge pull request #27906 from hashicorp/alisdair/remove-var-args-from-validate
cli: Remove -var/-var-file flags from validate
2021-02-24 12:43:53 -05:00
James Bardin b735d80f1f website: Provider configuration notes for the v0.15 upgrade guide 2021-02-24 09:37:55 -08:00
Martin Atkins 9508ff2630 website: Terraform v0.15 upgrade guide first draft
As usual, we'll continue to iterate on this based on feedback and
questions during the beta period, but this is a first draft intended to
help those who are trying out the first beta.
2021-02-24 09:37:55 -08:00
Alisdair McDiarmid 4271b0e11d cli: Remove -var/-var-file flags from validate
These flags are not used and have been deprecated since 0.12.11.
2021-02-24 12:29:56 -05:00
Kristin Laemmert e5a7586559
moduletest: update provider to match recent provider interface changes (#27904)
this fixes a bad merge on my part
2021-02-24 12:29:45 -05:00
James Bardin cd7fb9bd5a catch invalidly planned attributes earlier
Catch attributes which are planed but not computed separately to provide
a clearer error to provider developers.

The error conditions were previously caught, however it was unclear from
the error text as to _why_ the change was an error. The statements about
value inequality would be incorrect when planning no changes for a value
which should not have been set in the first place.
2021-02-24 12:13:12 -05:00
Kristin Laemmert ff05362d51
providers.Interface: rename ValidateDataSourceConfig to ValidateDataResourceConfig (#27874)
* providers.Interface: rename ValidateDataSourceConfig to
ValidateDataResourceConfig

This PR came about after renaming ValidateResourceTypeConfig to
ValidateResourceConfig: I now understand that we'd called it the former
instead of the latter to indicate that the function wasn't necessarily
operating on a resource that actually exists. A possibly-more-accurate
renaming of both functions might then be ValidateManagedResourceConfig
and ValidateDataResourceConfig.

The next commit will update the protocol (v6 only) as well; these are in
separate commits for reviewers and will get squashed together before
merging.

* extend renaming to protov6
2021-02-24 12:04:28 -05:00
Antoine Cotten 21d881d4d1
Update "Terraform Core Architecture Summary" doc (#27897)
* Update Godoc links from godoc.org to pkg.go.dev

* Update reference to renamed GraphNodeResource interface

Ref hashicorp/terraform#24389

* Update dead links; minor formatting adjustments

* Add FIXME item following deprecation of EvalNode
2021-02-24 08:32:08 -05:00
Alisdair McDiarmid 7a03c3153e
Merge pull request #27861 from hashicorp/alisdair/help-global-options
cli: Add reference to global options to help text
2021-02-23 14:19:08 -05:00
Alisdair McDiarmid 79f855b83b
Merge pull request #27840 from OJFord/docs-27554
Document `inline` & `on_failure` behaviour
2021-02-23 13:15:56 -05:00
Rachel Sharp 3cb4918739
Merge pull request #27862 from hashicorp/add-state-learn-tutorial
Add State Learn tutorial to State docs
2021-02-23 13:11:27 -05:00
Martin Atkins 7597f4791e
Update CHANGELOG.md 2021-02-23 10:01:00 -08:00
James Bardin c103242bef
Merge pull request #27885 from hashicorp/jbardin/show-json
jsonstate: indicate schema version mismatch during encoding
2021-02-23 12:57:06 -05:00
Martin Atkins 5f3fb00af5 config: Use Unicode 13 rules for string manipulation
Although we don't typically do configuration-level string wrangling
directly in Terraform, we delegate to several other upstream libraries
that do. These upgrades all switch to newer versions that support the
latest definitions from Unicode 13, primarily affecting operations such
as converting strings to upper/lowercase or splitting strings into
component characters (substr, reverse, etc).

The tests for the upstream libraries didn't show any regressions from
these updates, so the Unicode 13 changes seem to be backward-compatible
additions rather than significant breaking changes.

(Our go.mod file had also become non-canonical in some ways, and the Go
toolchain fixed that as part of this work, causing a few extra style-only
diffs here that shouldn't cause any change in behavior.)
2021-02-23 09:56:06 -08:00
Martin Atkins e3abe9020d build: Terraform is now built with Go 1.16 2021-02-23 09:56:06 -08:00
James Bardin c7995b7d4b update show -json docs 2021-02-23 11:45:50 -05:00
James Bardin 160020a1e1
Merge pull request #27824 from hashicorp/jbardin/proxy-providers
Provider transformer cleanup
2021-02-23 10:54:41 -05:00
James Bardin 3449a8aa35 don't marshal state with the wrong schema
Instead of returning an error with no context about unexpected
attributes or incorrect types, notify users that the schema stored in
the state does not match the current provider.

User can only encounter this error if the providers have updated their
schemas since the state was stored. This would appears when running
`terraform show -json` to display the current state, or
`terraform show -json planfile` if that plan was created with
`-refresh=false`. In either case, the state must be refreshed in order
to properly json encoded.
2021-02-23 10:19:24 -05:00