Commit Graph

28181 Commits

Author SHA1 Message Date
Kristin Laemmert a5cb780c87 terraform: refactor EvalValidateSelfref
The EvalValidateSelfref eval node implementation was removed in favor of a regular function.
2020-12-10 08:05:00 -05:00
Kristin Laemmert 468999b9b0 rename files for consistency with contents 2020-12-10 08:05:00 -05:00
Nick Fagerlund 48d35b9332 website: Fix a stray broken link to 0.8 -> 0.9 backend upgrade doc
I missed this earlier because my link checker was collapsing the two links from
this page to that page into a single report.

For posterity's sake, I'm linking directly to the markdown file in GitHub at an
appropriate tag version. I do not expect anyone to ever click this link again,
though.
2020-12-09 13:28:01 -08:00
Martin Atkins 3268a7eaba command/output: Raw output mode
So far the output command has had a default output format intended for
human consumption and a JSON output format intended for machine
consumption.

However, until Terraform v0.14 the default output format for primitive
types happened to be _almost_ a raw string representation of the value,
and so users started using that as a more convenient way to access
primitive-typed output values from shell scripts, avoiding the need to
also use a tool like "jq" to decode the JSON.

Recognizing that primitive-typed output values are common and that
processing them with shell scripts is common, this commit introduces a new
-raw mode which is explicitly intended for that use-case, guaranteeing
that the result will always be the direct result of a string conversion
of the output value, or an error if no such conversion is possible.

Our policy elsewhere in Terraform is that we always use JSON for
machine-readable output. We adopted that policy because our other
machine-readable output has typically been complex data structures rather
than single primitive values. A special mode seems justified for output
values because it is common for root module output values to be just
strings, and so it's pragmatic to offer access to the raw value directly
rather than requiring a round-trip through JSON.
2020-12-09 10:10:02 -08:00
Pam Selle 7acc483110
Merge pull request #27206 from hashicorp/pselle/vendor-provisioner-docs
Fix docs for 0.15 for vendor provisioners
2020-12-09 08:08:33 -05:00
Pam Selle aa044bdd39 Fix docs for 0.15 for vendor provisioners 2020-12-08 16:51:50 -05:00
Alisdair McDiarmid 30126baff4
Merge pull request #27199 from hashicorp/alisdair/remote-backend-version-latest
backend/remote: Fix for "latest" workspace version
2020-12-08 15:40:43 -05:00
Alisdair McDiarmid 94e2fe9a38
Merge pull request #27197 from hashicorp/alisdair/terraform-remote-state-version-fix
Fix terraform_remote_state backend version check
2020-12-08 15:40:28 -05:00
Alisdair McDiarmid 6e0d8cde91 backend/remote: Fix for "latest" workspace version
Terraform Cloud/Enterprise support a pseudo-version of "latest" for the
configured workspace Terraform version. If this is chosen, we abandon
the attempt to verify the versions are compatible, as the meaning of
"latest" cannot be predicted.

