Commit Graph

22 Commits

Author SHA1 Message Date
Paddy
e6592dc710
Add support for provider metadata to modules. (#22583)
Implement a new provider_meta block in the terraform block of modules, allowing provider-keyed metadata to be communicated from HCL to provider binaries.

Bundled in this change for minimal protocol version bumping is the addition of markdown support for attribute descriptions and the ability to indicate when an attribute is deprecated, so this information can be shown in the schema dump.

Co-authored-by: Paul Tyng <paul@paultyng.net>
2020-03-05 16:53:24 -08:00
Alex Pilon
4bf43efcfd
move hcl2shim package to configs 2019-08-06 19:58:58 -04:00
Alex Pilon
7f8f198719
remove UnknownVariabeValue from config and update references to shim 2019-07-17 22:41:24 -04:00
James Bardin
059dcf1e25 implement UpgradeResourceState in the mock provider
The default is a Noop that simply encodes the provided state
2019-05-14 18:00:01 -04:00
Martin Atkins
12572e97bc core: Automatically upgrade resource instance states on read
If an instance object in state has an earlier schema version number then
it is likely that the schema we're holding won't be able to decode the
raw data that is stored. Instead, we must ask the provider to upgrade it
for us first, which might also include translating it from flatmap form
if it was last updated with a Terraform version earlier than v0.12.

This ends up being a "seam" between our use of int64 for schema versions
in the providers package and uint64 everywhere else. We intend to
standardize on int64 everywhere eventually, but for now this remains
consistent with existing usage in each layer to keep the type conversion
noise contained here and avoid mass-updates to other Terraform components
at this time.

This also includes a minor change to the test helpers for the
backend/local package, which were inexplicably setting a SchemaVersion of
1 on the basic test state but setting the mock schema version to zero,
creating an invalid situation where the state would need to be downgraded.
2018-11-30 11:22:39 -08:00
James Bardin
0b7be2d0e3 fixes for the remaining tests
It's possible that a computed collection could be handled by the
attribute name, rather than the index count value.

Use a new testDiffFn for some tests, which don't work with the old
function that can't determine `computed` without the schema.
2018-11-19 18:56:50 -05:00
James Bardin
155f899249 update terraform with PrepareProviderConfig
Change the call sites and update the MockProvider. No core behavior is
changed yet.
2018-10-18 08:48:55 -04:00
James Bardin
7e0fc55b80 return proper PlanResourceChange in mock 2018-10-16 19:14:11 -07:00
Martin Atkins
4ee15ec604 core: MockProvider.GetSchema shouldn't panic if unconfigured
Some mock objects will not have any mock behavior configured for the
GetSchema method, so we should just return a valid-but-empty schema in
that case, rather than panicking as we did before.
2018-10-16 19:14:11 -07:00
Martin Atkins
032f908f4a core: MockProvider and MockProvisioner can't lock in Stop
The only reasonable usage of these methods is for them to run concurrently
with other methods, so we mustn't hold a lock to do this work. For tests
that deal with stopping, it's the test's own responsibility to deal with
any concurrency issues that arise from their StopFns running concurrently
with other mock functions.
2018-10-16 19:14:11 -07:00
Martin Atkins
faddb83a92 core: If create leg of create_before_destroy fails, restore deposed
I misunderstood the logic here on the first pass of porting to the new
provider and state types: EvalUndeposeState is supposed to return the
deposed object back to being current again, so we can undo the deposing
in the case where the create leg fails.

If we don't do this, we end up leaving the instance with no current object
at all and with its prior object deposed, and then the later destroy
node deletes that deposed object, leaving the user with no object at all.

For safety we skip this restoration if there _is_ a new current object,
since a failed create can still produce a partial result which we need
to keep to avoid losing track of any remote objects that were successfully
created.
2018-10-16 19:14:11 -07:00
James Bardin
4824eba07d convert import tests 2018-10-16 19:14:11 -07:00
Martin Atkins
26aef7dc22 core: MockProvider legacy ApplyFn handling correct behavior of nil
In the old protocol, returning a nil InstanceState was a way to indicate
that the object had been deleted. In the new world we signal that with
an actual object that contains a null value, which Terraform Core itself
will then recognize and turn into a nil state, eventually removing the
entry from state altogether.
2018-10-16 19:14:11 -07:00
Martin Atkins
b83a563cf0 core: MockProvider.PlanResourceChange must lock before mutating 2018-10-16 19:14:11 -07:00
Martin Atkins
54be8c02d4 core: Implement ValidateFn shim for MockProvider 2018-10-16 19:14:11 -07:00
Martin Atkins
d1da65b6be core: Allow ProviderMock to fetch its own schema without deadlock 2018-10-16 19:14:11 -07:00
Martin Atkins
a7680ad175 core: Shim to old p.ApplyFn interface in MockProvider
This is a pretty basic attempt to turn a pair of values into an old-school
diff. It probably won't work correctly for all tests, but hopefully works
well enough that we can just update the remaining tests in-place to use
the new API directly.
2018-10-16 19:14:11 -07:00
Martin Atkins
84102170b3 core: MockProvider shim handling of DiffFn
This should allow many of our existing tests using DiffFn to continue
working with little or no further modification.
2018-10-16 19:14:11 -07:00
Martin Atkins
52c28183b5 core: MockProvider not to panic if import mock function returns no attrs 2018-10-16 19:14:11 -07:00
Martin Atkins
ebd3aba0be core: Fix various compile-time errors in tests
Significant changes to the provider interface left a lot of the
tests in a non-buildable state. This set of changes gets the
tests building again but does not attempt to make them run to
completion or pass.

After this commit, it is possible to build a test program for
the ./terraform package but it will panic during its run. That
will be addressed in subsequent commits.
2018-10-16 19:14:11 -07:00
Martin Atkins
44bc7519a6 terraform: More wiring in of new provider types
This doesn't actually work yet, but it builds and then panics in a pretty
satisfying way.
2018-10-16 19:12:54 -07:00
James Bardin
bddfd0412c add new provider and provisioner mocks
MockProvider and MockProvisioner implement the new plugin interfaces,
and are built following the patterns used by the legacy
MockResourceProvider and MockResourceProvisioner
2018-10-16 19:11:09 -07:00