Commit Graph

52 Commits

Author SHA1 Message Date
Kristin Laemmert
8108face36
terraform: return initialization required error when provider schemas not found (#24715)
A side effect of the various changes to the provider installer included losing the initialization required error message which would occur if a user removed or modified the .terraform directory.

Previously, plugin factories were created after the configuration was loaded, in terraform.NewContext. Terraform would compare the required providers (from config and state) to the available providers and return the aforementioned error if a provider was missing.

Provider factories are now loaded at the beginning of any terraform command, before terraform even loads the configuration, and therefore before terraform has a list of required providers.

This commit replaces the current error when a providers' schema cannot be found in the provider factories with the init error, and adds a command test (to plan tests, for no real reason other than that's what I thought of first).
2020-04-21 16:29:27 -04:00
Martin Atkins
549aede792 Remove terraform.ResourceProvider, use providercache.Installer instead
Back when we first introduced provider versioning in Terraform 0.10, we
did the provider version resolution in terraform.NewContext because we
weren't sure yet how exactly our versioning model was going to play out
(whether different versions could be selected per provider configuration,
for example) and because we were building around the limitations of our
existing filesystem-based plugin discovery model.

However, the new installer codepath is new able to do all of the
selections up front during installation, so we don't need such a heavy
inversion of control abstraction to get this done: the command package can
select the exact provider versions and pass their factories directly
to terraform.NewContext as a simple static map.

The result of this commit is that CLI commands other than "init" are now
able to consume the local cache directory and selections produced by the
installation process in "terraform init", passing all of the selected
providers down to the terraform.NewContext function for use in
implementing the main operations.

