A comprehensive Terraform-based infrastructure-as-code project for managing multi-cloud resources supporting the Kainos Core application platform. This project provides reusable modules and environment-specific configurations for serverless functions, storage, and related cloud services across AWS and Azure.
The infrastructure supports a form-based application platform with the following key components:
- Serverless Functions: Main application logic for form processing and rendering (AWS Lambda / Azure Functions)
- Upload Functions: Specialized functions for handling KFD (Kainos Form Definition) file uploads
- Cloud Storage: Secure storage for form definitions and user uploads (S3 / Azure Storage)
- Multi-Environment Support: Separate configurations for dev, staging, and production environments
- Multi-Cloud Support: Infrastructure deployable to both AWS and Azure
Before you begin, ensure you have met the following requirements:
- Terraform: Ensure you have Terraform installed. You can install it using tfenv if the current version does not match the expected version in your environment.
- Pre-commit: Ensure you have pre-commit installed. If not, it will be installed during the
initprocess. - Python: Required for installing pre-commit.
- Cloud CLI:
- AWS CLI: Configured with appropriate credentials and permissions (for AWS deployments)
- Azure CLI: Configured with appropriate credentials and permissions (for Azure deployments)
- Node.js: Required for serverless function development and testing
git clone <this-repo>
cd KainosStudio-CoreInfraThis project supports multiple cloud providers. Navigate to the provider-specific directory:
cd awscd azureOnce you've selected your provider directory, run:
make init devThis command will:
- Initialize Terraform backend for the selected provider
- Install pre-commit hooks
- Download required providers and modules
Each provider directory includes a Makefile with commands to manage Terraform configurations and pre-commit hooks.
dev: Development environment (default)staging: Staging environmentpipeline: Pipeline environmentprod: Production environment
init: Initialize Terraform and pre-commit dependenciesplan: Create a Terraform planapply: Apply Terraform changes using the plandestroy: Destroy Terraform infrastructurefmt: Format Terraform filesvalidate: Validate Terraform configurationcheckov: Run Checkov security scancheck: Runfmt,validate, and Checkov scanpre-commit-install: Install pre-commit hookspre-commit-run: Run pre-commit hooks
# For AWS - Plan changes for development environment
cd aws
make plan dev
# For Azure - Apply changes to staging environment
cd azure
make apply staging
# Run security scan (from respective provider directory)
make checkov prod
# Format and validate all configurations
make checkKainosStudio-CoreInfra/
βββ aws/ # AWS-specific infrastructure
β βββ modules/
β β βββ lambda/ # AWS Lambda module
β β βββ s3/ # AWS S3 module
β βββ dev/
β β βββ resources.tf # AWS Core Resources
β β βββ lambdas/
β β βββ core/ # Core application Lambda
β β βββ upload/ # Upload handling Lambda
β βββ staging/
β βββ prod/
β βββ pipeline/
β βββ Makefile # AWS-specific commands
β βββ checkov.yaml # AWS security scanning config
βββ azure/ # Azure-specific infrastructure
β βββ modules/
β β βββ function-app/ # Azure Functions module
β β βββ storage/ # Azure Storage module
β βββ dev/
β β βββ resources.tf # Azure Core Resources
β β βββ functions/
β β βββ core/ # Core application Function
β β βββ upload/ # Upload handling Function
β βββ staging/
β βββ prod/
β βββ pipeline/
β βββ Makefile # Azure-specific commands
β βββ checkov.yaml # Azure security scanning config
βββ .github/ # GitHub Actions workflows
βββ .pre-commit-config.yaml # Pre-commit configuration
βββ README.md # This file
A versatile module for deploying AWS Lambda functions with comprehensive configuration options.
Key Features:
- Configurable runtime, memory, and timeout settings
- Environment variable management
- CloudWatch logging with encryption
- Version management and aliasing
- Automated source code packaging
Basic Usage:
module "my_lambda" {
source = "./modules/lambda"
function_name = "myFunction"
description = "My Lambda function"
env = "dev"
handler = "index.handler"
runtime = "nodejs18.x"
memory_size = 256
environment_variables = {
NODE_ENV = "development"
}
logs_retention_days = 30
lambda_execution_role_arn = aws_iam_role.lambda_exec.arn
cloudwatch_kms_key_id = aws_kms_key.logs.arn
lambda_source_dir = "src/"
publish = true
}A comprehensive module for creating and managing S3 buckets with security best practices.
Key Features:
- Server-side encryption with KMS
- Versioning and lifecycle management
- Access logging configuration
- Public access blocking
- Automated file uploads
- Comprehensive tagging
Basic Usage:
module "kfd_files_bucket" {
source = "./modules/s3"
bucket_name = "my-bucket-name"
enable_versioning = true
enable_encryption = true
enable_public_access_block = true
kms_key_id = aws_kms_key.s3.arn
tags = {
Environment = "development"
Project = "kainoscore"
}
}A comprehensive module for deploying Azure Functions with enterprise-grade configuration.
Key Features:
- Configurable runtime and scaling settings
- Application settings management
- Application Insights integration
- Version management
- Automated deployment from source
A secure module for creating and managing Azure Storage accounts with best practices.
Key Features:
- Encryption at rest and in transit
- Access tier management
- Network access controls
- Comprehensive monitoring
- Automated lifecycle management
The main application component that:
- Serves form definitions from cloud storage or local storage
- Handles user authentication and sessions
- Processes form submissions
- Manages file uploads
Environment Variables (AWS):
COOKIE_SECRET: Session data encryptionSESSION_SECRET: Authentication session encryptionBUCKET_NAME: KFD files storage locationAUTH_CONFIG_FILE_NAME: Authentication configuration file name (default: "auth")BUCKET_NAME_FOR_FORM_FILES: S3 bucket name for storing files uploaded by usersBUCKET_REGION_FOR_FORM_FILES: AWS region where the file storage bucket is hostedUSE_LOCAL_SERVICES: Enable local development mode (default: false)LOG_LEVEL: Application logging level (default: info)PORT: Application port (default: 3000)CLOUD_PROVIDER: must be 'aws'FORM_SESSION_TABLE_NAME: Table name for storing user's form dataALLOWED_ORIGIN: Used for API endpoint CORS configuration
Environment Variables (Azure):
COOKIE_SECRET: Session data encryptionSESSION_SECRET: Authentication session encryptionAUTH_CONFIG_FILE_NAME: Authentication configuration file name (default: "auth")USE_LOCAL_SERVICES: Enable local development mode (default: false)LOG_LEVEL: Application logging level (default: info)PORT: Application port (default: 3000)CLOUD_PROVIDER: must be 'azure'AZURE_STORAGE_ACCOUNT: Azure Storage Account name for KFD filesAZURE_STORAGE_CONTAINER: Azure Storage Container name for KFD filesAZURE_STORAGE_ACCOUNT_FOR_FORM_FILES: Azure Storage Account name for storing files uploaded by usersAZURE_STORAGE_CONTAINER_FOR_FORM_FILES: Azure Storage Container name for storing files uploaded by usersAZURE_COSMOS_ENDPOINT: Azure Cosmos DB endpoint URLAZURE_COSMOS_DATABASE: Azure Cosmos DB database nameFORM_SESSION_TABLE_NAME: Table name for storing user's form dataALLOWED_ORIGIN: Used for API endpoint CORS configuration
Specialized function for handling KFD file uploads:
- Validates and processes form definition files
- Manages cloud storage upload operations
- Handles authentication for upload operations
Create a .env file in the respective function directories:
AWS Core Application (.env):
COOKIE_SECRET='your-cookie-secret'
SESSION_SECRET='your-session-secret'
CLOUD_PROVIDER='aws'
BUCKET_NAME='your-kfd-files-bucket'
AUTH_CONFIG_FILE_NAME='auth'
PORT=3000
USE_LOCAL_SERVICES='true'
LOG_LEVEL='debug'
BUCKET_NAME_FOR_FORM_FILES='your-form-files-bucket'
BUCKET_REGION_FOR_FORM_FILES='your-aws-region'
FORM_SESSION_TABLE_NAME='Core_FormSessions_dev'Azure Core Application (.env):
COOKIE_SECRET='your-cookie-secret'
SESSION_SECRET='your-session-secret'
AUTH_CONFIG_FILE_NAME='auth'
PORT=3000
USE_LOCAL_SERVICES='true'
LOG_LEVEL='debug'
CLOUD_PROVIDER='azure'
AZURE_STORAGE_ACCOUNT='your-storage-account'
AZURE_STORAGE_CONTAINER='kfd-files'
AZURE_STORAGE_ACCOUNT_FOR_FORM_FILES='your-form-files-storage-account'
AZURE_STORAGE_CONTAINER_FOR_FORM_FILES='submitted-forms'
AZURE_COSMOS_ENDPOINT='https://your-cosmosdb.documents.azure.com:443/'
AZURE_COSMOS_DATABASE='your-database-name'
FORM_SESSION_TABLE_NAME='FormSessions'This project uses GitHub Actions for CI/CD workflows. The workflows are defined in the .github/workflows/ directory and handle:
- Terraform plan, apply, and destroy operations for both providers
- Running pre-commit hooks and formatting checks
- Security scanning with Checkov
- Testing serverless functions
- Provider-specific deployment workflows
- Local: Uses
local.tsentry point, can load forms fromservicesfolder - AWS: Uses
lambda.tsentry point, loads forms from S3 buckets
- Local: Uses
local.tsentry point, can load forms fromservicesfolder - Azure: Uses
function.tsentry point, loads forms from Azure Storage
- Navigate to AWS S3 Console
- Open the production KFD files bucket
- Create or navigate to the appropriate folder
- Upload your KFD file
- Navigate to Azure Portal
- Open the production Storage Account
- Navigate to the appropriate container
- Upload your KFD file
- Encryption: All S3 buckets use KMS encryption
- Access Control: Public access blocked by default
- Logging: Comprehensive CloudWatch logging with retention policies
- IAM: Least-privilege access patterns
- Encryption: Storage accounts use customer-managed keys
- Access Control: Network access restrictions and Azure AD integration
- Logging: Azure Monitor and Application Insights integration
- RBAC: Role-based access control patterns
- Security Scanning: Automated Checkov security analysis for both providers
- Infrastructure as Code: Version-controlled security configurations
- Secrets Management: Environment-specific secret handling
All resources are tagged with:
Environment: dev/staging/prodOwner: TerraformProject: KainosStudioService: KainoscoreProvider: aws/azure
- CloudWatch Logs: Centralized logging for all Lambda functions
- CloudWatch Metrics: Custom metrics for application performance
- CloudWatch Alarms: Automated alerting for critical issues
- Azure Monitor: Centralized logging and monitoring
- Application Insights: Application performance monitoring
- Azure Alerts: Automated alerting for critical issues
- Retention: Configurable log retention periods
- Performance Metrics: Application and infrastructure monitoring
- Cost Optimization: Resource utilization tracking
This project uses:
- Pre-commit hooks: Automated code formatting and validation
- Terraform fmt: Code formatting for both providers
- Terraform validate: Configuration validation
- Checkov: Security and compliance scanning for both AWS and Azure
- Follow AWS Well-Architected Framework principles
- Use AWS-native services where possible
- Ensure compatibility with existing Lambda functions
- Follow Azure Well-Architected Framework principles
- Use Azure-native services where possible
- Ensure compatibility with existing Function Apps
- Azure Deployment Summary: Overview of current vs planned Azure architecture
- Azure CDN Deployment Architecture: Detailed CDN routing and architecture documentation
- Testing Guide: Comprehensive testing procedures for Azure infrastructure
- CDN Architecture Analysis: Original architecture analysis and recommendations
- Security Best Practices: Security guidelines for both AWS and Azure
- Makefile Usage: Detailed guide for using project Makefiles
- Unified Domain Architecture: Cross-cloud domain architecture strategies
- Terraform Documentation
- AWS Resources:
- Azure Resources:
This project is licensed under the terms of the license file included in this repository. Please see the LICENSE file for more information.
We welcome contributions to Kainos Core Infra! Please read our contributing guide for details on our code of conduct and the process for submitting pull requests.
Note: This README is subject to changes as the project evolves. Please check back regularly for updates and new features.
Last Updated: August 2025