Skip to content

fix: validate Terraform resource names before import (0 bounty) - #14

Open
gaomingyi779-del wants to merge 2 commits into
123a-bcd:mainfrom
gaomingyi779-del:fix/validate-terraform-resource-names
Open

fix: validate Terraform resource names before import (0 bounty)#14
gaomingyi779-del wants to merge 2 commits into
123a-bcd:mainfrom
gaomingyi779-del:fix/validate-terraform-resource-names

Conversation

@gaomingyi779-del

Copy link
Copy Markdown

@

Issue

Closes #1 — [$40 BOUNTY] [Python] Validate Terraform import resource names

Changes

Production code (tools/terraform_import.py)

  • Added validate_resource_name() — rejects hyphens, dots, uppercase, and other invalid characters. Only [a-z][a-z0-9_]* permitted.
  • Validation in CSV loading: invalid names are skipped with a clear error, counting skipped resources.
  • Validation in import_resource(): invalid names fail before any terraform import invocation, preventing state corruption.

Tests (tools/test_terraform_import_validation.py)

8 focused tests:

  1. Valid names (underscore-separated) pass validation
  2. Hyphenated names raise ValueError with clear message
  3. Empty names rejected
  4. Uppercase names rejected
  5. Names with dots rejected
  6. CSV mixed import: valid imported, invalid skipped
  7. Script generation preserves valid names (regression)
  8. Invalid name fails import_resource before reaching terraform binary

Required artifacts

  • diagnostic/build-*.logd included
  • diagnostic/build-*.json included

Verification

All 8 validation tests passed

🤖 Generated with Claude Code
@

gaomingyi779-del and others added 2 commits June 24, 2026 18:17
fix: validate Terraform resource names before import ($40 bounty)

- Add validate_resource_name() that rejects hyphens, dots, uppercase,
  and other characters unsafe for Terraform resource identifiers.
  Only [a-z][a-z0-9_]* is permitted.
- Validate names during CSV loading (skip invalid rows with clear error)
- Validate names in import_resource() before terraform invocation
- Add 8 focused tests covering valid names, hyphenated rejection,
  empty name, uppercase, dots, CSV mixed import, script generation,
  and invalid-name failure path
- Include diagnostic artifacts from build.py

Fixes the known issue where hyphenated resource names cause Terraform
state corruption by catching them early with a clear error message.

Closes 123a-bcd#1

Co-Authored-By: Claude <noreply@anthropic.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.

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

1 participant