Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added cloudsql serverless_export #530

Merged
merged 13 commits into from
Nov 9, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This example shows how to create:
- a PostgreSQL Cloud SQL Instance
- A GCS Bucket for storing the Backup
- The Workflows for exports (external backups) and (internal) backups
- The Workflows with serverless export

## Run Terraform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module "backup" {
backup_retention_time = 1
backup_schedule = "5 * * * *"
export_schedule = "10 * * * *"
use_serverless_export = true
service_account = "${data.google_project.test_project.number}-compute@developer.gserviceaccount.com"
}

Expand Down
1 change: 1 addition & 0 deletions modules/backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fetch workflows.googleapis.com/Workflow
| sql\_instance | The name of the SQL instance to backup | `string` | n/a | yes |
| sql\_instance\_replica | The name of the SQL instance replica to export | `string` | `null` | no |
| unique\_suffix | Unique suffix to add to scheduler jobs and workflows names. | `string` | `""` | no |
| use\_serverless\_export | Whether to use serverless export for DB export | `bool` | `false` | no |
| use\_sql\_instance\_replica\_in\_exporter | Whether or not to use replica instance on exporter workflow. | `bool` | `false` | no |

## Outputs
Expand Down
1 change: 1 addition & 0 deletions modules/backup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ resource "google_workflows_workflow" "sql_export" {
enableConnectorParams = var.enable_connector_params
connectorParamsTimeout = var.connector_params_timeout
logDbName = var.log_db_name_to_export
serverlessExport = var.use_serverless_export
})
}

Expand Down
4 changes: 4 additions & 0 deletions modules/backup/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ spec:
description: Unique suffix to add to scheduler jobs and workflows names.
type: string
default: ""
- name: use_serverless_export
description: Whether to use serverless export for DB export
type: bool
default: false
outputs:
- name: backup_workflow_name
description: The name for internal backup workflow
Expand Down
2 changes: 2 additions & 0 deletions modules/backup/templates/export.yaml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ main:
body:
exportContext:
databases: [$${database}]
offload: "${serverlessExport}"
uri: $${"${gcsBucket}/${instanceName}-" + database + "-" + backupTime + %{ if compressExport == true }".sql.gz"%{ else }".sql"%{ endif }}
%{ endif }

Expand Down Expand Up @@ -109,5 +110,6 @@ main:
body:
exportContext:
databases: $${databases}
offload: "${serverlessExport}"
uri: $${"${gcsBucket}/${instanceName}-" + backupTime + %{ if compressExport == true }".sql.gz"%{ else }".sql"%{ endif }}
%{ endif }
6 changes: 6 additions & 0 deletions modules/backup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ variable "sql_instance_replica" {
type = string
default = null
}

variable "use_serverless_export" {
description = "Whether to use serverless export for DB export"
type = bool
default = false
}