https://github.com/woodprogrammer/tf_importer
Generate terraform import commands
https://github.com/woodprogrammer/tf_importer
aws devops iac terraform
Last synced: 6 months ago
JSON representation
Generate terraform import commands
- Host: GitHub
- URL: https://github.com/woodprogrammer/tf_importer
- Owner: WoodProgrammer
- Created: 2021-10-07T20:39:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-26T12:49:39.000Z (over 4 years ago)
- Last Synced: 2025-04-28T11:50:16.439Z (11 months ago)
- Topics: aws, devops, iac, terraform
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tf_importer
This tool helps to generate terraform import commands for the huge terraform stack. If you want to import terraform resources to make your configuration and terraform states under the same state you can use this tool for the huge terraform stacks.
The tools like former2 allows us to generate entire AWS stack but while you are importing this, that can take too much time.
tf_import helps to generate import commands for the huge amount of stacks.
# How it works
The most important configuration file is resource_mapping.yaml file, this file contains the configuration map and provider specific keys based on your provider.
```yaml
## resource_map.yaml
resources:
buckets:
to_import: aws_s3_bucket
import_key: bucket
prefix: ""
suffix: ""
sns_topics:
to_import: aws_sns_topic
import_key: name
prefix: "arn:aws:sns:us-west-2:0123456789012:"
suffix: ""
staging_helm_releases:
to_import: helm_release
import_key: name
prefix: "/"
suffix: ""
```
Under the resources map, you only have to define which resources you need to import;
* to_import : Resource name of the provider
* import_key: The identifier key in the resource definition
* prefix: The prefix to refer real resource. Because some of the resources like AWS SNS requires a direct arn name so that you have to set a arn prefix in front of the resource name.You can check the example usage.
* suffix: The suffix to refer real resource.
After you defined your resource map you only have to run this command like that;
```sh
$ python3 main.py --file resource_mapping.yaml --directory ./infra
terraform import aws_s3_bucket.b my-tf-test-bucket
terraform import aws_sns_topic.user_updates arn:aws:sns:us-west-2:0123456789012:user-updates-topic
terraform import aws_rds_cluster.default aurora-cluster-demo
terraform import aws_rds_cluster.default_new aurora-cluster-demo
terraform import aws_rds_cluster.default_hede aurora-cluster-demo
```
## TODO
- Dynamic and block based import generation
- Manual Resource Check
- Config Drift Check