Generate Terraform import blocks directly from a binary .plan file
Project description
generate-imports-from-plan
Generates Terraform import {} blocks directly from a binary .plan file — no terraform CLI, no provider plugins, no terraform init required.
Why?
terraform show -json does not expose all planned attribute values — computed fields like resource names and resource group names are missing from the JSON output. This tool reads the raw msgpack-encoded attributes directly from the binary plan, giving access to all values needed to construct Azure resource IDs.
For resources whose IDs are assigned at creation time (Entra ID resources, Azure role assignments), the tool calls the Azure CLI to look up the real ID interactively.
Resources whose ID depends on another resource in the same plan (e.g. azurerm_virtual_network_dns_servers needs the VNet ID, subnet associations need the subnet ID) are resolved automatically by reading the plan's HCL references — no CLI call needed. The correct subscription ID is determined per resource by following the azurerm provider chain through the config, so plans that span multiple subscriptions get the right ID on each resource.
Installation
uvx generate-imports-from-plan terraform.plan
Or install permanently:
uv tool install generate-imports-from-plan
generate-imports-from-plan terraform.plan
Requirements
- Python 3.11+
- uv (for
uvx) - Azure CLI (
az) — required for live resolution of Entra ID resources and Azure role assignments
Workflow
# 1. Generate plan
terraform plan -out terraform.plan
# 2. Generate import blocks interactively
generate-imports-from-plan terraform.plan > imports.tf
# 3. Fill in any remaining placeholder IDs, then re-plan and apply
terraform plan -out terraform.plan
terraform apply terraform.plan
Interactive flow
The tool prompts per resource based on what it can derive:
- Complete formula-based ID — emitted immediately, no prompt.
- Cross-plan ID (depends on another resource in the plan) — resolved and emitted automatically, no prompt.
- Entra ID resource or Azure role assignment — shows the
azcommand it will run and asks confirmation. - Unresolvable ID — shows which attribute is computed and its HCL reference chain; asks whether to skip.
- Unsupported import (e.g.
azuread_application_password) — emits a comment block.
Use --yes to accept all without prompting, --no for a dry run.
Output
import {
to = module.core.azurerm_resource_group.this
id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-myapp-dev-we-01"
}
import {
to = module.core.azuread_application.default["my-app"]
id = "/applications/00000000-0000-0000-0000-000000000000"
}
# import not supported for azuread_application_password:
# module.core.azuread_application_password.default["my-app"]
Flags
| Flag | Description |
|---|---|
--yes |
Accept all without prompting |
--no |
Reject all without prompting (dry-run) |
--no-resolve |
Skip Azure CLI lookups; use formula-based IDs only |
--skip-imported |
Skip resources that already have an import {} block in the config |
--list |
Print address\tid pairs instead of HCL blocks |
--list --powershell |
Output a PowerShell array literal of resource addresses |
--target ADDR [ADDR ...] |
Only process the specified resource addresses |
--debug |
Dump all decoded attributes per resource |
Adding a resource type
See docs/resolvers.md for how to add a formula, a cross-plan resolver, or a live resolver.
Quick formula example — extend _ID_FORMULAS in generate_imports/ids.py:
"azurerm_my_resource":
lambda a, s: _arm(s, _str(a, "resource_group_name"),
"Microsoft.MyNamespace/myResources", _str(a, "name")),
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file generate_imports_from_plan-0.3.0.tar.gz.
File metadata
- Download URL: generate_imports_from_plan-0.3.0.tar.gz
- Upload date:
- Size: 41.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cda4ed8ac83815779231d91ab6a0029f039112d789446abe4ac75ed760fc19d9
|
|
| MD5 |
7c8792e44d089a6fe5ebfa698e715400
|
|
| BLAKE2b-256 |
d495b6473cfe42b436a503c2bf74076ad49595565839bb4dfc0718a572ec5be6
|
File details
Details for the file generate_imports_from_plan-0.3.0-py3-none-any.whl.
File metadata
- Download URL: generate_imports_from_plan-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1317c7ece48f4530066190f7348e4774188152ac7c129e183536a1349e7e8f25
|
|
| MD5 |
f4dd3220cb0cb68482971ef304d762e5
|
|
| BLAKE2b-256 |
45e81e31c300197b3a2e39b88dc4dd465505b4d3cc10aaabebb20c8c9e80395e
|