Commit Graph

23458 Commits

Author SHA1 Message Date
Martin Atkins
15cd6d8300 core: Retain prior state if update fails with no new state
In an ideal world, providers are supposed to respond to errors during
apply by returning a partial new state alongside the error diagnostics.
In practice though, our SDK leaves the new value set to nil for certain
errors, which was causing Terraform to "forget" the object altogether by
assuming that the provider intended to say "null".

We now adjust that assumption to apply only in the delete case. In all
other cases (including updates) we retain the prior state if the new
state is given as nil. Although we could potentially fix this in the SDK
itself, I expect this is a likely bug in other future SDKs for other
languages too, so this new assumption is a safer one to make to be
resilient to data loss when providers don't behave perfectly.

Providers that return both nil new value and no errors are considered
buggy, but unfortunately that applies to the mocks in many of our tests,
so for pragmatic reasons we can't generate an error for that case as we do
for other "should never happen" situations. Instead, we'll just retain the
prior value in the state so the user can retry.
2019-01-18 16:54:52 -08:00
Sander van Harmelen
db36ccb316
Merge pull request #20054 from hashicorp/svh/b-typo
backend/remote: fix a small typo
2019-01-18 19:56:32 +01:00
Sander van Harmelen
8937fedb76 backend/remote: fix a small typo 2019-01-18 19:40:57 +01:00
Martin Atkins
8b094f48f7 command: Update "terraform get" to use the new module installer
We missed this on the initial update pass because this was calling
directly into the module package API rather than going through the Meta
methods that we updated for the new config loader.

m.installModules here is the same method that "terraform init" is using
for this purpose, ensuring the two will behave the same way. This changes
the output a little compared to the old installer, but it still includes
the important information about where each module is coming from.
2019-01-17 16:52:34 -08:00
James Bardin
565eeac5d1
Merge pull request #20041 from hashicorp/jbardin/shims
Some fixes for the provider shims
2019-01-17 19:34:54 -05:00
James Bardin
c045d3e6a3 disable known failing tests
We need these changes in master for testing, worry about these test
after.
2019-01-17 19:19:13 -05:00
James Bardin
286cb0a39d clean out diff a little more before checking
Check if there wasn't any real diff attributes first, before returning
the original state in PlanResourceChange.
2019-01-17 19:19:13 -05:00
James Bardin
4f691c5988 don't replace null strings with empty strings
This adds unexpected values in some cases, and since the case this
handles is only within set objects, we'll deal woth this when tackling
the sets themselves.
2019-01-17 19:19:13 -05:00
James Bardin
2cc651124e don't overwrite values in plan
Plan can change known values too, which we can't match in sets. We'll
find another way to normalize these eithout losing plan values.
2019-01-17 18:51:18 -05:00
James Bardin
4439a7dcf4 add tests for nested default values
Don't lose default values set within a nested block.
2019-01-17 18:51:18 -05:00
Martin Atkins
176a5abfd3 command: Restore single-file support in "terraform fmt"
This possibility was lost in the rewrite to use HCL2, but it's used by
a number of external utilities and text editor integrations, so we'll
restore it here.

Using the stdin/stdout mode is generally preferable for text editor use
since it allows formatting of the in-memory buffer rather than directly
the file on disk, but for editors that don't have support for that sort of
tooling it can be convenient to just launch a single command and directly
modify the on-disk file.
2019-01-17 14:21:18 -08:00
Martin Atkins
b0a43cab84 command: "terraform fmt" must fail if file has invalid syntax
Since the HCL formatter only works with tokens, it can in principle be
called with any input and produce some output. However, when given invalid
syntax it will tend to produce nonsensical results that may drastically
change the input file and be hard for the user to undo.

Since there's no strong reason to try to format an invalid or incomplete
file, we'll instead try parsing first and fail if parsing does not
complete successfully.

