I am pleased to announce the release of reconcile-tfstate v1.0.4, a critical stability and usability enhancement release. This version addresses crucial operational gaps identified during real-world CI/CD pipeline integration, ensuring more reliable command execution and guaranteeing comprehensive diagnostic reporting even in the face of unexpected errors.
Building on the comprehensive reporting and backup capabilities introduced in previous versions, v1.0.4 makes reconcile-tfstate more resilient and transparent, particularly for automated reconciliation workflows.
Key Features & Improvements in v1.0.4:
- Robust Command Execution (Fixes
terraform importissues):- Corrected Terraform Command Syntax: Resolves a critical bug where
terraform import(andterraform state rm) commands generated by the tool were malformed, leading to execution failures. The tool now correctly structures these commands, placing options like-statebefore positional arguments (ADDR ID). - Explicit Terraform Working Directory (
--tf-working-dirflag): Introduces a new command-line flag (--tf-working-dirdefaulting to.) that explicitly specifies the directory whereterraformcommands should be executed. This ensures consistency and predictability, especially in complex CI/CD environments where the binary might be invoked from varying paths relative to the Terraform project.
- Corrected Terraform Command Syntax: Resolves a critical bug where
- Guaranteed Error Reporting and Audit Trails to S3:
- Automatic S3 Upload on Application Crash: Implements a robust error recovery mechanism. If
reconcile-tfstateencounters an unexpected error or panic during execution (e.g., a criticalterraformcommand fails), it will now automatically attempt to upload all generated local backups and reports (Markdown and JSON) to your configured S3 bucket. This ensures vital diagnostic information is captured and persisted for debugging, even if the application terminates unexpectedly. - Comprehensive Command Execution Logs in Reports: The JSON report (
report.<env>.json) now includes a detailedexecution_logsarray. This array captures the exact command string executed, itsstdout,stderr,exit_code, and anyerrorencountered for every remediation command attempted. This provides an invaluable audit trail, clarifying precisely what happened during automated execution. - Enhanced JSON Report for Root-Level Errors: The JSON report now features an
application_errorfield at the root level, providing clear visibility into any top-level application panics or critical failures that prevented full report generation.
- Automatic S3 Upload on Application Crash: Implements a robust error recovery mechanism. If
- Internal Code Quality & Efficiency Enhancements:
- Optimized Struct Memory Layout: Fields within key Go structs (
Config,ResourceStatus,AWSClient,TFStateFile,OutputStateV4,ResourceStateV4,InstanceObjectStateV4,CheckResultsV4,CheckResultsObjectV4,CommandExecutionLog,JSONBackupPaths,JSONResultItem,JSONResults,JSONOutput) have been reordered from largest to smallest type size. This reduces memory padding, leading to a slightly smaller memory footprint and potentially improved performance. - Resolved Minor Typos and Logic Gaps: Addressed small but impactful errors such as a
uint66typo, missingCategoryfield references inResourceStatus, missingModefield references inResourceStateV4, and an undefinedserviceNamevariable in a specific ECS verification path.
- Optimized Struct Memory Layout: Fields within key Go structs (
How to Use (New --tf-working-dir flag & Enhanced JSON Output):
To leverage the new working directory control:
# Example in GitHub Actions or any script:
# Assuming your Terraform project root is in: /home/runner/work/another-terraform-project/another-terraform-project/terraform-environments/dev
# And reconcile-tfstate is run from: /home/runner/work/another-terraform-project/another-terraform-project/terraform-environments/dev
./reconcile-tfstate \
-s3-state "s3://your-bucket/path/to/dev.tfstate" \
-region "us-west-2" \
-backups-dir "./backups" \
--json \
--should-execute \
--tf-working-dir "." # Or, if run from a different directory, specify the actual path to your Terraform projectViewing the Changes and Audit Trails:
- GitHub Actions Artifacts: After any workflow run (even failed ones), navigate to the "Summary" tab of the workflow run in GitHub Actions. Look for the "Artifacts" section. The generated JSON report (
tfstate-man-report-env-region.json) will be available for download. This report now containsexecution_logsfor detailed command outcomes. - S3 Backups: In the event of a critical failure during execution of the
reconcile-tfstatebinary itself, look in your S3 bucket (s3://your-bucket/state-backups/YYYY/MM/TIMESTAMP/) for the timestampedreport.json,report.txt, and backup state files. These will contain the diagnostic information.
Known Limitations / Future Enhancements:
- This tool still only supports Terraform state file format version 4.
This v1.0.4 release significantly enhances reconcile-tfstate's reliability and diagnostic capabilities, making it an even more trustworthy component in your automated infrastructure management workflows.