This repository contains Terraform modules for automating common cloud operations tasks in Yandex Cloud using Cloud Functions and scheduled triggers.
| Function | Directory | Description | Use Case |
|---|---|---|---|
| Start VM Cron | 01-start-vm-cron |
Automatically starts specified virtual machines on a schedule | Start development/testing VMs every morning at 8:00 AM |
| Stop VM Cron | 02-stop-vm-cron |
Automatically stops specified virtual machines on a schedule | Stop development/testing VMs every evening at 8:00 PM to save costs |
| Scale Instance Groups | 03-scale-fixed-ig-cron |
Automatically scales Yandex Cloud Instance Groups up and down on schedule | Scale production workloads up during business hours and down during nights/weekends |
| Bucket Clean Up | 04-bucket-clean-up |
Automatically deletes objects from Object Storage buckets based on key prefix | Clean up temporary files, logs, or old backups on schedule |
| Auto Copy Bucket Objects | 05-auto-copy-bucket-objects |
Automatically copies objects between Object Storage buckets. Tutorial is also available. | Backup important data or sync buckets on schedule |
| ALB Logs to YDB | 06-alb-logging-to-ydb |
Automatically processes Cloud Logging messages from ALB and stores them in YDB for analysis. Tutorial for PostgreSQL is available | Store and analyze load balancer logs in a structured database |
| S3 Logs to YDB | 07-bucket-logs-to-ydb |
Automatically processes S3 bucket access logs and stores them in YDB for analysis | Store and analyze S3 bucket access patterns, monitor usage, and track requests in a structured database |
| Snapshots Clean Up | 08-snapshots-clean-up |
Automatically deletes old compute disk snapshots based on age | Clean up disk snapshots older than specified number of days to save storage costs |
-
Clone the repository:
git clone https://github.com/yandex-cloud-examples/yc-serverless-cloudops-automation.git cd yc-serverless-cloudops-automation -
Choose a scenario and navigate to its directory:
cd 01-start-vm-cron -
Copy and configure variables:
cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values -
Deploy with Terraform:
terraform init terraform plan terraform apply
-
Clean up when done:
terraform destroy
- Yandex Cloud CLI (yc) installed and configured
- Terraform
- Service account authorized key file for Yandex Cloud
Each scenario includes:
variables.tf- Input variablesterraform.tfvars.example- Example configurationmain.tf- Terraform resourcessrc/- Function source codeversions.tf- Provider requirements
All scenarios share this common provider configuration:
provider_key_file- Path to service account key filecloud_id- Yandex Cloud IDfolder_id- Yandex Cloud folder IDzone- Yandex Cloud availability zone (default:ru-central1-a)