terragrunt

Import Existing Resources in Terragrunt


I'm looking for a way to manage existing resources in my Terragrunt workflow without recreating them. Basic Terraform has the ability to import the remote state here but I don't see a way to do it in Terragrunt. I know it would be possible to use a data source but I'm pretty sure this will mean that it checks the remote state each run instead of bringing it in to be managed.

In the end I'd like to be able to import an existing network host project and it's networks and subnetworks, then use that to create service projects.


Solution

  • According to the documentation, Terragrunt is a thin wrapper around Terraform, so every cli-option/flag that is available in Terraform should also be available in Terragrunt.

    Importing a single resource:

    terragrunt import module.iam.aws_iam_user.user bill
    

    Importing a for_each generated resource:

    terragrunt import module.iam.aws_iam_user.user[\"bill\"] bill
    terragrunt import module.iam.aws_iam_user.user[\"jane\"] jane
    

    Alternatively use single quotes:

    terragrunt import 'module.iam.aws_iam_user.user["bill"]' bill
    terragrunt import 'module.iam.aws_iam_user.user["jane"]' jane