This commit is just enough to get the providers passing into the
terraform.Context. There's still plenty more to do here, including to
repair all of the tests this change has additionally broken.
2020-04-06 09:24:23 -07:00
Kristin Laemmert
2a646aba46 comment cleanup: those FIXME comments are load-bearing and must be up to date 2020-02-14 15:41:31 -08:00
Kristin Laemmert
9891d0354a
providers: use addrs.Provider as map keys for provider.Factory (#23548)
* terraform/context: use new addrs.Provider as map key in provider factories
* added NewLegacyProviderType and LegacyString funcs to make it explicit that these are temporary placeholders

This PR introduces a new concept, provider fully-qualified name (FQN), encapsulated by the `addrs.Provider` struct.
2019-12-04 11:30:20 -05:00
James Bardin
44afe5b6ff remove unused ResourceProviderError 2019-02-20 14:23:56 -05:00
James Bardin
6cc3e1d0bd move init error to where it is generated
The init error was output deep in the backend by detecting a
special ResourceProviderError and formatted directly to the CLI.

Create some Diagnostics closer to where the problem is detected, and
passed that back through the normal diagnostic flow. While the output
isn't as nice yet, this restores the helpful error message and makes the
code easier to maintain. Better formatting can be handled later.
2019-02-20 14:18:37 -05:00
James Bardin
16df9c37cf first step in core provider type replacement
Chaange ResourceProvider to providers.Interface starting from the
context, and fix all type errors.

This only replaced some of method calls directly applicable to the
providers themselves. The resource methods will follow.
2018-10-16 19:11:09 -07:00
Martin Atkins
f14369e7fb core: Remove machinery for the "input" walk
Provider input is now longer handled with a graph walk, so the code
related to the input graph and walk are no longer needed.

For now the Input method is retained on the ResourceProvider interface,
but it will never be called. Subsequent work to revamp the provider API
will remove this method.
2018-10-16 18:49:20 -07:00
Martin Atkins
183833affc core: terraform.ResourceProvider.GetSchema method
In order to parse provider, resource and data source configuration from
HCL2 config files, we need to know the relevant configuration schema.
This new method allows Terraform Core to request these from a provider.

This is a breaking change to this interface, so all of its implementers
in this package are updated too. This includes concrete implementations
of the new method in helper/schema that use the schema conversion code
added in an earlier commit to produce a configschema.Block automatically.

Plugins compiled against prior versions of helper/schema will not have
support for this method, and so calls to them will fail. Callers of
this new method will therefore need to sniff for support using the
SchemaAvailable field added to both ResourceType and DataSource.

This careful handling will need to persist until next time we increment
the plugin protocol version, at which point we can make the breaking
change of requiring this information to be available.
2017-10-17 07:23:41 -07:00
James Bardin
5be15ed77c have the local backend provide a plugin init msg
During plan and apply, because the provider constraints need to be built
from a plan, they are not checked until the terraform.Context is
created. Since the context is always requested by the backend during the
Operation, the backend needs to be responsible for generating contextual
error messages for the user.

Instead of formatting the ResolveProviders errors during NewContext,
return a special error type, ResourceProviderError to signal that
init will be required. The backend can then extract and format the
errors.
2017-06-22 13:15:30 -04:00
Martin Atkins
7ca592ac06 core: use ResourceProviderResolver to resolve providers
Previously the set of providers was fixed early on in the command package
processing. In order to be version-aware we need to defer this work until
later, so this interface exists so we can hold on to the possibly-many
versions of plugins we have available and then later, once we've finished
determining the provider dependencies, select the appropriate version of
each provider to produce the final set of providers to use.

This commit establishes the use of this new mechanism, and thus populates
the provider factory map with only the providers that result from the
dependency resolution process.

This disables support for internal provider plugins, though the
mechanisms for building and launching these are still here vestigially,
to be cleaned up in a subsequent commit.

This also adds a new awkward quirk to the "terraform import" workflow
where one can't import a resource from a provider that isn't already
mentioned (implicitly or explicitly) in config. We will do some UX work
in subsequent commits to make this behavior better.

This breaks many tests due to the change in interface, but to keep this
particular diff reasonably easy to read the test fixes are split into
a separate commit.
2017-06-09 14:03:59 -07:00
Martin Atkins
ba3ee00837 core: ResourceProviderResolver interface
ResourceProviderResolver is an extra level of indirection before we
get to a map[string]ResourceProviderFactory, which accepts a map of
version constraints and uses it to choose from potentially-many available
versions of each provider to produce a single ResourceProviderFactory
for each one requested.

As of this commit the ResourceProviderResolver interface is not used. In
a future commit the ContextOpts.Providers map will be replaced with a
resolver instance, with the creation of the factory delayed until the
version constraints have been resolved.
2017-06-09 14:03:59 -07:00
Mitchell Hashimoto
4582c2c016
terraform: Stop API added to ResourceProvider 2016-10-25 12:09:44 -07:00
Mitchell Hashimoto
60140b28f4
Revert "Merge pull request #9536 from hashicorp/f-provider-stop"
This reverts commit c3a4cff133, reversing
changes made to 791a02e6e4.

This change requires plugin recompilation and we should hold off until a
minor release for that.
2016-10-25 12:00:36 -07:00
Mitchell Hashimoto
2be72cfe03
terraform: Stop API added to ResourceProvider 2016-10-25 11:31:55 -07:00
Mitchell Hashimoto
e2c415a87e
terraform: resource provider must never return pointers to same data
This is a requirement for the parallelism of Terraform to work sanely.
We could deep copy every result but I think this would be unrealistic
and impose a performance cost when it isn't necessary in most cases.
2016-10-17 20:55:20 -07:00
Martin Atkins
0e0e3d73af core: New ResourceProvider methods for data resources
This is a breaking change to the ResourceProvider interface that adds the
new operations relating to data sources.

DataSources, ValidateDataSource, ReadDataDiff and ReadDataApply are the
data source equivalents of Resources, Validate, Diff and Apply (respectively)
for managed resources.

The diff/apply model seems at first glance a rather strange workflow for
read-only resources, but implementing data resources in this way allows them
to fit cleanly into the standard plan/apply lifecycle in cases where the
configuration contains computed arguments and thus the read must be deferred
until apply time.

Along with breaking the interface, we also fix up the plugin client/server
and helper/schema implementations of it, which are all of the callers
used when provider plugins use helper/schema. This would be a breaking
change for any provider plugin that directly implements the provider
interface, but no known plugins do this and it is not recommended.

At the helper/schema layer the implementer sees ReadDataApply as a "Read",
as opposed to "Create" or "Update" as in the managed resource Apply
implementation. The planning mechanics are handled entirely within
helper/schema, so that complexity is hidden from the provider implementation
itself.
2016-05-14 08:26:36 -07:00
Mitchell Hashimoto
d1a81379d0
terraform: use InstanceInfo more appropriately, pass ID to ImportState 2016-05-11 13:02:35 -07:00
Mitchell Hashimoto
531f609564
terraform: add ImportState to the provider interface 2016-05-11 13:02:30 -07:00
Mitchell Hashimoto
9142ec400e
terraform: flowerbox the ResourceProvider interface because it is huge 2016-05-11 13:02:30 -07:00
Mitchell Hashimoto
84531a3fd5
helper/schema: sets Importable to true for resources that have importer 2016-05-11 13:02:30 -07:00
Sander van Harmelen
0b1dbf31a3 core: close provider/provisioner connections
Currently Terraform is leaking goroutines and with that memory. I know
strictly speaking this maybe isn’t a real concern for Terraform as it’s
mostly used as a short running command line executable.

But there are a few of us out there that are using Terraform in some
long running processes and then this starts to become a problem.

Next to that it’s of course good programming practise to clean up
resources when they're not needed anymore. So even for the standard
command line use case, this seems an improvement in resource management.

Personally I see no downsides as the primary connection to the plugin
is kept alive (the plugin is not killed) and only unused connections
that will never be used again are closed to free up any related
goroutines and memory.
2015-06-19 21:52:50 +02:00
Mitchell Hashimoto
5611b9b8a8 terraform: add Input API to ResourceProvider 2014-09-28 23:50:37 -07:00
Mitchell Hashimoto
1835a03842 terraform: hook parameter is an InstanceInfo 2014-09-25 10:40:44 -07:00
Mitchell Hashimoto
9b2b3a963f ResourceDiff => InstanceDiff 2014-09-17 16:33:24 -07:00
Mitchell Hashimoto
95f3e626a5 terraform: modify the ResourceProvider API super hardcore 2014-09-16 16:20:11 -07:00
Mitchell Hashimoto
3a79a1ca1a terraform: add ResourceProviderFactoryFixed 2014-07-10 09:46:21 -07:00
Mitchell Hashimoto
b0a83adea4 terraform: manually interpolate variables in walker functions
This avoids issues where we were interpolating when we didn't need to
2014-07-07 16:56:23 -07:00
Mitchell Hashimoto
d0577fda02 terraform: add ValidateResource API to ResourceProvider 2014-07-02 20:35:03 -07:00
Mitchell Hashimoto
2fd129ddc4 terraform: support both raw and clean config 2014-06-20 12:07:18 -07:00
Mitchell Hashimoto
dc193f5f33 terraform: call refresh before every diff
In the future, we'll make this a separate thing...
2014-06-19 21:22:07 -07:00
Mitchell Hashimoto
b3e20a3e85 terraform: basic apply, more tests needed 2014-06-18 15:35:03 -07:00
Mitchell Hashimoto
6bef265514 terraform: IsSet can be called on nil 2014-06-12 23:23:15 -07:00
Mitchell Hashimoto
c10eed752f terraform: tests for ResourceConfig.Get 2014-06-12 23:16:28 -07:00
Mitchell Hashimoto
9751878513 terraform: helpers on ResourceConfig 2014-06-12 23:08:47 -07:00
Mitchell Hashimoto
8a2eb95a42 terraform: Validate called on provider 2014-06-12 22:30:09 -07:00
Mitchell Hashimoto
a256f27b24 terraform: pass through the unknown keys 2014-06-12 18:11:21 -07:00
Mitchell Hashimoto
7e421dd89b terraform: ResourceConfig 2014-06-12 17:59:59 -07:00
Mitchell Hashimoto
fd39728cbb terraform: start using the RawConfig interpolations 2014-06-12 17:51:38 -07:00
Mitchell Hashimoto
02a3603a9a rpc: Diff implementation 2014-06-06 00:48:32 -07:00
Mitchell Hashimoto
0561edc2fd terraform: check for errors initializing a provider 2014-06-06 00:28:57 -07:00
Mitchell Hashimoto
796dfd54e9 terraform: just hardcode a UUID in there for computed placeholders 2014-06-05 20:03:16 -07:00
Mitchell Hashimoto
9018beda81 terraform: placeholder key for computed values 2014-06-05 11:30:48 -07:00
Mitchell Hashimoto
d77a72ba84 terraform: take into account dependency variables in diffs 2014-06-05 07:27:01 -07:00
Mitchell Hashimoto
7c6920bba1 terraform: diff/state work better together, merge 2014-06-05 06:57:06 -07:00
Mitchell Hashimoto
e904fca3da terraform: Diff! 2014-06-05 02:32:10 -07:00
Mitchell Hashimoto
9480783ee4 terraform: add Diff to ResourceProvider
rpc and plugin don't compile yet
2014-06-03 16:42:21 -07:00
Mitchell Hashimoto
c9d8413431 terraform: New happy path works decently well 2014-06-03 15:08:00 -07:00
Mitchell Hashimoto
0c1a341d90 terraform: Resources method for providers 2014-06-03 14:26:31 -07:00
Mitchell Hashimoto
f8dc3286d9 rpc: ResourceProvider over RPC 2014-05-28 15:07:47 -07:00