7

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.

xaocon
  • 185
  • 1
  • 1
  • 9

2 Answers2

5

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
Cloudkollektiv
  • 11,852
  • 3
  • 44
  • 71
1

So it seems that you can use the same import cli option in terragrunt as you do terraform. There's not much to it.

xaocon
  • 185
  • 1
  • 1
  • 9
  • 2
    Along the same lines, depending on the existing/target module structure, you may be able to `terraform state pull > mystate.tf` (in the existing TF project) and `terragrunt state push mystate.tf` (in Terragrunt) – Max Ivanov Jan 29 '21 at 22:30