Skip to content

v1.0.0

Choose a tag to compare

@andreimerlescu andreimerlescu released this 20 Jul 14:29
f6d5eb0

I am excited to announce the initial release of reconcile-tfstate, a crucial new tool designed to help us manage and reconcile our Terraform state files with greater confidence and efficiency. This binary was developed to directly address the challenges we've faced with state file discrepancies, particularly after recent multi-region resource movements.

Key Features & Improvements:

  • Comprehensive State File Analysis: Scans your Terraform state file (.tfstate) and compares it against live AWS resources in a specified region.
  • Intelligent Categorization: Provides a clear, actionable report categorizing every resource into one of six states:
    • OK: Resource exists in both state and AWS, and IDs match.
    • INFO: Local data sources or resources that don't require external AWS verification.
    • WARNING: Resources that are complex to verify fully, or that have minor discrepancies not requiring immediate action (e.g., aws_security_group_rule, aws_region). Manual verification is recommended for these.
    • ERROR: Critical issues found during live AWS checks (e.g., a child resource is present in state, but its parent resource is missing in AWS). These often indicate fundamental infrastructure issues or severe state corruption.
    • REGION_MISMATCH: Resources that exist in the state file but whose ARN indicates a different AWS region than the one being scanned. This helps identify resources that have truly "moved" or are tracked in the wrong state.
    • DANGEROUS: Resources present in the state file but explicitly not found in the target AWS environment. These represent potential drift or unmanaged deletions and require immediate attention.
    • POTENTIAL_IMPORT: Resources found in AWS that exist in your state, but their IDs (or other identifying attributes) don't perfectly match, indicating they might need to be imported to fix the state.
  • Automated Remediation Commands: Generates a ready-to-use list of terraform import and terraform state rm commands to quickly synchronize your state file with reality.
  • S3 State File Support: Seamlessly downloads and prepares state files directly from S3 for analysis, providing clear instructions for re-uploading modified state (with versioning in mind).

How to Use:

# Analyze a local state file
reconcile-tfstate --state dev.tfstate --region us-west-2

# Analyze an S3-backed state file
reconcile-tfstate --s3-state s3://your-bucket/path/to/dev.tfstate --region us-west-2

Known Limitations / Future Enhancements:

  • aws_security_group_rule: Due to the complex, nested nature of security group rules in the AWS API, full attribute-level verification is not yet implemented and they are flagged as WARNING. Manual validation for these specific rules is still recommended.

This tool marks a significant step towards improving our Terraform state hygiene and reducing manual debugging efforts. We encourage everyone working with Terraform to integrate it into their workflow.