Skip to content

v1.0.4

Latest

Choose a tag to compare

@andreimerlescu andreimerlescu released this 23 Jul 17:53
5cb14ce

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 import issues):
    • Corrected Terraform Command Syntax: Resolves a critical bug where terraform import (and terraform state rm) commands generated by the tool were malformed, leading to execution failures. The tool now correctly structures these commands, placing options like -state before positional arguments (ADDR ID).
    • Explicit Terraform Working Directory (--tf-working-dir flag): Introduces a new command-line flag (--tf-working-dir defaulting to .) that explicitly specifies the directory where terraform commands 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.
  • Guaranteed Error Reporting and Audit Trails to S3:
    • Automatic S3 Upload on Application Crash: Implements a robust error recovery mechanism. If reconcile-tfstate encounters an unexpected error or panic during execution (e.g., a critical terraform command 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 detailed execution_logs array. This array captures the exact command string executed, its stdout, stderr, exit_code, and any error encountered 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_error field at the root level, providing clear visibility into any top-level application panics or critical failures that prevented full report generation.
  • 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 uint66 typo, missing Category field references in ResourceStatus, missing Mode field references in ResourceStateV4, and an undefined serviceName variable in a specific ECS verification path.

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 project

Viewing 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 contains execution_logs for detailed command outcomes.
  • S3 Backups: In the event of a critical failure during execution of the reconcile-tfstate binary itself, look in your S3 bucket (s3://your-bucket/state-backups/YYYY/MM/TIMESTAMP/) for the timestamped report.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.