Terraform import for dynamodb tables

I have many DynamoDB tables on different environments that I want to manage through Terraform. For example:

  • sales_dev
  • sales_stage
  • sales_prod

Now I need to find a way to import those tables into Terraform but I’d like to do this in an automated way since we have a lot of tables for several environments. I tried to use the import block but looks like we cannot mix variables with it so that didn’t work…

import {
      to = aws_dynamodb_table.sales_table
      id = "sales_${environment}"

resource "aws_dynamodb_table" "sales_table" {

I’m also aware of the import command but that would be extremely difficult since it would require us to run the import command manually for every table/environment.

Any suggestions?