Commit Graph

22846 Commits

Author SHA1 Message Date
Martin Atkins aecb66d3db command: Fix TestMetaBackend_configuredChangeCopy_multiToNoDefaultWithoutDefault
As part of integrating the new "remote" backend we relaxed the requirement
that a "default" workspace must exist in all backends and now skip
migrating empty workspace states to avoid creating unnecessary "default"
workspaces when switching between backends that require it and backends
that don't, such as when switching from the local backend (which always
has a "default" workspace) to Terraform Enterprise.
2018-11-19 09:02:35 -08:00
Martin Atkins ec27526cc3 command: Fix TestMetaBackend_configuredChangeCopy_multiToMulti
This was failing because we now handle the settings for the local backend
a little differently as a result of decoding it with the HCL2 machinery.

Specifically, the backend.State* fields are now assumed to be what is
given in configuration, and any CLI overrides are maintained separately
in OverrideState* fields so that they can be imposed "just in time" in
StatePaths.

This is particularly important because OverrideStatePath (when set) is
used regardless of workspace name, while StatePath is a suitable value
only for the "default" workspace, with others needing to be constructed
from StateWorkspaceDir instead.
2018-11-19 09:02:35 -08:00
Martin Atkins 6c7cecfbd8 command: More logging during migration
This just finishes off the logging added in earlier commits to get all
the way through to the actual migration call.
2018-11-19 09:02:35 -08:00
Martin Atkins f39a5d0962 command: Fix various TestMetaBackend-prefix tests
Our new state model has a different implementation of "empty" that doesn't
consider lineage/serial, so we need to have some actual content in these
state fixtures to avoid them being skipped during state migrations.
2018-11-19 09:02:35 -08:00
Martin Atkins 22c84c71a4 command: Use statemgr.Import and statemgr.Export for state push and pull
We previously hacked around the import/export functionality being missing
in the statemgr layer after refactoring, but now it's been reintroduced
to fix functionality elsewhere we should use the centralized Import and
Export functions to ensure consistent behavior.

In particular, this pushes the logic for checking lineage and serial
during push down into the state manager itself, which is better because
all other details about lineage and serial are managed within the state
managers.
2018-11-19 09:02:35 -08:00
Martin Atkins 985b414dca states/statemgr: Fix the Filesystem state manager tests
Now that we're verifying the Terraform version during state loading, we
need to force a particular Terraform version to use during these tests.
2018-11-19 09:02:35 -08:00
Martin Atkins aacbe1d14b command: Fix TestMetaBackend_configureNewWithState
This test was initially failing because its fixture had a state which our
new state models consider to be "empty", and thus it was not migrated.

After fixing that (by adding an output to the fixture), this revealed a
bug that the lineage was not being persisted through the migration. This
is fixed by using the statemgr.Migrate method instead of writing via the
normal Writer interface, which allows two cooperating state managers to
properly transfer the lineage and serial along with the state snapshot.
2018-11-19 09:02:35 -08:00
Martin Atkins 24046ab833 command: More TRACE logging for the Backend instantiation codepaths 2018-11-19 09:02:35 -08:00
Martin Atkins 94510bc1b9 states/statemgr: Migrate, Import, and Export functions
In our recent refactoring of the state manager interfaces we made serial
and lineage management the responsibility of the state managers
themselves, not exposing them at all to most callers, and allowing for
simple state managers that don't implement them at all.

However, we do have some specific cases where we need to preserve these
properly when available, such as migration between backends, and the
"terraform state push" and "terraform state pull" commands.

These new functions and their associated optional interface allow the
logic here to be captured in one place and access via some simple
calls. Separating this from the main interface leaves things simple for
the normal uses of state managers.

Since these functions are mostly just thin wrappers around other
functionality, they are not yet well-tested directly, but will be
indirectly tested through the tests of their callers. A subsequent commit
will add more unit tests here.
2018-11-19 09:02:35 -08:00
Martin Atkins 2293391241 command: Fix TestMetaBackend_emptyWithExplicitState
This test was incorrectly updated in a previous iteration, with it
creating a modified state to write but then not actually writing it,
writing an empty test state instead.

This made the test fail because a backup state file is created only if
the new state snapshot is different to the old when written.
2018-11-19 09:02:35 -08:00
Radek Simko da5ae6e382
Merge pull request #19382 from hashicorp/b-tfdiags-enhancements
tfdiags: Detect more complex cfgs in ElaborateFromConfigBody
2018-11-17 14:27:24 +00:00
James Bardin e4270993be remove unused value 2018-11-16 15:28:30 -05:00
James Bardin db968733da re-count the flatmapped containers
When applying a legacy diff, recount the flatmapped containers. We can't
trust helper/schema to return the correct value, if it even exists.
2018-11-16 15:26:16 -05:00
James Bardin e95f2b586e another test case in helper/plugin 2018-11-16 15:12:16 -05:00
James Bardin eddf676c1f add provider test with a nested list in a set
in some cases helper/schema misses the list counts.
2018-11-16 15:11:16 -05:00
James Bardin 3716db3865
Merge pull request #19384 from hashicorp/jbardin/nested-sets
New Attribute and Diff handling in shims
2018-11-16 11:55:41 -05:00
James Bardin 89b2c6f21e comment fixes 2018-11-16 11:24:14 -05:00
James Bardin a681124301 verify DiffSuppresFunc behavior
Terraform used to provide empty diffs to the provider when calculating
`ignore_changes`, which would cause some DiffSuppressFunc to fail, as
can be seen in #18209.

Verify that this is no longer the case in 0.12
2018-11-16 11:17:23 -05:00
James Bardin 17ecda53b5 strip empty containers from flatmap attributes
In order to prevent mismatched states between read/plan/apply, we need
to ensure that the attributes are generated consistently each time.
Because of the various ways in which helper/schema and the hcl2 shims
interpret empty values, the only way to ensure consistency is to always
remove them altogether.
2018-11-16 09:59:03 -05:00
James Bardin 83317975fe add more tests with carious set combinations 2018-11-16 09:59:03 -05:00
James Bardin 21dfa56766 use ShimInstanceStateFromValue in DiffFromValues
This makes sure the diff is generated with the matching set ids from
helper/schema.

Update the tests to add ID fields to the state, which will exists in
practice, since any state traversing through the shims will have the ID
inserted.
2018-11-16 09:59:03 -05:00
James Bardin 71b55601ce new failing tests for nested sets 2018-11-16 09:59:03 -05:00
James Bardin 16f28f7348 new mechanism for applying a diff to a value
This attempts to apply the diff in order to get consistent output from
the shimmed values.
2018-11-16 09:59:03 -05:00
James Bardin 34766ca666 use the new InstanceState shim 2018-11-16 09:59:03 -05:00
James Bardin df04e2e7a6 move InstanceState shim into schema.Resource
This was the resource can rebuild the flatmapped state using the
schema and ResourceData, providing us the the correct set key values.
2018-11-16 09:59:03 -05:00
James Bardin b872491baa incremental progress towards applying diffs 2018-11-16 09:58:42 -05:00
Sander van Harmelen 812e7f66aa
Merge pull request #19375 from hashicorp/svh/b-atlas
Make the Atlas backend work after updating depencies
2018-11-15 20:47:34 +01:00
Sander van Harmelen 04439595ab Make the Atlas backend work after updating depencies
Newer versions of the retryablehttp package use a context, so we need to
add that in our custom `CheckRetry` function.

In addition I removed the `return true, nil` to continue retrying in
case of an error, and instead directly call the `DefaultRetryPolicy`.
This is because the `DefaultRetryPolicy` will now also take the context
into consideration.
2018-11-15 20:34:31 +01:00
Sander van Harmelen 7a268f1e48
Merge pull request #19374 from hashicorp/b-state-migration
Fix wildcard dependencies when upgrading states
2018-11-15 17:11:52 +01:00
Radek Simko aca52ce2b9
tfdiags: Document missing tests 2018-11-15 14:57:42 +00:00
Radek Simko ec127e4a7b
tfdiags: Detect more complex cfgs in ElaborateFromConfigBody 2018-11-15 14:57:42 +00:00
Radek Simko 9e0c6ab5e0
tfdiags: Add more test cases 2018-11-15 14:57:42 +00:00
Radek Simko 547006d943
tfdiags: Restructure tests into subtests 2018-11-15 14:57:42 +00:00
Sander van Harmelen 634430ebb2 Fix wildcard dependencies when upgrading states
Fixes #19347
2018-11-15 13:17:15 +01:00
James Bardin d2bd41c260 add a nested set test 2018-11-13 18:53:02 -05:00
James Bardin ce5d7ff6d0 spelling 2018-11-13 18:41:53 -05:00
James Bardin 6fee1f24ab don't add duplicate unknowns to a set
The flatmap shim was lazily adding duplicate items and letting cty.Set
clear them out, but if those duplicates contains unknown values they
can't be checked for equality and will end up remaining in the set.
2018-11-13 18:41:53 -05:00
James Bardin ebc9745788 fix "too many items" error message 2018-11-13 18:41:53 -05:00
James Bardin c4d0be8a52 failing test for schemas with a single set attr
Resources with certain combinations of attributes in a nested single set
fail to perperly coerce their shimmed values.
2018-11-13 18:41:53 -05:00
Paddy 2a6ad820bb
Merge pull request #19271 from danawillow/test-state
return state in tests even if cfg is invalid
2018-11-13 14:39:41 -08:00
Sander van Harmelen 785307f4fb
Merge pull request #19359 from hashicorp/f-update-deps
depencies: update `go-tfe`
2018-11-13 17:28:58 +01:00
Sander van Harmelen d0c320f148 depencies: update `go-tfe` 2018-11-13 16:24:45 +01:00
Dana Hoffman 7edbb3c8bf return state even if cfg is invalid 2018-11-12 21:49:30 -05:00
Martin Atkins 8c54da0ad2 command: TestInit_fromModule_explicitDest guard against other tests
Some other test is leaving behind a terraform.tfstate after it concludes,
which can cause this test to fail in a strange way due to picking up
extra provider requirements from that state.

This check doesn't fix that problem, but it at least makes the test fail
in a more helpful way to avoid time wasted trying to debug this test when
it's some other test that actually has the bug.
2018-11-12 15:19:55 -08:00
Martin Atkins ced06a4ca3 command: fix panic in TestStatePush_lineageMismatch
This test is currently failing due to the command completing successfully,
which would previously cause a panic because we didn't properly initialize
the MockUi and so its error buffer is nil unless written to.

(The failure this was masking will be fixed in a subsequent commit.)
2018-11-12 15:19:55 -08:00
Martin Atkins 544c2932ce command: Fix TestInit_checkRequiredVersion
In prior refactoring we lost the required core version check from
"terraform init", which we restore here.

Additionally, this test used to have an incorrect name that suggested it
was testing something in the "getProvider" codepath, but version checking
happens regardless of what other options are selected.
2018-11-12 15:19:55 -08:00
Martin Atkins 9ba399bca8 command: Fix TestInit_getProvider
After all of the refactoring we were no longer checking the Terraform
version field in a state file, causing this test to fail.

This restores that check, though with a slightly different error message.
2018-11-12 15:19:55 -08:00
Martin Atkins f6d468ffd5 command: Fix TestInit_inputFalse
This test was using old-style state files as its input, differing only by
lineage. Since lineages are now managed within the state manager itself,
the test can't use that to distinguish the two files and so we put a
different output in each one instead.

This also introduces some TRACE logging to the migration codepaths.
There's some hard-to-follow control flow here and so this extra logging
helps to understand the reason for a particular outcome, and since this
codepath is visited only in "terraform init" anyway it doesn't hurt to
be a bit more verbose here.
2018-11-12 15:19:55 -08:00
Martin Atkins c0b7f58143 command: Fix detection of necessary backend migration
In the refactoring for new HCL this codepath stopped taking into account
changes to the CLI -backend-config options when deciding if a backend
migration is required.

This restores that behavior in a different way than it used to be: rather
than re-hashing the merged config and comparing the hashes, we instead
just compare directly the configuration values, which must be exactly
equal in order to skip migration.

This change is covered by the test TestInit_inputFalse, although as of
this commit it is still not passing due a downstream problem within the
migration code itself.
2018-11-12 15:19:55 -08:00
Sander van Harmelen 3c850947a7
Merge pull request #19350 from hashicorp/b-select-workspace
backend/migrations: only select workspaces if supported
2018-11-12 17:15:42 +01:00