command/import: default provider config in same module

Previously we were defaulting the provider configuration selection to a
provider in the root module inferred from the resource type name.

This is close, but not quite right: we need to _start_ with a provider
configuration in the same module as we're importing into, and then our
provider resolution steps during import graph construction will use that
as a starting point for a walk up the tree to find the nearest matching
configuration (which might eventually still be in the root, but not
necessarily).
This commit is contained in:
Martin Atkins 2018-05-08 11:19:02 -07:00
parent e4e972db67
commit fc7871c5ee
1 changed files with 4 additions and 1 deletions

View File

@ -174,7 +174,10 @@ func (c *ImportCommand) Run(args []string) int {
providerAddr = relAddr.Absolute(addrs.RootModuleInstance) providerAddr = relAddr.Absolute(addrs.RootModuleInstance)
} else { } else {
// Use a default address inferred from the resource type. // Use a default address inferred from the resource type.
providerAddr = resourceRelAddr.DefaultProviderConfig().Absolute(addrs.RootModuleInstance) // We assume the same module as the resource address here, which
// may get resolved to an inherited provider when we construct the
// import graph inside ctx.Import, called below.
providerAddr = resourceRelAddr.DefaultProviderConfig().Absolute(addr.Module)
} }
// Check for user-supplied plugin path // Check for user-supplied plugin path