Skip to content

Commit 9008e0b

Browse files
Android Build Filesystem (ABFS) Teamsce-taid
authored andcommitted
support SQL comments
PiperOrigin-RevId: 794468000
1 parent 60c3c83 commit 9008e0b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

modules/server/spanner.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ data "local_file" "abfs_spanner_database_schema" {
3636
filename = "${path.module}/../../files/schemas/${var.abfs_spanner_database_schema_version}-schema.sql"
3737
}
3838

39+
locals {
40+
# 1. Remove comment lines from the DDL content.
41+
cleaned_ddl = replace(data.local_file.abfs_spanner_database_schema.content, "(?m)^--.*\\R?", "")
42+
43+
# 2. Split the content into individual statements using the semicolon as a delimiter.
44+
statements = split(";", local.cleaned_ddl)
45+
46+
# 3. Trim whitespace from each statement and filter out any empty statements.
47+
spanner_ddl_statements = var.abfs_spanner_database_create_tables ? [for s in local.statements : trimspace(s) if length(trimspace(s)) > 0] : []
48+
}
49+
3950
resource "google_spanner_database" "abfs" {
4051
instance = google_spanner_instance.abfs.name
4152
name = var.abfs_spanner_database_name
42-
ddl = var.abfs_spanner_database_create_tables ? split(";;", data.local_file.abfs_spanner_database_schema.content) : []
53+
ddl = local.spanner_ddl_statements
4354
deletion_protection = true
4455
lifecycle {
4556
# Ignore changes after database creation to avoid accidental data loss.

0 commit comments

Comments
 (0)