# README
tf-import-gen (Terraform import generator)
Tool to generate terraform import statements to simplify state migrations from one terraform code base to another.
Installation
Using Homebrew (Mac and linux)
brew install kishaningithub/tap/tf-import-gen
Using docker
alias tf-import-gen="docker run -i ghcr.io/kishaningithub/tf-import-gen:latest"
terraform show -json | tf-import-gen
Using pkgx
terraform show -json | pkgx tf-import-gen@latest
or if you prefer the env style which only adds tf-import-gen to your current shell session
env +tf-import-gen@latest
terraform show -json | tf-import-gen
Others
Head over to the releases page and download a binary for your platform
Examples
Generating import statements by module
$ terraform show -json | tf-import-gen module.example
import {
to = module.example.aws_glue_catalog_database.example_db
id = "123456789012:example_db"
}
import {
to = module.example.aws_iam_instance_profile.example_instance_profile
id = "example_instance_profile"
}
Generating import statements by resource
$ terraform show -json | tf-import-gen aws_instance.example
import {
to = aws_instance.example
id = "i-123456789012"
}
Generating import statements by multiple resource
$ terraform show -json | tf-import-gen aws_instance.example module.example
import {
to = aws_instance.example
id = "i-123456789012"
}
import {
to = module.example.aws_glue_catalog_database.example_db
id = "123456789012:example_db"
}
import {
to = module.example.aws_iam_instance_profile.example_instance_profile
id = "example_instance_profile"
}
Generating import statements for all resources
$ terraform show -json | tf-import-gen
import {
to = module.example.aws_glue_catalog_database.example_db
id = "123456789012:example_db"
}
import {
to = module.example.aws_iam_instance_profile.example_instance_profile
id = "example_instance_profile"
}
import {
to = aws_instance.example
id = "i-123456789012"
}
Usage
$ tf-import-gen --help
Generate terraform import statements to simplify state migrations from one terraform code base to another.
The address argument can be used to filter the instances by resource or module. If
no pattern is given, import statements are generated for all the resources.
The addresses must either be module addresses or absolute resource
addresses, such as:
aws_instance.example
module.example
module.example.module.child
module.example.aws_instance.example
Usage:
tf-import-gen [flags] address...
Examples:
## Generating import statements by module
terraform show -json | tf-import-gen module.example
## Generating import statements by resource
terraform show -json | tf-import-gen aws_instance.example
## Generating import statements by multiple resources
terraform show -json | tf-import-gen aws_instance.example module.example
## Generating import statements for all resources
terraform show -json | tf-import-gen
Flags:
-h, --help help for tf-import-gen
-v, --version version for tf-import-gen
Note
Import management of terraform resources is provider specific, which means that this tool does not have 100% coverage. If you attempt to use this tool and notice that it generates faulty imports, consider extending the support for your resources and contributing a PR.
Contributing
PRs are always welcome!. Refer CONTRIBUTING.md for more information
# Packages
No description provided by the author
# Variables
No description provided by the author