Since we talk directly to the HCL API here this is only a _syntax_ check,
and so it can be applied to files that are invalid in other ways as far
as Terraform is concerned, such as using unsupported top-level block types,
resource types that don't exist, etc.
2019-01-17 14:21:18 -08:00
Martin Atkins
a10f9a18cf vendor: go get github.com/zclconf/go-cty@master
There are no code changes in this update. This just catches up with the
latest master commit in the upstream repo, which has only seen
documentation updates since the prior commit.
2019-01-17 14:21:18 -08:00
Martin Atkins
787c176063 vendor: go get github.com/hashicorp/hcl2@master
This includes a missing feature for the splat syntax (null.* returns an
empty tuple) and also fixes a bug in the source code formatter where it
was inserting spaces between two consecutive interpolation sequences, like
"${foo}${bar}".
2019-01-17 14:21:18 -08:00
Kim Ngo
b88ef2b47c
Update CHANGELOG.md 2019-01-17 12:09:13 -06:00
Martin Atkins
6ab15a80a4
Update CHANGELOG.md 2019-01-17 10:03:30 -08:00
Martin Atkins
2f8f7d6f4d lang/funcs: Type conversion functions
It's not normally necessary to make explicit type conversions in Terraform
because the language implicitly converts as necessary, but explicit
conversions are useful in a few specialized cases:

- When defining output values for a reusable module, it may be desirable
  to force a "cleaner" output type than would naturally arise from a
  computation, such as forcing a string containing digits into a number.
- Our 0.12upgrade mechanism will use some of these to replace use of the
  undocumented, hidden type conversion functions in HIL, and force
  particular type interpretations in some tricky cases.
- We've found that type conversion functions can be useful as _temporary_
  workarounds for bugs in Terraform and in providers where implicit type
  conversion isn't working correctly or a type constraint isn't specified
  precisely enough for the automatic conversion behavior.

These all follow the same convention of being named "to" followed by a
short type name. Since we've had a long-standing convention of running all
the words together in lowercase in function names, we stick to that here
even though some of these names are quite strange, because these should
be rarely-used functions anyway.
2019-01-17 10:01:47 -08:00
Kim Ngo
ba6e243bd9
Merge pull request #20030 from findkim/bump-plugin-install-version
Bump provider installer protocol version to 5
2019-01-17 11:37:48 -06:00
Radek Simko
5d4946e27a
Merge pull request #20004 from hashicorp/issue-template-labels
Add labels to issue templates
2019-01-17 15:22:49 +00:00
Radek Simko
b661a983b8
Add labels to issues templates 2019-01-17 15:04:16 +00:00
findkim
073d367018 tools/terraform-bundle: match plugin installer protocol with terraform's installer 2019-01-16 16:15:52 -06:00
findkim
7816e61614 Bump installer protocol version to 5 and separate client and server protocol references 2019-01-16 15:07:57 -06:00
Radek Simko
2ad9f0513a
Update CHANGELOG.md 2019-01-16 19:31:28 +00:00
Radek Simko
aaf4319953
Merge pull request #20005 from hashicorp/b-statemgr-avoid-html-escaping
states/statemgr: Avoid HTML escaping when printing LockInfo
2019-01-16 19:30:50 +00:00
Martin Atkins
4e14ab7557 config: Remove "setproduct" function, which is now in lang/funcs 2019-01-16 09:57:16 -08:00
Martin Atkins
da51e72cbb lang/functions: set functions from cty
The sethaselement, setintersection, and setunion functions are defined in
the cty stdlib. Making them available in Terraform will make it easier to
work with sets, and complement the currently-Terraform-specific setproduct
function.

In the long run setproduct should probably move into the cty stdlib too,
but since it was submitted as a Terraform function originally we'll leave
it here now for simplicity's sake and reorganize later.
2019-01-16 09:57:16 -08:00
Martin Atkins
edb5f82de1 lang/funcs: Convert the "setproduct" function to the new approach
In our new world it produces either a set of a tuple type or a list of a
tuple type, depending on the given argument types.