This affects both the StateMgr check (used for commands which execute
remotely) and the full version check (for local commands).
2020-12-08 15:34:23 -05:00
Alisdair McDiarmid 107dc0c34f Fix terraform_remote_state backend version check
The change recently introduced to ensure that remote backend users do
not accidentally upgrade their state file needs to be disabled for all
read-only uses, including the builtin terraform_remote_state data
source.
2020-12-08 14:18:04 -05:00
Kristin Laemmert 93c36e67b1
terraform: refactor ReadData (#27189)
I took some lessons learned during yesterday's marathon refactoring and
re-refactored the dataSource plan and apply to be functions on
NodeResourceAbstractInstance. Includes mild renaming to differentiate
between plan and planDataSource.
2020-12-08 10:43:04 -05:00
Pam Selle c2a143bb78
Merge pull request #27178 from hashicorp/deps/hcl2
Update hcl2 dependency
2020-12-08 09:18:18 -05:00
Hyunsuk Shin 16f8baa40e
Update setproduct.html.md (#27184)
fill wrong syntax
2020-12-08 10:05:37 -04:00
Kristin Laemmert e7aaf9e39f
Eval() Refactor: Plan Edition (#27177)
* terraforn: refactor EvalRefresh

EvalRefresh.Eval(ctx) is now Refresh(evalRefreshReqest, ctx). While none
of the inner logic of the function has changed, it now returns a
states.ResourceInstanceObject instead of updating a pointer. This is a
human-centric change, meant to make the logic flow (in the calling
functions) easier to follow.

* terraform: refactor EvalReadDataPlan and Apply

This is a very minor refactor that removes the (currently) redundant
types EvalReadDataPlan and EvalReadDataApply in favor of using
EvalReadData with a Plan and Apply functions.

This is in effect an aesthetic change; since there is no longer an
Eval() abstraction we can rename functions to make their functionality
as obvious as possible.

* terraform: refactor EvalCheckPlannedChange

EvalCheckPlannedChange was only used by NodeApplyableResourceInstance
and has been refactored into a method on that type called
checkPlannedChange.

* terraform: refactor EvalDiff.Eval

EvalDiff.Eval is now a method on NodeResourceAbstracted called Plan
which takes as a parameter an EvalPlanRequest. Instead of updating
pointers it returns a new plan and state.

I removed as many redundant fields from the original EvalDiff struct as
possible.

* terraform: refactor EvalReduceDiff

EvalReduceDiff is now reducePlan, a regular function (without a method)
that returns a value.

* terraform: refactor EvalDiffDestroy

EvalDiffDestroy.Eval is now NodeAbstractResourceInstance.PlanDestroy
which takes ctx, state and optional DeposedKey and returns a change.
I've removed the state return value since it was only ever returning a
nil state.

* terraform: refactor EvalWriteDiff

EvalWriteDiff.Eval is now NodeAbstractResourceInstance.WriteChange.

* rename files to something more logical

* terrafrom: refresh refactor, continued!

I had originally made Refresh a stand-alone function since it was
(obnoxiously) called from a graphNodeImportStateSub, but after some
(greatly appreciated) prompting in the PR I instead made it a method on
the NodeAbstractResourceInstance, in keeping with the other refactored
eval nodes, and then built a NodeAbstractResourceInstance inside import.

Since I did that I could also remove my duplicated 'writeState' code
inside graphNodeImportStateSub and use n.writeResourceInstanceState, so
double thanks!

* unexport eval methods

* re-refactor Plan, it made more sense on NodeAbstractResourceInstance. Sorry

* Remove uninformative `Eval`s from EvalReadData, consolidate to a single
file, and rename file to match function names.

* manual rebase
2020-12-08 08:50:30 -05:00
Martin Atkins 776b33db32 website: Recommend against making JSON/YAML with heredocs
This is a repeated cause of confusion and questions in the community
forum, because both JSON and YAML valid syntax are hard to generate using
just string concatenation. Terraform has built-in functions for both of
these common serializations to avoid those problems, and so this will
hopefully make these better alternatives more discoverable.
2020-12-07 15:39:37 -08:00
Martin Atkins ab1dd87540 website: Elaborate the "expressions" sub-pages in the language section
When we did the earlier documentation rework for Terraform v0.12 we still
had one big "Expressions" page talking about the various operators and
constructs, and so we had to be a bit economical with the details about
some more complicated constructs in order to avoid the page becoming even
more overwhelming.

However, we've recently reorganized the language documentation again so
that the expressions section is split across several separate pages, and
that gives some freedom to go into some more detail about and show longer
examples for certain features.

My changes here are not intended to be an exhaustive rewrite but I did
try to focus on some areas I've commonly seen questions about when helping
in the community forum and elsewhere, and also to create a little more
connectivity between the different content so readers can hopefully find
what they are looking for more easily when they're not yet sure what
terminology to look for.
2020-12-07 15:39:37 -08:00
James Bardin 627a2121b8
Merge pull request #27174 from hashicorp/jbardin/ignore-unknown
ignore_changes can ignore unknowns too
2020-12-07 17:40:21 -05:00
Pam Selle 52da8b6074 Update hcl2 dependency 2020-12-07 14:43:31 -05:00
Pam Selle 1db33b7ec7
Merge pull request #27169 from hashicorp/pselle/get-plugins
Update docs and add warning for -get-plugins
2020-12-07 14:22:04 -05:00
Pam Selle b963ea8594 Update docs and add warning for -get-plugins
As of Terraform 0.13+, the get-plugins command has been
superceded by new provider installation mechanisms, and
general philosophy (providers are always installed, but
the sources may be customized). Updat the init command
to give users a warning if they are setting this flag,
to encourage them to remove it from their workflow, and
update relevant docs and docstrings as well
2020-12-07 14:13:52 -05:00
James Bardin ee52f26647 ignore_changes can ignore unknowns too
The logic for handling unknown equality was incorrect, and would miss
changes where the configuration is still not known during plan.
2020-12-07 14:01:44 -05:00
Kristin Laemmert bedc08f5eb
terraform: refactor EvalWriteStateDeposed (#27149)
* terraform: refactor EvalWriteStateDeposed

EvalWriteStateDeposed is now
NodeDestroyDeposedResourceInstanceObject.writeResourceInstanceState.
Since that's the only caller I considered putting the logic directly
inline, but things are clunky enough right now that I think this is good
enough for this refactor.
2020-12-07 08:39:20 -05:00
Ben Drucker 2549e53aed add backend refresh test with provider config 2020-12-06 10:02:26 -08:00
Ben Drucker 7e11b97923 Merge remote-tracking branch 'origin/master' into validate-ignore-empty-provider 2020-12-06 09:47:24 -08:00
Ben Drucker a2c31088f4 call configBody.Content 2020-12-06 09:38:43 -08:00
Ben Drucker 186eff96b8 expand early return comment 2020-12-06 09:36:53 -08:00
Ben Drucker eacf8b5c55 rename empty provider config test 2020-12-06 09:35:35 -08:00
Pam Selle ae025248cc
Merge pull request #27131 from hashicorp/pselle/double-marks
Avoid double-marking variables
2020-12-04 13:21:54 -05:00
Pam Selle 12b5d437da Avoid double-marking variables
It is possible, say with multiple layers of
sensitive variables, to "double-mark" a variable.
Add a check to ensure this does not happen.
2020-12-04 13:10:02 -05:00
James Bardin 3b4079d451
Merge pull request #27141 from hashicorp/jbardin/ignore_changes
Fixes for ignore_changes with unintended provider behavior
2020-12-04 12:55:26 -05:00
Kristin Laemmert 29d89c4a15
Eval(): refactor EvalWriteState() (#27145)
* fix inaccurate log

* terraform: refactor EvalWriteState

EvalWriteState is refactored into a method on
NodeAbstractResourceInstance and renamed writeResourceInstanceState.

Import, my nemesis, gave me pause. I did not expect to find
EvalWriteState in an transform node, and so I decided to copy the
function inline rather than rethink my entire refactor for one function
that's likely to be (heavily) refactored in the future.
2020-12-04 12:44:40 -05:00
Pam Selle 0c0ea09546
Merge pull request #27134 from tillepille/patch-1
documentation: fix small typo
2020-12-04 11:15:14 -05:00
James Bardin b831039cf8 update CHANGELOG.md 2020-12-04 10:14:49 -05:00
Kristin Laemmert 7370a98ab7
Eval() Refactor (#27087)
* terraform: refactor EvalPreApply and EvalPostApply

EvalPreApply and EvalPostApply have been refactored as methods on
NodeAbstractResourceInstance.

* terraform: remove EvalReadState and EvalReadStateDeposed

These two functions had already been re-implemented as functions on
NodeAbstractResource, so this commit finished the process of removing
the Evals and refactoring the tests.

* terraform: remove EvalRefreshLifecycle

EvalRefreshLifecycle was only used in one node,
NodePlannableResourceInstance, so the functionality has been moved
directly inline.

* terraform: remove EvalDeposeState

EvalDeposeState was only used in one function, so it has been removed
and the logic placed in-line in
NodeApplyableResourceInstance.managedResourceExecute.

* terraform: remove EvalMaybeRestoreDeposedObject

EvalMaybeRestoreDeposedObject was only used in one place, so I've
removed it in favor of in-line code.
2020-12-04 09:16:26 -05:00
James Bardin 4f4e8c17e0 validate the configuration before ignore_changes
The ignore_changes option `all` can cause computed attributes to show up
in the validation configuration, which will be rejected by the provider
SDK. Validate the config before applying the ignore_changes options.

In the future it we should probably have a way for processIgnoreChanges
to skip computed values based on the schema. Since we also want a way to
more easily query the schema for "computed-ness" to validate the
ignore_changes arguments for computed values, we can fix these at the
same time with a future change to configschema. This will most likely
require some sort of method to retrieve info from the configschema.Block
via cty.Path, which we cannot easily do right now.
2020-12-03 17:59:03 -05:00
James Bardin 02e7efab9e re-apply ignore_changes after plan for legacy
Because we allow legacy providers to depart from the contract and return
changes to non-computed values, the plan response may have altered
values that were already suppressed with ignore_changes. A prime example
of this is where providers attempt to obfuscate config data by turning
the config value into a hash and storing the hash value in the state.
There are enough cases of this in existing providers that we must
accommodate the behavior for now, so for ignore_changes to work at all
on these values, we will revert the ignored values once more on the
planned state.
2020-12-03 17:44:35 -05:00
Alisdair McDiarmid 6bacc7a73c
Merge pull request #27128 from hashicorp/alisdair/sensitivity-change-permadiff
terraform: Write state if sensitivity changes
2020-12-03 16:48:09 -05:00
Dmitry Tokarev 8d1c416a53
website: Fix link to external documentation "Git URLs" 2020-12-03 13:24:56 -08:00
James Bardin aa5c8add2e fix bug in ignore_changes Transform
The cty.Transform for ignore_changes could return early when building a
map that had multiple ignored keys.

Refactor the function to try and separate the fast-path a little better,
and hopefully make it easier to follow.
2020-12-03 16:09:12 -05:00
Alisdair McDiarmid 50f4d79867 terraform: Write state if sensitivity changes
When applying, we return early if only sensitivity changed between the
before and after values of the changeset. This avoids unnecessarily
invoking the provider.

Previously, we did not write the new value for a resource to the state
when this happened. The result was a permanent diff for resource updates
which only change sensitivity, as the apply step is skipped and the
state is unchanged.

This commit adds a state write to this shortcut return path, and fixes a
test for this exact case which was accidentally relying on a value diff
caused by an incorrect manual state value.
2020-12-03 15:58:54 -05:00
Petros Kolyvas 2ce71ab43c
Upgrade guide link fix (#27124) 2020-12-03 15:21:58 -04:00
Masayuki Morita 93b6f15c9d
website: Fix typo in docs/commands/cli-config (#27038) 2020-12-03 14:30:24 -04:00
Petros Kolyvas 20a5db1c86
Website: 0.14 Upgrade guide additions (#27112)
* Update 0-14.html.markdown

Spelling again. Thanks @pselle
2020-12-03 14:21:31 -04:00
Nick Fagerlund 0c0749edcf
website: Fix several broken links (#27091) 2020-12-03 13:54:38 -04:00
Martin Atkins 323cd4364b website: Correct formatting for lists in dependency lock docs
I originally drafted these docs in a context where I was relying on
GitHub's Markdown renderer, and carelessly imported them into the
Terraform website without verifying that the website's Markdown renderer
could process it. This particular quirk has bitten us before: the website
Markdown parser expects follow-on paragraphs in a list item to be indented
at least four spaces, and with less than that it ignores the leading
whitespace altogether and just understands a normal paragraph.

This change will cause the follow-on paragraphs to now correctly render
as part of the bullet points they are intended to be attached to.
2020-12-03 09:16:58 -08:00
Mark Lewis 9935138e1c
Update for_each.html.md
minor grammar improvement.
2020-12-03 16:45:52 +00:00
Mark Lewis ffea7a4cda
Update for_each.html.md 2020-12-03 16:45:04 +00:00
Tim Schrumpf e102465e91
fix small typo 2020-12-03 16:05:19 +01:00
Connor Osborn 2c2ed53ff3
Fix apt install typo (#27074)
Apt install expects a `name=version` NOT `name==version`
2020-12-03 10:23:14 -04:00
Petros Kolyvas 5cb2d4894c
Anytrue alltrue docs clarification. (#27108)
* Anytrue alltrue docs clarification.

* Update alltrue.html.md

I can't spell.

* Update anytrue.html.md

Yes, I can't spell.
2020-12-03 10:13:20 -04:00