gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.09k stars 981 forks source link

Support for Terraform `import` blocks #3477

Closed olivermeyer closed 1 month ago

olivermeyer commented 1 month ago

Describe the enhancement

Terraform supports import blocks as a way of importing existing resources into the state without running commands manually. For example, the following block will import the EC2 instance with id i-abcd1234 to aws_instance.example in the state:

import {
  to = aws_instance.example
  id = "i-abcd1234"
}

For further details, see the Terraform docs.

It would be great if Terragrunt supported these blocks, since running import commands manually is inherently risky.

Note that this is different from the Terragrunt import blocks described here.

Additional context

Alternatives: run the import commands manually

yhakbar commented 1 month ago

Hey @olivermeyer ,

It supports it today! Terragrunt will respect any .tf files placed next to a terragrunt.hcl file, so if you want to use the same syntax to import resources, you can just place the HCL import block you referenced above in an imports.tf file right next to your terragrunt.hcl.

olivermeyer commented 1 month ago

Hey @olivermeyer ,

It supports it today! Terragrunt will respect any .tf files placed next to a terragrunt.hcl file, so if you want to use the same syntax to import resources, you can just place the HCL import block you referenced above in an imports.tf file right next to your terragrunt.hcl.

Hi @yhakbar, thanks for the quick reply and apologies from my side - for some reason I couldn't get it to work and since I couldn't find it mentioned in the documentation, I assumed it wasn't supported. I'll take another shot at it :-)

yhakbar commented 1 month ago

No problem!

If you can think of a way to improve the documentation so that it's clearer for the next person, please submit a pull request. There isn't anything special in how Terragrunt handles imports. This feature is just a side-effect of the design of Terragrunt automatically ensuring that .tf files next to a terragrunt.hcl file are used for terragrunt commands.