
Terraform Search Import
Discover existing cloud resources with Terraform Search list queries and bulk-import them into state so unmanaged infra becomes auditable IaC.
Install
npx skills add https://github.com/hashicorp/agent-skills --skill terraform-search-importWhat is this skill?
- Terraform Search list block plus bulk import workflow per HashiCorp docs
- Mandatory first step: ./scripts/list_resources.sh to verify provider list support
- Decision tree from resource type → support check → query → generated import config
- Use cases: unmanaged resources, audits, manual-to-IaC migration, multi-region discovery
- Requires Terraform >= 1.14 and providers with list resource support
Adoption & trust: 1.8k installs on skills.sh; 654 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Operate/infra is the canonical shelf for adopting Terraform control over live resources, though the same flow supports migration during Build integrations and pre-ship audits. Search-and-import is infrastructure state management—aligning real cloud inventory with Terraform—not application frontend or growth analytics.
Common Questions / FAQ
Is Terraform Search Import safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Terraform Search Import
# Terraform Search and Bulk Import Discover existing cloud resources using declarative queries and generate configuration for bulk import into Terraform state. **References:** - [Terraform Search - list block](https://developer.hashicorp.com/terraform/language/block/tfquery/list) - [Bulk Import](https://developer.hashicorp.com/terraform/language/import/bulk) ## When to Use - Bringing unmanaged resources under Terraform control - Auditing existing cloud infrastructure - Migrating from manual provisioning to IaC - Discovering resources across multiple regions/accounts ## IMPORTANT: Check Provider Support First **BEFORE starting, you MUST verify the target resource type is supported:** ```bash # Check what list resources are available ./scripts/list_resources.sh aws # Specific provider ./scripts/list_resources.sh # All configured providers ``` ## Decision Tree 1. **Identify target resource type** (e.g., aws_s3_bucket, aws_instance) 2. **Check if supported**: Run `./scripts/list_resources.sh <provider>` 3. **Choose workflow**: - ** If supported**: Check for terraform version available. - ** If terraform version is above 1.14.0** Use Terraform Search workflow (below) - ** If not supported or terraform version is below 1.14.0 **: Use Manual Discovery workflow (see [references/MANUAL-IMPORT.md](references/MANUAL-IMPORT.md)) **Note**: The list of supported resources is rapidly expanding. Always verify current support before using manual import. ## Prerequisites Before writing queries, verify the provider supports list resources for your target resource type. ### Discover Available List Resources Run the helper script to extract supported list resources from your provider: ```bash # From a directory with provider configuration (runs terraform init if needed) ./scripts/list_resources.sh aws # Specific provider ./scripts/list_resources.sh # All configured providers ``` Or manually query the provider schema: ```bash terraform providers schema -json | jq '.provider_schemas | to_entries | map({key: (.key | split("/")[-1]), value: (.value.list_resource_schemas // {} | keys)})' ``` Terraform Search requires an initialized working directory. Ensure you have a configuration with the required provider before running queries: ```hcl # terraform.tf terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 6.0" } } } ``` Run `terraform init` to download the provider, then proceed with queries. ## Terraform Search Workflow (Supported Resources Only) 1. Create `.tfquery.hcl` files with `list` blocks defining search queries 2. Run `terraform query` to discover matching resources 3. Generate configuration with `-generate-config-out=<file>` 4. Review and refine generated `resource` and `import` blocks 5. Run `terraform plan` and `terraform apply` to import ## Query File Structure Query files use `.tfquery.hcl` extension and support: - `provider` blocks for authentication - `list` blocks for resource discovery - `variable` and `locals` blocks for parameterization ```hcl # discovery.tfquery.hcl provider "aws" { region = "us-west-2" } list "aws_instance" "all" { provider = aws } ``` ## List Block Syntax ```hcl list "<list_type>" "<symbolic_name>" { provider = <provider_reference> # Required # Optional: filter configuration (provider-specific) # The `config` block schema is provider-specific. Discover available options using `terraform providers schema -json | jq '.provid