Skip to main content

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. --out splits resolved blocks (imports.tf) from
#    unresolved ones (imports.tf.unresolved); re-running converges.
generate-imports-from-plan terraform.plan --out imports.tf

# 3. Fill in any placeholders from imports.tf.unresolved, move them into
#    imports.tf, then re-plan and apply
terraform plan -out terraform.plan
terraform apply terraform.plan

Without --out, import blocks go to stdout (pipe with > imports.tf); unresolved ones are emitted as commented blocks.

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 az command it will run and asks confirmation.
  • Unresolvable ID — shows which attribute is computed and its HCL reference chain; emitted to the unresolved sink (sidecar with --out, commented block otherwise).
  • Unsupported import (e.g. azuread_application_password) — emits a comment block.

Use --auto-resolve for a fully autonomous run (runs every az lookup without asking), or --dry-run to skip az calls and resolve deterministically (formula + cross-plan) only.

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
--out FILE Write resolved blocks to FILE, unresolved to FILE.unresolved; re-running converges
--auto-resolve Run every Azure CLI resolve automatically, without prompting
--dry-run Skip Azure CLI calls; resolve with formula + cross-plan only (no prompts)
--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 emit the specified addresses (other plan resources stay available as cross-plan resolution context)
--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")),

Metadata

Release files for generate-imports-from-plan 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generate-imports-from-plan 0.4.0
File Size Uploaded
generate_imports_from_plan-0.4.0.tar.gz 59.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for generate-imports-from-plan 0.4.0
File Interpreter ABI Platform
generate_imports_from_plan-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 87.8 kB

Release files / generate_imports_from_plan-0.4.0.tar.gz

Download URL generate_imports_from_plan-0.4.0.tar.gz
Size 59.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1e05476c5e45f4771b6b9cbd5e36815817da4abf5862bfa115922f320bfb9da4
BLAKE2b-256 checksum
How to use checksums
3322b3e3359c1e800652679f87c1e830d9f4a9cb507e0b0cc96349e43abafc6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","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}

Release files / generate_imports_from_plan-0.4.0-py3-none-any.whl

Download URL generate_imports_from_plan-0.4.0-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fb651ea55e013a7b89742679f267f019fb9b9aa0bd7731fb64e37c728d932f6
BLAKE2b-256 checksum
How to use checksums
5ac138a8c34b72f883a525571287115a6e34332671a13a9cc66a8e7cdb717c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","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}

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page