Terraform Import Error With Remote Backend

I am trying to import resources into the Terraform Enterprise remote backend by running CLI commands from my local machine. Terraform version specified is 0.13.5 on the local system and the target Terraform Enterprise workspace. I’m making use of azurerm provider version 2.60.0

The configuration looks like the following:


terraform {
  backend "remote"  {
    hostname = "my_host_name"
    organization = "my_organization_name"
    workspaces {
        prefix = "my_workspace_prefix_"
provider "azurerm" {
  version = ">=1.20.0"
  subscription_id = var.my_subscription_id
  tenant_id = var.my_tenant_id
  client_id = var.my_client_id
  client_secret = var.my_client_secret
  features {}
module "my_module" {
  source = "link to private registry"
  version = "version_value"

  subscription_id = var.my_subscription_id
  tenant_id = var.my_tenant_id
  client_id = var.my_client_id
  client_secret = var.my_client_secret

# variable declarations and definitions 


my_subscription_id = "value"
my_tenant_id = "value"
my_client_id = "value"
my_client_secret = "value"

When I try to import a resource for my_module by running the command terraform import <module_path> <resource_address>, I run into the following error:

Error: Invalid provider configuration

    on main.tf line 8:
    8: provider "azurerm" {

The configuration for provider["registry.terraform.io/hashicorp/azurerm"] depends
on values that cannot be determined until apply.

Another thing to note is that the provider input variables are also defined as Terraform Enterprise workspace variables.

I’m not sure why I would get this error when the values to the input variables are defined in an .auto.tfvars file.

To try to resolve this, I have also tried passing in the provider variables explicitly via the command line arguments in the -var 'foo=bar' format, but I still get the same error.

I also tried switching to the local backend with the exact same configuration, the import is successful when I do so. So the issue seems to be relevant just for the remote backend.

When I specified the literal values to the provider arguments (instead of input variables), the import was successful for the remote backend.

I need to use the input variables for provider arguments because these are sensitive in nature and can only be specified at runtime and cannot be specified as literal values. Does anyone has any feedback on how to resolve this issue?

Thank you!

Hello! This is sadly a known limitation of the remote backend. import is supported, but only as a local operation (your workspace execution mode must be set to local, and the variables accessible on your local machine) afterwhich you can push the modified state back up to the remote workspace. More information here: Import - Terraform by HashiCorp

Thanks @chrisarcand!

I understand this and I’m actually running this on my local system (with remote backend configured for state file) and providing the provider variables via command line (-var arguments) but I’m still running into the error mentioned above.

Oh interesting! Something else might be up; I notice you’re a Terraform Enterprise customer - I suggest you open a support ticket if you haven’t already, and we should be able to get you sorted with some more details regarding your setup.

@sohi429 did you manage to solve this? I’m facing the same issue at the moment just with a different provider.

Yes, I was able to get it working it on my local machine. The trick is to not to refer to the provider variables via input variables but pass the actual values directly for the arguments such as client-secret, client-id, etc. in the provider block.