I’m attempting to use the new ‘import’ block to import a manually created Route53 zone in AWS into my Terraform state.
I have a number of environments in which I’m running my TF deploy and this import block is only relevant for the ‘production’ environment. I therefore need to make this import block conditional.
I’ve attempted to do so using the ‘count’ and a local var to read my ‘environment’ variable:
However, when I run a plan using this configuration I get the following error:
╷
│ Error: Unsupported argument
│
│ on hosted_zone.tf line 6, in import:
│ 6: count = local.prod-env ? 1 : 0
│
│ An argument named "count" is not expected here.
It’s not possible to make import blocks conditional - that means that if you’re accustomed to using the same code in multiple environments, differentiating only with variables and backend config, import blocks aren’t compatible with this workflow.
The only solution is to find a way external to Terraform, to only include the relevant .tf files when processing certain environments.