{"id":49883987,"url":"https://github.com/coolapso/tfimport","last_synced_at":"2026-06-11T08:01:24.672Z","repository":{"id":357108666,"uuid":"1232096434","full_name":"coolapso/tfimport","owner":"coolapso","description":"Automatically import infrastructure to tfstate","archived":false,"fork":false,"pushed_at":"2026-06-02T10:53:29.000Z","size":9034,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-02T12:09:37.312Z","etag":null,"topics":["automation","cli","iac","opentofu","terraform"],"latest_commit_sha":null,"homepage":"https://tfimport.coolapso.sh","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coolapso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null},"funding":{"github":"coolapso","buy_me_a_coffee":"coolapso"}},"created_at":"2026-05-07T15:28:25.000Z","updated_at":"2026-06-02T10:53:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/coolapso/tfimport","commit_stats":null,"previous_names":["coolapso/tfimport"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/coolapso/tfimport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolapso%2Ftfimport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolapso%2Ftfimport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolapso%2Ftfimport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolapso%2Ftfimport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coolapso","download_url":"https://codeload.github.com/coolapso/tfimport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coolapso%2Ftfimport/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34188272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","cli","iac","opentofu","terraform"],"created_at":"2026-05-15T17:00:43.818Z","updated_at":"2026-06-11T08:01:24.648Z","avatar_url":"https://github.com/coolapso.png","language":"Go","funding_links":["https://github.com/sponsors/coolapso","https://buymeacoffee.com/coolapso"],"categories":["Tools"],"sub_categories":["State","Community providers"],"readme":"# tfimport 🚀\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"tfimport_nobg.png\" alt=\"tfimport gopher mascot\" width=\"300\" /\u003e\n\u003c/p\u003e\n\n`tfimport` is a Go-based CLI auto-pilot designed to automate the painful process of importing existing infrastructure into a Terraform or OpenTofu state file. \n\nInstead of manually hunting down the correct `terraform import` string format for every single resource (Is it an ARN? A VPC ID? A namespace/name combo?), you simply write the code that matches your existing infrastructure, generate a plan, and let `tfimport` figure out the rest.\n\n## ✨ Features\n\n- **Multi-Tool Support**: Works seamlessly with `terraform`, `terragrunt`, and `tofu`.\n- **Smart ID Deduction**: Understands the provider-specific import formats for hundreds of resources (e.g., AWS, Kubernetes).\n- **Offline Capable**: Can parse an existing `terraform show -json` plan file without needing to re-run plans.\n- **SDK Lookups**: Uses cloud provider SDKs (like AWS SDK) to look up opaque IDs (like `vpc-xxxxx` or resolving `aws_iam_policy` ARNs from path prefixes) based on tags and attributes known at plan time.\n- **Resilient**: Gracefully skips newly created resources and handles rate limiting with built-in configurable delays.\n\n## 📦 Installation\n\n### Arch Linux (AUR)\nYou can install `tfimport` from the Arch User Repository using your favorite AUR helper (e.g., `yay`, `paru`):\n```bash\nyay -S tfimport-bin\n```\n\n### Debian-based / Ubuntu\nGrab the latest `.deb` package from the [Releases](https://github.com/coolapso/tfimport/releases) page and install it:\n```bash\n# Example for amd64 architecture\nwget https://github.com/coolapso/tfimport/releases/latest/download/tfimport_\u003cversion\u003e_linux_amd64.deb\nsudo dpkg -i tfimport_\u003cversion\u003e_linux_amd64.deb\n```\n\n### RPM-based (RHEL, Fedora, CentOS)\nGrab the latest `.rpm` package from the [Releases](https://github.com/coolapso/tfimport/releases) page and install it:\n```bash\n# Example for amd64 architecture\nwget https://github.com/coolapso/tfimport/releases/latest/download/tfimport_\u003cversion\u003e_linux_amd64.rpm\nsudo rpm -i tfimport_\u003cversion\u003e_linux_amd64.rpm\n```\n\n### Go Install ( Linux / macOS / Windows )\nIf you have Go installed on your system, you can build and install it directly:\n```bash\n# Install the latest version\ngo install github.com/coolapso/tfimport@latest\n\n# Or install a specific version\ngo install github.com/coolapso/tfimport@v0.0.1\n```\n\n### Windows\nDownload the latest Windows `.zip` archive from the [Releases](https://github.com/coolapso/tfimport/releases) page. Extract the `tfimport.exe` binary and move it to a folder that is included in your system's `PATH`.\nAlternatively, you can build it from source using the `go install` method above.\n\n### Install Script (macOS / Linux)\nYou can also use our convenient installation script that automatically detects your OS and architecture, and downloads the correct binary to `/usr/local/bin`:\n```bash\ncurl -sL https://raw.githubusercontent.com/coolapso/tfimport/main/docs/install.sh | sudo bash\n```\n*(An uninstall script is also available at `docs/uninstall.sh`)*\n\n## 🛠 Usage\n\n1. Write your Terraform/Terragrunt manifests to match the infrastructure that already exists in the cloud.\n2. Run `tfimport` and point it to your tool of choice!\n\n```bash\n# Using Terragrunt with an existing plan file\ntfimport --tg --plan-file .tfimport/tfplan\n\n# Using Terraform\ntfimport --terraform\n\n# Using OpenTofu (Default)\ntfimport\n```\n\n### Flags\n\n- `--tg`: Execute plan and import using Terragrunt.\n- `--terraform` / `--tf`: Execute plan and import using Terraform.\n- `--plan-file \u003cpath\u003e`: Provide a path to an existing plan file to skip the planning phase.\n- `--dry-run`: Show import details, only used with `--run-import`.\n- `--ignore \u003cpatterns\u003e`: Comma-separated list of resource addresses or wildcards to ignore (e.g., `aws_iam_role.*`, `module.new_feature.*`). Can be set multiple times.\n- `--run-import`: Import resources directly via the CLI instead of generating an `import.tf` block file.\n- `--delay \u003cduration\u003e`: Set a delay between imports to avoid API rate limits and DNS exhaustion when using `--run-import` (e.g., `1s`, `5s`). Defaults to `2s`.\n\n---\n\n## ⚖️ Import Execution\n\nBy default, `tfimport` generates a static `import.tf` file containing HCL `import {}` blocks (available in Terraform 1.5+ and OpenTofu). You can opt out of this and run CLI imports sequentially by passing the `--run-import` flag.\n\n### 💡 Resilience \u0026 Smart Imports\n- **Graceful New Resource Handling:** If `tfimport` attempts to import a resource and the cloud provider returns a \"non-existent remote object\" error, it intelligently assumes this is a genuinely new resource you want to create (not import). It will gracefully skip it and continue without penalizing you with error timeouts.\n- **SDK Lookups:** Uses cloud provider SDKs (like AWS SDK) to look up opaque IDs (like `vpc-xxxxx` or IAM Policy ARNs based on `name_prefix`) using attributes known at plan time.\n\n## 💻 For Developers\n\n`tfimport` is designed to be highly extensible. The core logic (`cmd/root.go`) is completely decoupled from the provider-specific logic. \n\nAll ID deduction logic lives in the `internal/providers/` package. The CLI simply passes the resource type and configuration to `providers.GetImportID(ctx, resourceType, config)`.\n\n### Adding Support for New Providers (🛑 READ THIS FIRST)\n\nTerraform providers (like Azure, GCP, or even AWS) have *hundreds* to *thousands* of resources. Each resource has its own specific string format required for the `terraform import` command.\n\n**DO NOT DO THIS MANUALLY.** It is incredibly tedious and error-prone. \n\nInstead, we strongly recommend using an **AI Agent** (like Copilot, Cursor, or Claude) to bootstrap new providers. We have built a specialized workflow for this:\n\n1. **Read the AI Guide:** Check out [`AGENTS.md`](AGENTS.md) in the root of the project. This file contains precise instructions for AI agents on how this project is structured.\n2. **The Doc Cruncher Trick:** Inside the `scripts/` directory, there is a `doc_cruncher.go` script. You (or your AI agent) can clone the official HashiCorp provider documentation repository (e.g., `terraform-provider-google`) and run the script against the markdown files. The script uses Regex to parse the \"Import\" sections of the official documentation and automatically generates the entire Go switch statement for thousands of resources in seconds!\n3. **Custom Resolvers:** Not all IDs can be statically generated. Some require querying the cloud API (e.g., looking up a VPC ID by its Name tag). For this, the system supports \"Custom Resolvers\" (e.g., `internal/providers/aws_resolvers.go`). The injected `ProviderContext` allows you to lazy-load cloud SDK clients (like the AWS EC2 client) only when that specific provider's resources are encountered, keeping the core tool completely provider-agnostic. Custom resolvers take precedence over the auto-generated documentation mappings.\n\n### Building Locally\n\n```bash\ngit clone https://github.com/coolapso/tfimport.git\ncd tfimport\ngo build ./...\ngo run main.go --help\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolapso%2Ftfimport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoolapso%2Ftfimport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoolapso%2Ftfimport/lists"}