The resulting collection's element tuple type is decided by the element
types of the given collections, allowing type information to propagate
even if unknown values are present.
2019-01-16 09:57:16 -08:00
Martin Atkins
9d11d427a8 config: Rename "product" function to "setproduct"
This hopefully makes it clearer that it works with sets rather than real
numbers, avoiding confusion with "sum", "min", "max", etc.
2019-01-16 09:57:16 -08:00
Fábio Matavelli
acd17d9075 Create product interpolation function
This creates the product interpolation function that returns the cartesian product of a list of lists.
2019-01-16 09:57:16 -08:00
Kim Ngo
2bca828e46
Merge pull request #20015 from findkim/rm-dup-discovery-logging
Remove duplicate discovery logging
2019-01-15 16:12:54 -06:00
findkim
abeb86072b Remove duplicate logging 2019-01-15 15:39:28 -06:00
James Bardin
30eead2df5
Merge pull request #20012 from hashicorp/jbardin/nested-set-shims
Fix shims with deeper nested containers
2019-01-15 15:40:16 -05:00
appilon
c5e4ac9b7c
Merge pull request #20013 from appilon/go1.11.4
Require go1.11.4
2019-01-15 15:00:36 -05:00
Alex Pilon
9929bd05a3
update vagrantfile for go1.11.4 2019-01-15 14:31:51 -05:00
Alex Pilon
de769533e1
require go1.11.4 2019-01-15 14:26:21 -05:00
James Bardin
7d05dee08d refactor ApplyResourceChange
Remove a bunch of indentation by returning early, and make sure we don't
fail on non-fatal error without saving the applied value.
2019-01-15 12:35:58 -05:00
James Bardin
0a731167db add a round trip through the shims during apply
Cycle through the shim operations after Apply, to ensure that we can
converge on a stable value for for Plan. While the shims produce valid
values in both directions, helper/schema sometimes does not agree on
which containers should be empty or null.
2019-01-15 11:59:15 -05:00
James Bardin
0d1252812b add more tests for a computed nested list and set 2019-01-15 11:55:02 -05:00
Radek Simko
a29daf0176
Update CHANGELOG.md 2019-01-15 16:26:01 +00:00
Radek Simko
cb39836705
Merge pull request #19995 from hashicorp/f-cmd-fmt-reduce-diff
command/format: Reduce whitespaces in empty fields
2019-01-15 16:25:19 +00:00
Sander van Harmelen
9ba5b1b507
Merge pull request #20010 from hashicorp/svh/f-remote-backend
backend/remote: use the correct test operation
2019-01-15 16:37:09 +01:00
Sander van Harmelen
e08a7e979e backend/remote: use the correct test operation 2019-01-15 16:13:16 +01:00
Sander van Harmelen
4d9da13d85 go-mod: update dependencies 2019-01-15 15:52:37 +01:00
Radek Simko
13896d72c5
command/format: Render empty object as {} 2019-01-15 14:34:49 +00:00
Radek Simko
5f14b7a7f2
command/format: Render empty primitive list/set as [] 2019-01-15 14:34:49 +00:00
Radek Simko
09d19ca9d9
command/format: Render empty JSON object as {} 2019-01-15 14:34:48 +00:00
Radek Simko
0dd2d56f18
command/format: Render empty maps as {} 2019-01-15 14:34:46 +00:00
Radek Simko
ea05da89cb
states/statemgr: Avoid HTML escaping when printing LockInfo 2019-01-15 10:57:31 +00:00
Martin Atkins
0995559934 go mod tidy 2019-01-14 17:39:16 -08:00
Kim Ngo
41a2376915
Merge pull request #19981 from findkim/colorize-protocol-mismatch-msg
Condense protocol mismatch UI error message
2019-01-14 15:12:09 -06:00