arehmandev / terraform-google-cloud-sql-saver

Terraform module to simplify cost savings of Cloud SQL instances on GCP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

terraform-google-cloud-sql-saver

Terraform module to simplify cost savings of Cloud SQL instances on GCP.

View on Terraform Registry

Purpose

This module is intended to reduce the cost of using GCP's Cloud SQL service by scheduling your instances to start and stop. This is a practice that would typically be implemented in a non-production environment. Running your instances in this manner can save you ~75% of the cost to run an instance per week. The cost savings estimate assumes an instance running 9 hours a day, 5 days a week compared to 24/7.

Note: Backups can only be performed while an instance is running so the backup window needs to be adjusted accordingly.

Inspired by a blog post from Google, the module was developed with reusability in mind by leveraging Terraform. It also goes a step beyond that of the blog post to handle:

  • Multiple start/stop schedules
  • Multiple instances

Architecture

Cloud SQL Saver architecture

  1. Cloud Scheduler job sends start/stop message to Pub/Sub topic.
  2. Pub/Sub topic message publish event triggers the Cloud Function.
  3. Cloud Function sends start/stop API call to Cloud SQL instance(s).

Requirements

Usage

module "cloud-sql-saver" {
  source     = "mscribellito/cloud-sql-saver/google"
  project_id = "your-project-id"
  region     = "us-east1"
  jobs =  {
    "8am-5pm" = {
      start     = "0 8 * * 1-5"
      stop      = "0 17 * * 1-5"
      instances = ["acme-db"]
      time_zone = null
    }
  }
  create_app_engine = false # set to false if an App Engine application is already created in your project
}

Inputs

Name Description Type Default Required
project_id The project ID to manage the resources. string n/a yes
region The region of the resources. string "us-east1" no
jobs Mao of start/stop jobs. Map {} no
time_zone Default time zone name from the tz database for scheduled jobs. string "America/New_York" no
create_app_engine Whether App Engine application should be created. bool true no
gcp_services List of GCP Services to enable. list(string) Check variables.tf no

Outputs

N/A

Changelog

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

About

Terraform module to simplify cost savings of Cloud SQL instances on GCP.

License:MIT License


Languages

Language:HCL 72.5%Language:Go 27.5%