Skip to content

[#1] [ BOUNTY] Add Terraform resource name validation before import#18

Open
lushan888 wants to merge 1 commit into
123a-bcd:mainfrom
lushan888:feat/terraform-name-validation
Open

[#1] [ BOUNTY] Add Terraform resource name validation before import#18
lushan888 wants to merge 1 commit into
123a-bcd:mainfrom
lushan888:feat/terraform-name-validation

Conversation

@lushan888

Copy link
Copy Markdown

Summary

Add explicit validation for Terraform resource names before import operations, preventing hyphenated names (which cause state corruption) and other invalid identifiers from reaching terraform import.

Changes

  • tools/terraform_import.py: Add ResourceToImport.validate_resource_name() static method that checks for valid HCL identifiers. Validation runs in main() before any import, dry-run, or script generation — invalid names are rejected early with actionable error messages.
  • tools/test_terraform_validation.py: 4 tests covering valid names, invalid names (hyphenated, starts with digit, empty, special chars), mixed validation, and CSV-driven import flow.

Testing

  • 4/4 tests pass
  • Valid names: my_resource, resource_123, _private_resource, a, MyAWSInstance
  • Invalid names: my-resource (specific hyphen error message), 123resource, ``, , `my.resource`, `resource@name`

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

Closes #1

- Add ResourceToImport.validate_resource_name() static method
  that checks for valid HCL identifiers: must start with letter or
  underscore, contain only letters/digits/underscores
- Hyphenated names get a specific error message mentioning the
  known Terraform state corruption issue
- Validation runs in main() before any import, dry-run, or script
  generation — invalid names are rejected early with actionable
  error messages
- Add test_terraform_validation.py: 4 tests covering valid names,
  invalid names (including hyphenated), mixed validation, and
  CSV-driven import flow

Issue: 123a-bcd#1
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