Is it possible when importing into a module to use a provider from the module? My goal is to avoid putting things related only to the module in the root config (and also to avoid redundancy).
I have a case where the provider datadog
is used, and therefore declared, only in a certain module. I have tried the following with terraform v1.6.1, but it fails:
/main.tf:
import {
to = module.logging.datadog_logs_index.main
id = "main"
provider = module.logging.datadog
}
Output:
$ terraform init
Initializing the backend...
Initializing modules...
╷
│ Error: Invalid import provider argument
│
│ on main.tf line 75, in import:
│ 75: provider = module.logging.datadog
│
│ The provider argument can only be specified in import blocks that will generate
│ configuration.
│
│ Use the providers argument within the module block to configure providers for all resources
│ within a module, including imported resources.
╵
╷
│ Error: Invalid provider configuration reference
│
│ on main.tf line 75, in import:
│ 75: provider = module.logging.datadog
│
│ The provider argument requires a provider type name, optionally followed by a period and
│ then a configuration alias.
╵
I have got it to work by declaring the datadog
provider at the root-level, but this seems redundant (but perhaps necessary).
Allow import blocks within child modules · Issue #33474 · hashicorp/terraform · GitHub may help with my situation in the long run, in any case.