Skip to content

Commit

Permalink
feat: include log for each database name in export workflow (#407)
Browse files Browse the repository at this point in the history
Co-authored-by: g-awmalik <malik.awais@gmail.com>
  • Loading branch information
Carlos Mondo and g-awmalik authored May 1, 2023
1 parent fc76048 commit e638a24
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fetch workflows.googleapis.com/Workflow
| export\_databases | The list of databases that should be exported - if is an empty set all databases will be exported | `set(string)` | `[]` | no |
| export\_schedule | The cron schedule to execute the export to GCS | `string` | `"15 3 * * *"` | no |
| export\_uri | The bucket and path uri for exporting to GCS | `string` | n/a | yes |
| log\_db\_name\_to\_export | Whether or not to log database name in the export workflow | `bool` | `false` | no |
| project\_id | The project ID | `string` | n/a | yes |
| region | The region where to run the workflow | `string` | `"us-central1"` | no |
| scheduler\_timezone | The Timezone in which the Scheduler Jobs are triggered | `string` | `"Etc/GMT"` | no |
Expand Down
1 change: 1 addition & 0 deletions modules/backup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ resource "google_workflows_workflow" "sql_export" {
gcsBucket = var.export_uri
dbType = split("_", data.google_sql_database_instance.backup_instance.database_version)[0]
compressExport = var.compress_export
logDbName = var.log_db_name_to_export
})
}

Expand Down
12 changes: 12 additions & 0 deletions modules/backup/templates/export.yaml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ main:
value: database
in: $${databases}
steps:
%{ if logDbName }
- log:
call: sys.log
args:
data: $${"Starting backup from database " + database}
%{ endif }
- export database:
call: googleapis.sqladmin.v1.instances.export
args:
Expand All @@ -60,6 +66,12 @@ main:
value: database
in: $${databases}
steps:
%{ if logDbName }
- log:
call: sys.log
args:
data: $${"Starting backup from database " + database}
%{ endif }
- exclude System DB:
switch:
- condition: $${database != "tempdb" } #tempdb has to be excluded in an export
Expand Down
6 changes: 6 additions & 0 deletions modules/backup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ variable "unique_suffix" {
type = string
default = ""
}

variable "log_db_name_to_export" {
description = "Whether or not to log database name in the export workflow"
type = bool
default = false
}

0 comments on commit e638a24

Please sign in to comment.