Deploying TextLayer Core
This guide covers deploying applications built with TextLayer Core using Terraform for infrastructure as code. TextLayer Core includes Terraform scripts in the repository that define the AWS infrastructure components needed for a production deployment.Terraform Overview
TextLayer Core uses Terraform to define, provision, and manage the cloud infrastructure required for deployment. The Terraform scripts are located in theinfra directory of the textlayer-core repository and are organized into several modules:
- Network: VPC, subnets, DNS configurations
- Backend: Core infrastructure components
- Langfuse ECS: Langfuse observability platform running on ECS
Deployment Prerequisites
Before deploying TextLayer Core, ensure you have:- AWS Account: Access to an AWS account with appropriate permissions
- AWS CLI: Installed and configured with credentials
- Terraform: Version 1.0 or later installed
- S3 Bucket: For storing Terraform state files (e.g.,
tfstate-core-dev) - textlayer-core Repository: Cloned locally
Terraform state contains sensitive information. Always use encrypted S3 buckets for state storage and restrict access to authorized personnel only.
Deployment Workflow
Step 1: Initialize Terraform
The first step is to initialize Terraform with the S3 backend configuration for state storage:- Development
- Production
Step 2: Plan the Infrastructure Changes
Generate and review an execution plan to see what actions Terraform will take to change your infrastructure:Step 3: Apply the Infrastructure Changes
Apply the execution plan to create or update the infrastructure:Step 4: Verify the Deployment
After applying the changes, verify that the infrastructure was created correctly:Infrastructure Components
TextLayer Core deployment involves several key infrastructure components:Network Module
The network module creates the base networking infrastructure:- VPC with public and private subnets
- Internet Gateway and NAT Gateways
- Route tables and security groups
- DNS configurations (if specified)
Backend Module
The backend module deploys the TextLayer Core application infrastructure:- ECS cluster and task definitions
- Load balancer and target groups
- IAM roles and policies
- CloudWatch log groups
- Other required resources
Langfuse ECS Module
The Langfuse ECS module deploys the observability platform:- ECS cluster for Langfuse
- RDS database
- Load balancer
- Supporting resources
Scaling Strategies
TextLayer Core can be scaled in several ways to accommodate increasing loads:Horizontal Scaling
Adjust the ECS task count to scale the number of application instances:Vertical Scaling
Increase the CPU and memory allocations for ECS tasks:Auto Scaling
Implement ECS auto scaling based on CPU utilization or custom metrics:Best Practices
State Management
- Always use remote state with S3 and DynamoDB for state locking
- Use separate state files for different environments and modules
- Back up state files regularly
Environments
- Use separate AWS accounts for development, staging, and production
- Create environment-specific variable files (e.g.,
dev.tfvars,prod.tfvars) - Use consistent naming conventions that include the environment
Security
- Follow the principle of least privilege for IAM roles
- Encrypt sensitive data in transit and at rest
- Use security groups to restrict network access
- Enable AWS CloudTrail and VPC Flow Logs for auditing
Continuous Integration
- Integrate Terraform with your CI/CD pipeline
- Run
terraform planin CI to validate changes - Use automated testing for infrastructure code
- Only apply changes after successful review
Troubleshooting
If you encounter issues during deployment:- State Lock Issues: Use
terraform force-unlockif a previous operation was interrupted - AWS Permission Errors: Verify IAM permissions and role assumptions
- Resource Creation Failures: Check AWS service quotas and region availability
- Timeout Errors: Some resources take longer to create; adjust timeouts in the configuration