Commit Graph

23939 Commits

Author SHA1 Message Date
Martin Atkins
2a64a00983 core: Upgrade flatmap to JSON when dynamic attributes are present
When a resource type schema includes dynamically-typed attributes we can't
do any automatic conversion from flatmap to JSON because we don't know
how to interpret the keys that start with the dynamically-typed
attribute's prefix.

To work around that, we'll instead just ask the SDK to do a no-op upgrade
(current and target versions are the same) which will convert from flatmap
to JSON using the SDK's own logic as a side-effect.

This situation should rarely arise in real-world use, but it ends up being
very important for the helper/resource provider test harness because it
is forced to lower the state back to flatmap repeatedly after every step
in order to run legacy checking and processing code.
2019-03-21 15:19:59 -07:00
Martin Atkins
135121562e helper/plugin: Implement Schema.SkipCoreTypeCheck
The previous commit added this flag but did not implement it. Here we
implement it by adjusting the shape of schema we return to Terraform Core
to mark the attribute as untyped and then ensure that gets handled
correctly on the SDK side.
2019-03-21 15:19:59 -07:00
Martin Atkins
7f860dc83e helper/schema: Schema.SkipCoreTypeCheck flag
When running in v0.12-and-higher mode, this will cause the SDK to report
the type of the attribute as "any", effectively skipping type checking
on the Core side altogether and checking only in the SDK and provider
code.

The practical impact of this is to restore the v0.11-style checking
behavior of allowing object values to be missing certain attributes as
long as they are marked as optional in the schema. The SDK can do this
because it uses a unified schema model for both object values and nested
blocks, while Terraform Core only supports the idea of "optional" when
talking about attributes in nested blocks.

This is a continuation of the pile of workarounds that also includes
the ConfigMode and AsSingle fields, allowing providers to selectively opt
out of new v0.12 behaviors in situations where they conflict with
decisions made in the design of the providers in our old world where
Terraform Core delegated _all_ validation to providers.

This is designed as an opt-in so that we can limit its impact only to
specific cases where it's needed and minimize the risk of regressions
elsewhere. Providers should use this sparingly only in situations where
prevailing usage disagrees with the new expectations of Terraform Core in
v0.12.

This commit only adds the flag, and does not implement any behavior for it
yet. That means this commit can exist in both the v0.11 and v0.12
codebases, allowing for API compatibility. A subsequent commit for v0.12
(not included in v0.11) will then implement this behavior.
2019-03-21 15:19:59 -07:00
Justin Downing
1e32ae243c grammatical updates to comments and docs (#20195) 2019-03-21 14:05:41 -07:00
Sander van Zoest
42305e62ea website: Fix a typo in null_resource provisioner page description (#19928) 2019-03-21 13:31:00 -07:00
Kim Ngo
479964ad66
Merge pull request #20781 from findkim/registry-checksum
plugin/discovery: verify registry checksum
2019-03-21 15:02:28 -05:00
Justin Clark
7af7fb3f71 website: access_token is not required in atlas backend (#20222) 2019-03-21 12:50:05 -07:00
findkim
161fe47b34 plugin/discovery: improve providery discovery verification errors 2019-03-21 14:38:51 -05:00
findkim
2726282307 plugin/discovery: add context for provider discovery verification 2019-03-21 14:38:20 -05:00
Daniel Schroeder
b29102dbc6 website: Add TF_IN_AUTOMATION to environment variables page (#19721)
* Adds TF_IN_AUTOMATION description

Blatantly copied from https://learn.hashicorp.com/terraform/development/running-terraform-in-automation since it is missing on the [env var page](https://www.terraform.io/docs/configuration/environment-variables.html).

* Update website/docs/commands/environment-variables.html.md

Co-Authored-By: udondan <udondan@users.noreply.github.com>
2019-03-21 12:08:56 -07:00
findkim
1a32617d5e plugin/discovery: verify checksum matches Registry response 2019-03-21 12:31:31 -05:00
Brian Flad
2e6c316fc9
Merge pull request #20760 from hashicorp/mar19_s3_path_style
website: document s3 backend's force_path_style argument
2019-03-21 09:24:49 -04:00
Alvaro Miranda Aguilera
ac0bdb7f21 website: fix heredoc syntax in chef.html.markdown (#19739)
remove - from EOF
2019-03-20 16:52:01 -07:00
Martin Atkins
373f94fe89 vendor: go get github.com/zclconf/go-cty/cty@master
This includes a fix to prevent unintentional infinite recursion when
trying to unify multiple object types to a single type for conversion to
list(any).

Sadly I wasn't able to reproduce the problem as reported (in #20728), so
therefore I wasn't able to write a Terraform test for it, but I have
confirmed that the cty behavior here was incorrect anyway (recursively
calling the same function we're already in with the same arguments is
clearly not productive) and so this change will allow whatever situation
that was to terminate with a type conversion error, rather than causing a
stack overflow.

It's likely that there is another bug lurking under this, since the
problematic code here was supposed to be unreachable, but avoiding the
crash is the priority for now. If the problem re-surfaces then it should
at least be an error message with some additional context about what the
goal of the caller was.

This also includes an unrelated fix for the gocty package, which doesn't
affect Terraform because it makes very little use of that package.
2019-03-20 16:34:05 -07:00
Nikolai Vavilov
01e26e337e website: add missing article (#19368) 2019-03-20 16:20:32 -07:00
Nathan Dataguake Basanese
32daeec29d website: clean up terraform destroy output example (#20099) 2019-03-20 16:15:30 -07:00
Martin Atkins
2632ccc5d3
Update CHANGELOG.md 2019-03-19 17:36:39 -07:00
Martin Atkins
096b1bb87b lang/funcs: Port the "reverse" function from the old functions set
This has the same functionality as the "reverse" function that was
implemented in the "config" package, but adapted to the new language type
system.
2019-03-19 17:32:19 -07:00
Sargun Dhillon
ebb551b86f config: new "reverse" interpolation function
It reverses a list.
2019-03-19 17:32:19 -07:00
Martin Atkins
2f2897f01a
Update CHANGELOG.md 2019-03-19 17:30:55 -07:00
Stefan Schmidt
3ca1253796 backend/gcs: Mark the unused attributes project and region as removed.
These two attributes are not used since aec45e6967.
2019-03-19 17:29:04 -07:00
Martin Atkins
2b1e650df2 lang/funcs: Fix out-of-bounds ArgError in templatefile function
The templatefile function only has two arguments, so ArgErrorf can be
called with only zero or one as the argument index. If we are out of
bounds then HCL itself will panic trying to build the error message for
this call when called as an HCL function.

Unfortunately there isn't really a great layer in Terraform to test for
this class of bug systematically, because we are currently testing these
functions directly rather than going through HCL to do it. For the moment
we'll just live with that, but if we see this class of error arise again
we might consider either reworking the tests in this package to work with
HCL expression source code instead of direct calls or adding some
additional tests elsewhere that do so.
2019-03-19 16:23:51 -07:00
Martin Atkins
a4df1ba6d1
Update CHANGELOG.md 2019-03-19 15:54:39 -07:00
Martin Atkins
e918fa83ec command/format: Don't panic when item removed from list of objects
Due to these tests happening in the wrong order, removing an object from
the end of a sequence of objects would previously cause a bounds-check
panic.

Rather than a more severe rework of the logic here, for now we'll just
introduce an extra precondition to prevent the panic. The code that
follows already handles the case where there _is_ no new object (i.e. the
"old" object is being deleted) as long as we're able to pass through this
type-checking logic.

The new "JSON list of objects - removing item" test covers this problem
by rendering a diff for an object being removed from the end of a list
of objects within a JSON value.
2019-03-19 15:46:40 -07:00
Martin Atkins
35df450dc0 helper/resource: Preserve provider address when shimming to old state
It's important to preserve the provider address because during the destroy
phase of provider tests we'll use the references in the state to determine
which providers are required, and so without this attempts to override
the provider using the "provider" meta-argument can cause failures at
destroy time when the wrong provider gets selected.

(This is particularly acute in the google-beta provider tests because that
provider is _always_ used with provider = "google-beta" to override the
default behavior of using the normal "google" provider.)
2019-03-19 15:08:46 -07:00
Sander van Harmelen
a710447eaf website: clarify behavior and version support for remote backend (#20739)
* docs: elaborate on supported remote backend versions

This PR adds a few lines to the docs to indicate which commands are
supported by what version of the remote backend and it makes a
recommendation about which version to use.

* Clarify remote state storage w/ TFE [skip ci]

Specifically, that this is the backend to use with remote state (all
tiers) and Free-Tier vs. Enterprise tiers differ in remote operations

* website: Arrange remote backend info differently
2019-03-19 12:41:42 -07:00
Nick Fagerlund
88fcb67cc7 website: document s3 backend's force_path_style argument
Added in
fb6b349e58
2019-03-19 11:48:44 -07:00
Tomas Chmelevskij
036a1e259e website: Typo fix (#20629) 2019-03-19 11:26:25 -07:00
PenelopeFudd
cf0ed422b2 website: Added missing doublequotes. (#20696) 2019-03-19 11:23:24 -07:00
Paul Tyng
eb582744df
Merge pull request #20738 from hashicorp/paultyng-patch-1
Fix documented limitations on Elem for TypeMap
2019-03-19 14:13:08 -04:00
Martin Atkins
50a101afbd lang: Consider "dynamic" blocks when resolving references
The hcldec package has no awareness of the dynamic block extension, so the
hcldec.Variables function misses any variables declared inside dynamic
blocks.

dynblock.VariablesHCLDec is a drop-in replacement for hcldec.Variables
that _is_ aware of dynamic blocks, returning all of the same variables
that hcldec would find naturally plus also any variables used inside
the dynamic block "for_each" and "labels" arguments and inside the
nested "content" block.
2019-03-19 10:04:45 -07:00
Martin Atkins
838a42d218 vendor: go get github.com/hashicorp/hcl2@master
This includes improved functionality for HCL's "dynamic block extension",
which will allow us (in a subsequent commit) to properly detect
dependencies inside nested "dynamic" blocks, where currently they get
missed.

For this commit though, we just upgrade HCL to a version that includes it
and make a small change to our "lang" package to align with an upstream
renaming.
2019-03-19 10:04:45 -07:00
HashedDan
a2c91ca582 Docs: reference resource by index, fixes #18184 2019-03-19 09:42:05 -07:00
Martin Atkins
04f3766fd9 website: Indicate v0.12-only content
We have released the v0.12-oriented content to the website early in order
to support the beta process, but in some places we neglected to explicitly
mark features or content as being v0.12-only.

Here we add explicit markers to the main cases we've seen where readers
have reported confusion, along with some other tweaks in similar vein.
2019-03-18 12:42:21 -07:00
Paul Tyng
ea7e922007
oxford comma 2019-03-18 14:16:20 -04:00
Paul Tyng
ec9450a262
Fix limitations on Elem for TypeMap 2019-03-18 14:15:25 -04:00
Justin Campbell
3119cb039b
Update CHANGELOG.md 2019-03-18 13:13:47 -04:00
Justin Campbell
e696e063dc
Merge pull request #20674 from hashicorp/registry-warnings
plugin/discovery: Parse warnings from TF Registry
2019-03-18 13:12:26 -04:00
Martin Atkins
3d6a8e0492
Update CHANGELOG.md 2019-03-18 09:30:00 -07:00
Justin Campbell
e6316c9de6 plugin/discovery: Parse warnings from TF Registry
Terraform Registry (and other registry implementations) can now return
an array of warnings with the versions response. These warnings are now
displayed to the user during a `terraform init`.
2019-03-18 12:21:27 -04:00
Justin Campbell
24e13d8ec1 plugin/discovery: Return tfdiags from Get
Allows us to surface warnings to the user using the tfdiags interfaces.
2019-03-18 12:21:27 -04:00
Martin Atkins
c39905e1a8 command: Fix various issues in the "terraform state ..." subcommands
In earlier refactoring we updated these commands to support the new
address and state types, but attempted to partially retain the old-style
"StateFilter" abstraction that originally lived in the Terraform package,
even though that was no longer being used for any other functionality.

Unfortunately the adaptation of the existing filtering to the new types
wasn't exact and so these commands ended up having a few bugs that were
not covered by the existing tests.

Since the old StateFilter behavior was the source of various misbehavior
anyway, here it's removed altogether and replaced with some simpler
functions in the state_meta.go file that are tailored to the use-cases of
these sub-commands.

As well as just generally behaving more consistently with the other
parts of Terraform that use the new resource address types, this commit
fixes the following bugs:

- A resource address of aws_instance.foo would previously match an
  resource of that type and name in any module, which disagreed with the
  expected interpretation elsewhere of meaning a single resource in the
  root module.

- The "terraform state mv" command was not supporting moves from a single
  resource address to an indexed address and vice-versa, because the old
  logic didn't need to make that distinction while they are two separate
  address types in the new logic. Now we allow resources that do not have
  count/for_each to be treated as if they are instances for the purposes
  of this command, which is a better match for likely user intent and for
  the old behavior.

Finally, we also clean up a little some of the usage output from these
commands, which hasn't been updated for some time and so had both some
stale information and some inaccurate terminology.
2019-03-18 09:19:55 -07:00
Martin Atkins
04cbf249aa core: Don't fail on dynamic attribute values during refresh
Our post-refresh safety check had the constraint and real type inverted,
so previously any refresh of a resource type with a dynamically-typed
attribute would fail this type check.

Also includes a small tweak to the error message from this check since the
old one was a little awkward to read in practice when the error is a
cty.PathError rendered with an attribute path prefix.
2019-03-18 09:18:06 -07:00
Martin Atkins
87fe6cbecd plans/objchange: Don't panic when prior state contains nested map blocks
We were using the wrong cty operation to access map members, causing a
panic whenever a prior value was present for a resource type with a nested
block backed by a map value.
2019-03-18 09:16:50 -07:00
Martin Atkins
f799a133e3
Update CHANGELOG.md 2019-03-15 16:13:47 -07:00
PenelopeFudd
d27651b305 website: Typo in link to the templatefile function page 2019-03-15 14:12:26 -07:00
Martin Atkins
ea1d5f8fcb vendor: go get github.com/hashicorp/hcl2@master
This includes two upstream fixes:

- Handle explicit JSON "null" consistently during decode of JSON syntax.
- Properly detect the end of a "heredoc" when formatting to avoid messing
  up indentation of other lines following the heredoc.
2019-03-15 13:55:30 -07:00
James Bardin
b5b67a4592
Merge pull request #20535 from hashicorp/jbardin/go-version
bump go version to 1.12
2019-03-15 16:53:26 -04:00
Kristin Laemmert
c73a5fc07d
command/show: add provider name to resource changes (#20711) 2019-03-15 13:20:43 -07:00
PenelopeFudd
247faca59d website: formatdate function in the navigation sidebar 2019-03-15 09:51:47 -07:00