feat: add terraform import block support for existing resources#484
Merged
feat: add terraform import block support for existing resources#484
Conversation
Add import_id field to ResourceConfig and generate Terraform import blocks automatically in render_and_write_terraform. Works across all providers with no per-provider changes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Benchmark
Details
| Benchmark suite | Current: 272f291 | Previous: 2a4d52e | Ratio |
|---|---|---|---|
tests/benchmarks/test_placeholder.py::test_import_time |
12617.801265118283 iter/sec (stddev: 0.000004846046533051096) |
9630.1489066661 iter/sec (stddev: 0.0000054635757391543555) |
0.76 |
This comment was automatically generated by workflow using github-action-benchmark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add support for Terraform
importblocks via a newimport_idfield on resource configurations. When a resource hasimport_idset, InfraFoundry automatically generates the corresponding Terraformimport {}block in the output, allowing users to adopt existing infrastructure into Terraform state without running manualterraform importcommands.The implementation is framework-level in
TerraformGeneratorMixin.render_and_write_terraform, so it works across all providers with no per-provider changes.Related Issue
Addresses #387
Type of Change
Changes Made
import_id: str | Nonefield toResourceConfigmodel_generate_import_blocksmethod toTerraformGeneratorMixinthat scans rendered Terraform for resource declarations and matches them against resources withimport_idrender_and_write_terraformto prepend import blocks when presentimport_idthrough all three config loaders (provider-centric, resource-centric, package)import_idTesting
tests/unit/test_import_blocks.py)doit checkpasses (format, lint, type-check, security, spell-check, tests)Checklist
doit format)doit lint)doit type_check)doit test)