Skip to content

Fix #1: Validate Terraform import resource names#5

Open
shadow6427 wants to merge 3 commits into
123a-bcd:mainfrom
shadow6427:validate-terraform-imports
Open

Fix #1: Validate Terraform import resource names#5
shadow6427 wants to merge 3 commits into
123a-bcd:mainfrom
shadow6427:validate-terraform-imports

Conversation

@shadow6427

Copy link
Copy Markdown

Summary

Add explicit validation for Terraform resource names before import to prevent Terraform state corruption caused by hyphenated names. Fixes #1.

Changes

  • Added validate_resource method to TerraformImporter in tools/terraform_import.py.
  • Validation checks that resource_name is a valid Terraform identifier (^[a-zA-Z_][a-zA-Z0-9_]*$) and does not contain hyphens.
  • Integrated validation into import_batch to reject invalid resources with actionable errors and fail the import.
  • Integrated validation into generate_import_script to raise a ValueError for invalid resources instead of writing unsafe commands.
  • Added a deterministic validation script tools/test_terraform_import.py with tests covering valid names, hyphenated names, invalid Terraform identifiers, and batch importing behavior.

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

  • I would like to request that my diagnostic build log is removed before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[$40 BOUNTY] [Python] Validate Terraform import resource names

1 participant