{"id":21431928,"url":"https://github.com/mikaeelkhalid/gcp-instance-scheduler-terraform","last_synced_at":"2026-07-04T19:31:38.962Z","repository":{"id":193778717,"uuid":"689471534","full_name":"mikaeelkhalid/gcp-instance-scheduler-terraform","owner":"mikaeelkhalid","description":"This project contains Terraform configurations and a Cloud Function in Python to schedule the shutdown of GCP VM instances based on specific labels.","archived":false,"fork":false,"pushed_at":"2024-06-02T21:30:53.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T22:37:16.218Z","etag":null,"topics":["cloudfunctions","gcp","instance","scheduler","terraform"],"latest_commit_sha":null,"homepage":"https://blog.mikaeels.com/gcp-instance-scheduler-using-terraform","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikaeelkhalid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-09T23:11:02.000Z","updated_at":"2024-06-02T21:30:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4a34194-0e29-41e0-8579-35902020eccf","html_url":"https://github.com/mikaeelkhalid/gcp-instance-scheduler-terraform","commit_stats":null,"previous_names":["mikaeelkhalid/gcp-instance-scheduler-terraform"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mikaeelkhalid/gcp-instance-scheduler-terraform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaeelkhalid%2Fgcp-instance-scheduler-terraform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaeelkhalid%2Fgcp-instance-scheduler-terraform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaeelkhalid%2Fgcp-instance-scheduler-terraform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaeelkhalid%2Fgcp-instance-scheduler-terraform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikaeelkhalid","download_url":"https://codeload.github.com/mikaeelkhalid/gcp-instance-scheduler-terraform/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikaeelkhalid%2Fgcp-instance-scheduler-terraform/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281398043,"owners_count":26494075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudfunctions","gcp","instance","scheduler","terraform"],"created_at":"2024-11-22T23:15:30.538Z","updated_at":"2025-10-28T07:07:39.948Z","avatar_url":"https://github.com/mikaeelkhalid.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GCP Instance Scheduler using Terraform\n\n[![Mikaeel Khalid](https://badgen.now.sh/badge/by/mikaeelkhalid/purple)](https://github.com/mikaeelkhalid)\n\nThis project contains Terraform configurations and a Cloud Function in Python to schedule the shutdown of GCP VM instances based on specific labels.\n\nFor complete and detail explanations, please visit a blog [post](https://blog.mikaeels.com/gcp-instance-scheduler-using-terraform).\n\n## Overview\n\nThe system works by:\n\n1. A Cloud Scheduler job triggers a Cloud Function at specific times (set via a cron pattern).\n2. The Cloud Function uses the GCP Compute API to:\n   - List all zones in the project.\n   - For each zone, list all VM instances with a specific label.\n   - If the VM instance is running, it is shut down.\n\n## Files Structure\n\n- `gcp_function/main.py`: The Cloud Function script.\n- `gcp_function/requirements.txt`: The Cloud Function dependencies.\n- `main.tf`: Contains the main Terraform configurations for creating the necessary GCP resources.\n- `provider.tf`: Sets the GCP provider and region.\n- `variables.tf`: Defines the necessary variables for the Terraform configurations.\n- `README.md`: Documentation\n\n## Prerequisites\n\n1. Google Cloud SDK installed and authenticated.\n2. Terraform installed.\n\n## Setup\n\n1. Update the `variables.tf` with:\n\n   - Your GCP project ID.\n   - Your preferred cron pattern.\n   - Your preferred storage bucket name for the Cloud Function archive.\n   - Your preferred label key and value for targeted VM instances.\n\n2. Package the Cloud Function:\n\n   ```bash\n   cd gcp_function\n   zip -r function.zip *\n   ```\n\n3. Initialize Terraform and apply the configurations:\n\n   ```bash\n   terraform init\n   terraform apply\n   ```\n\n4. Make sure to allow the required permissions for the created service account in the GCP Console.\n\n## Usage\n\n1. VM instances you want to be managed by the scheduler should have the specified label (default: `instance-scheduler=enabled`).\n2. The Cloud Scheduler job will automatically trigger the Cloud Function based on the cron pattern you set.\n\n## Customize\n\nTo use a different label or time, update the values in `variables.tf`.\n\nFor cron, you can use this website: https://crontab.guru\n\n## Contributing\n\nFeel free to raise issues or pull requests if you'd like to improve the configurations or add more features.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaeelkhalid%2Fgcp-instance-scheduler-terraform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikaeelkhalid%2Fgcp-instance-scheduler-terraform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikaeelkhalid%2Fgcp-instance-scheduler-terraform/lists"}