Skip to content

Validate Terraform import resource names - #11

Open
GautamKumarOffical wants to merge 1 commit into
123a-bcd:mainfrom
GautamKumarOffical:fix/terraform-import-validation
Open

Validate Terraform import resource names#11
GautamKumarOffical wants to merge 1 commit into
123a-bcd:mainfrom
GautamKumarOffical:fix/terraform-import-validation

Conversation

@GautamKumarOffical

Copy link
Copy Markdown

Summary

Adds explicit validation for Terraform resource names before import, dry-run, and generated script output. Invalid names (especially hyphenated ones that corrupt Terraform state) are now rejected with clear, actionable error messages instead of being passed to Terraform.

Changes

  • Added validate_resource_name() function that rejects empty names, names with invalid characters, and hyphenated names (which corrupt Terraform state per the known issue documented in the module docstring)
  • Hooked validation into import_resource(), import_batch() (dry-run path), and generate_import_script()
  • Added early validation when loading resources from CSV input — invalid names are rejected before any Terraform invocation
  • Added 12 tests covering valid names, hyphenated names, empty names, CSV-driven import handling, and error message formatting

Testing

  • Ran python3 -m pytest tools/test_terraform_import_validation.py — all 12 tests pass
  • Ran python3 build.py — diagnostic build log included in this PR
  • Verified valid names (my_instance, bucket_01, _private) pass validation
  • Verified hyphenated names (my-instance) are rejected with type+name in error message
  • Verified CSV import with invalid names returns exit code 1

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

Validates resource names before import, dry-run, and script generation.
Rejects hyphenated names that corrupt Terraform state with clear error
messages including resource type and name.

Closes #1

Signed-off-by: Gautam Kumar <gautamkumarofficial@users.noreply.github.com>
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.

1 participant