Skip to content

padok-team/terraform-google-sql

Repository files navigation

SQL Terraform module

Terraform module which creates SQL resources, secrets and backups on GCP. This module uses the sql-db module by GoogleCloudPlatform.

User Stories for this module

  • AASQL / POSTGRES INSTANCE I can be highly available or single zone
  • AASQL / POSTGRES INSTANCE I can be fully private or have a public ip
  • AASQL / POSTGRES INSTANCE I can have db users and store their passwords in secret manager
  • AASQL / POSTGRES INSTANCE I can have multiple dbs
  • AASQL / POSTGRES INSTANCE I can have custom exporter to schedule backups in a bucket
  • AASQL / POSTGRES INSTANCE I use can use custom managed keys to encrypt my disk
  • AASQL / POSTGRES INSTANCE I use execute a custom sql script on deployment

Usage

Databases

You can use either mysql or postgresql module to create databases instances in GCP. These modules optionnally include secrets module to create secrets in google secret manager with password values for each user.

SQL Exporter

This module creates a storage bucket and a cloud function to export database backups in buckets. In order to schedule backups on a regular basis, you need to create a cloud scheduler outside of the sql exporter module. In mysql and postgresql modules, you can optionnally enable and configure these schedulers for each databases.

⚠️ Althought we do not recommend creating different databases in the same instance, simultaneous backups for databases in the same instance. If you are in this situation, please be careful to schedule backups for your databases apart from each other to avoid failed backups.

Examples

Examples can be found in the examples folder. You might need to run terraform apply twice because of a race condition with the network. This would not be needed in normal configurations as the network would be created somewhere else.

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.