Skip to content

Implement State File Separation for Infrastructure Components #78

@runatyr1

Description

@runatyr1

Why Not Workspaces

  • Less explicit dependency management
  • Higher risk of accidental state modifications
  • Harder to manage different configurations per component
  • More difficult to handle concurrent modifications

Proposed Structure

terraform/
├── environments/
│   └── staging/
│       ├── core/           # VPC, IAM, EKS (required first)
│       ├── apps/          # ArgoCD, other k8s deployments
│       └── data/          # RDS, S3, ElastiCache (future)

Changes Required

New Files

  1. staging/core/main.tf
  • Move VPC, EKS from current staging/main.tf
  • Add data outputs for apps/data dependencies
  1. staging/core/outputs.tf
output "eks_cluster_endpoint" {}
output "vpc_id" {}
output "private_subnets" {}
  1. staging/apps/main.tf
  • Move ArgoCD configuration
  • Add data sources for core dependencies:
data "terraform_remote_state" "core" {
  backend = "s3"
  config = {
    bucket = "your-bucket"
    key    = "staging/core/terraform.tfstate"
  }
}
  1. staging/data/main.tf (future)
  • Similar core dependency pattern
  • Separate state for databases/storage

Modified Files

  1. Move provider configs to each component
  2. Update backend configurations for state separation
  3. Update module references to use remote state data

Dependencies

graph TD
    Core --> Apps
    Core --> Data
Loading
  • Core must be deployed first
  • Apps and Data can be deployed independently
  • Each component gets its own terraform.tfstate

Migration Steps

  1. Backup current state
  2. Create new S3 backend paths
  3. Move resources to new structure
  4. Import existing resources to new states
  5. Update CI/CD for separate apply stages

Future Considerations

  • IAM roles/policies in core
  • Networking components isolated in core
  • Monitoring stack could be separate component
  • Consider secrets management separation

Metadata

Metadata

Assignees

No one assigned

    Labels

    AWSAmazon Web Services

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions