Skip to content

feat: add terraform import block support for existing resources#484

Merged
endavis merged 1 commit intomainfrom
feat/387-terraform-import-blocks
Apr 5, 2026
Merged

feat: add terraform import block support for existing resources#484
endavis merged 1 commit intomainfrom
feat/387-terraform-import-blocks

Conversation

@endavis
Copy link
Copy Markdown
Owner

@endavis endavis commented Apr 4, 2026

Description

Add support for Terraform import blocks via a new import_id field on resource configurations. When a resource has import_id set, InfraFoundry automatically generates the corresponding Terraform import {} block in the output, allowing users to adopt existing infrastructure into Terraform state without running manual terraform import commands.

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvement

Changes Made

  • Added import_id: str | None field to ResourceConfig model
  • Added _generate_import_blocks method to TerraformGeneratorMixin that scans rendered Terraform for resource declarations and matches them against resources with import_id
  • Updated render_and_write_terraform to prepend import blocks when present
  • Passed import_id through all three config loaders (provider-centric, resource-centric, package)
  • Added 17 unit tests covering import block generation, multiple resources, no-op when absent, regex matching, and integration with render_and_write_terraform
  • Updated configuration docs (overview, YAML-only config, state management) to document import_id

Testing

  • All existing tests pass
  • Added new tests for new functionality (17 tests in tests/unit/test_import_blocks.py)
  • doit check passes (format, lint, type-check, security, spell-check, tests)

Checklist

  • My code follows the code style of this project (ran doit format)
  • I have run linting checks (doit lint)
  • I have run type checking (doit type_check)
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass (doit test)
  • I have updated the documentation accordingly
  • I have updated the CHANGELOG.md
  • My changes generate no new warnings

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>
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@endavis endavis added the ready-to-merge PR is reviewed and ready to merge label Apr 5, 2026
@endavis endavis merged commit 1509233 into main Apr 5, 2026
16 of 17 checks passed
@endavis endavis deleted the feat/387-terraform-import-blocks branch April 5, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge PR is reviewed and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant