Skip to main content
Back to projects

Terraform State Migration

Migrated Terraform backend state from cloud storage to PostgreSQL, creating a cloud-agnostic solution for infrastructure state management.

TerraformPostgreSQLAWSGCP

Overview

Led the migration of Terraform backend state from cloud-specific storage solutions (S3, GCS) to a centralized PostgreSQL database, creating a cloud-agnostic approach to infrastructure state management across a hybrid cloud environment.

Problem

With infrastructure spread across AWS, GCP, and Alibaba Cloud, Terraform state was fragmented across different cloud storage backends — S3 buckets for AWS resources, GCS buckets for GCP resources. This created operational complexity: different access patterns, inconsistent locking mechanisms, and no unified view of infrastructure state.

Solution

  • Designed a centralized PostgreSQL-based backend that serves as a single state store across all cloud providers
  • Developed a migration tool to safely move existing state files from S3 and GCS to PostgreSQL with zero downtime
  • Implemented state locking using PostgreSQL advisory locks for consistent concurrent access
  • Set up automated backups and point-in-time recovery for the state database

Impact

  • Unified state management across all cloud providers into a single backend
  • Simplified access control — one set of database credentials instead of IAM roles per cloud
  • Improved auditability with database-level logging of all state changes
  • Enabled easier disaster recovery with standard PostgreSQL backup and restore

Technical Details

  • IaC: Terraform
  • Backend: PostgreSQL (pg backend)
  • Previous: S3, GCS
  • Cloud Providers: AWS, GCP, Alibaba Cloud