Terraform v0.10.7
terraform import
locals {
vpc_cidr_blocks = {
"us-east-1:Network" = "10.10.0.0/16",
"us-east-1:Production" = "10.20.0.0/16",
"us-east-1:Stage" = "10.30.0.0/16",
"us-east-1:Test" = "10.40.0.0/16",
"us-east-2:Network" = "10.50.0.0/16"
},
"vpc_cidr_block" = "${local.vpc_cidr_blocks[terraform.env]}",
"region" = "${module.env.region}",
"environment" = "${module.env.name}",
"short_name" = "${module.env.short_name}"
}
provider "aws" {
region = "${local.region}"
}
wonko@deepthought:~/Documents/projects/terraform/Network$ terraform import aws_vpc.Production vpc-12345678
Error importing: Provider "aws" depends on non-var "local.region". Providers for import can currently
only depend on variables or must be hardcoded. You can stop import
from loading configurations by specifying `-config=""`.
Terraform should have imported the resource into the state.
An error was thrown.
Please list the steps required to reproduce the issue, for example:
terraform import aws_vpc.Production vpc-12345678
A simple workaround is to add
provider "aws" {
region = "us-east-1"
}
to main.tf
Hi @bhechinger
Thanks for opening this issue. This is the expected behavior: providers are evaluated very early in the graph resolution, whereas locals are evaluated later on.
Thus being said, you can't rely on locals for providers so there's nothing much we could help on here unfortunately 🤷♂️
I'll wait for your feedback / answer here and will close depending on it if you don't mind.
Thanks!
That completely breaks the way I am trying to do region selection. Guess I'll have to find a different way. :)
Thanks!
Just got bit by this as well.
This statement just seems incorrect:
you can't rely on locals for providers
It works fine for terraform plan
and terraform apply
. It's only terraform import
that is failing. Seems like this should be fixable?
I just hit exactly the same thing - apply
is fine, import
throws this error.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
I just hit exactly the same thing -
apply
is fine,import
throws this error.