Skip to main content

Infrastructure Modules

DocuStack uses a modular Terraform architecture with 16 production-ready modules organized into logical groups. All modules are versioned and maintained in the docustack-infrastructure-modules repository.

Module Categories

Core Infrastructure

Foundation modules that every environment requires:

ModulePurposeHIPAA
BootstrapTerraform state backend (S3 + DynamoDB)Yes
VPCMulti-AZ networking with VPC endpointsYes
ECS ClusterFargate cluster with Spot supportYes
ECRContainer registry with lifecycle policiesYes
RDSPostgreSQL with encryption and backupsYes

Database & Workflows

Application-layer infrastructure:

ModulePurposeHIPAA
DB Init LambdaAutomated database initializationYes
TemporalWorkflow orchestration on ECSYes

Secure Access

Zero-trust access to private resources:

ModulePurposeHIPAA
BastionOn-demand SSM bastion hostsYes
Bastion OrchestratorLifecycle management for bastionsYes

Cost Management

Automated cost optimization:

ModulePurposeSavings
Nightly SchedulerStop/start resources on schedule60-70%
Infra OrchestratorTier 1/2 teardown routingVariable

ChatOps

Slack-based infrastructure management:

ModulePurpose
Slack BotSocket Mode bot for infrastructure commands
IP WhitelistDynamoDB-backed IP management with auto-sync

Security & Compliance

Preventive and detective controls:

ModulePurposeHIPAA
ComplianceAWS Config with HIPAA conformance packYes
SCP PoliciesOrganization-wide guardrailsYes
GitHub Actions OIDCSecure CI/CD authenticationYes

Module Versioning

All modules use semantic versioning via Git tags:

terraform {
source = "git::git@github.com:docustackapp/docustack-infrastructure-modules.git//modules/vpc?ref=v1.2.0"
}

Version Strategy:

  • Major (v2.0.0): Breaking changes requiring migration
  • Minor (v1.1.0): New features, backward compatible
  • Patch (v1.0.1): Bug fixes only

Lambda Code Location

Infrastructure Lambda functions (bastion-orchestrator, db-init, nightly-scheduler, etc.) have their code in the monorepo and their deployment configuration in infrastructure-modules:

docustack-mono/services/lambdas/
├── bastion-orchestrator/ # Lambda code
├── db-init/
├── infra-orchestrator/
├── ip-whitelist-manager/
└── nightly-scheduler/

docustack-infrastructure-modules/modules/
├── bastion-orchestrator/ # Terraform module
├── db-init-lambda/
├── infra-orchestrator/
├── ip-whitelist/
└── nightly-scheduler/

This separation ensures:

  • Application code (monorepo) defines WHAT to deploy
  • Infrastructure modules define HOW to deploy

Quick Reference

Deployment Order

For a new environment, deploy modules in this order:

  1. bootstrap - State backend (run locally first)
  2. vpc - Networking foundation
  3. ecs-cluster - Container orchestration
  4. ecr - Container registry
  5. rds - Database
  6. db-init-lambda - Initialize databases
  7. temporal - Workflow engine
  8. bastion-orchestrator - Secure access
  9. nightly-scheduler - Cost optimization
  10. slack-bot - ChatOps (optional)

Environment-Specific Configurations

SettingDevStagingProd
Multi-AZNoYesYes
Fargate Spot100%80%50%
RDS Instancedb.t3.smalldb.t3.mediumdb.r5.large
Backup Retention7 days14 days35 days
Deletion ProtectionNoYesYes
Nightly SchedulerEnabledEnabledDisabled