terraform/helper/resource
Martin Atkins 86c02d5c35 command: "terraform init" can partially initialize for 0.12upgrade
There are a few constructs from 0.11 and prior that cause 0.12 parsing to
fail altogether, which previously created a chicken/egg problem because
we need to install the providers in order to run "terraform 0.12upgrade"
and thus fix the problem.

This changes "terraform init" to use the new "early configuration" loader
for module and provider installation. This is built on the more permissive
parser in the terraform-config-inspect package, and so it allows us to
read out the top-level blocks from the configuration while accepting
legacy HCL syntax.

In the long run this will let us do version compatibility detection before
attempting a "real" config load, giving us better error messages for any
future syntax additions, but in the short term the key thing is that it
allows us to install the dependencies even if the configuration isn't
fully valid.

Because backend init still requires full configuration, this introduces a
new mode of terraform init where it detects heuristically if it seems like
we need to do a configuration upgrade and does a partial init if so,
before finally directing the user to run "terraform 0.12upgrade" before
running any other commands.

The heuristic here is based on two assumptions:
- If the "early" loader finds no errors but the normal loader does, the
  configuration is likely to be valid for Terraform 0.11 but not 0.12.
- If there's already a version constraint in the configuration that
  excludes Terraform versions prior to v0.12 then the configuration is
  probably _already_ upgraded and so it's just a normal syntax error,
  even if the early loader didn't detect it.

Once the upgrade process is removed in 0.13.0 (users will be required to
go stepwise 0.11 -> 0.12 -> 0.13 to upgrade after that), some of this can
be simplified to remove that special mode, but the idea of doing the
dependency version checks against the liberal parser will remain valuable
to increase our chances of reporting version-based incompatibilities
rather than syntax errors as we add new features in future.
2019-01-14 11:33:21 -08:00
..
error.go helper/resource: Add retries to err message 2017-01-20 11:09:04 -08:00
grpc_test_provider.go plugin: Establish our current plugin protocol as version 5 2018-11-19 09:56:41 -08:00
id.go Export a const for validation methods 2018-03-10 12:40:37 -05:00
id_test.go Make failure message more explicit 2018-03-10 21:53:54 -05:00
map.go ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
map_test.go helper/resource: Fix duplicated function testConfig 2018-10-16 19:14:11 -07:00
resource.go ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
state.go helper/resource: fix ungrammatical doc comment in StateChangeConf 2017-11-08 09:43:36 -08:00
state_shim.go type names don't imply the resource mode 2019-01-12 11:43:48 -05:00
state_shim_test.go use actual schema.Resources for state shims 2019-01-10 12:20:03 -05:00
state_test.go add test for proper cancelation 2017-04-19 18:07:00 -04:00
testing.go command: "terraform init" can partially initialize for 0.12upgrade 2019-01-14 11:33:21 -08:00
testing_config.go use actual schema.Resources for state shims 2019-01-10 12:20:03 -05:00
testing_import_state.go use actual schema.Resources for state shims 2019-01-10 12:20:03 -05:00
testing_import_state_test.go skip resource tests for now 2018-10-31 14:17:23 -04:00
testing_test.go allow TestCheckNoResourceAttr for empty containers 2019-01-09 13:09:02 -05:00
wait.go Fixing small typo in resource/wait.go 2018-03-14 17:33:03 +01:00
wait_test.go fix tests affected by refreshGracePeriod 2017-04-19 18:07:00 -04:00