Skip to content

Commit d564270

Browse files
Android Build Filesystem (ABFS) Teamsce-taid
authored andcommitted
feat: optional table creation through IaC
PiperOrigin-RevId: 785444189
1 parent 3762731 commit d564270

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

examples/simple/main.tf

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ moved {
2323
}
2424

2525
module "abfs_server" {
26-
source = "github.com/terraform-google-modules/terraform-google-abfs//modules/server?ref=v0.7.0"
26+
source = "github.com/terraform-google-modules/terraform-google-abfs//modules/server?ref=v0.7.1"
2727

28-
project_id = data.google_project.project.project_id
29-
zone = var.zone
30-
service_account_email = data.google_service_account.abfs.email
31-
subnetwork = module.abfs-vpc.subnets["${var.region}/abfs-subnet"].name
32-
abfs_docker_image_uri = var.abfs_docker_image_uri
33-
abfs_license = var.abfs_license
34-
abfs_bucket_location = var.abfs_bucket_location
35-
abfs_server_machine_type = var.abfs_server_machine_type
36-
abfs_spanner_instance_config = var.abfs_spanner_instance_config
28+
project_id = data.google_project.project.project_id
29+
zone = var.zone
30+
service_account_email = data.google_service_account.abfs.email
31+
subnetwork = module.abfs-vpc.subnets["${var.region}/abfs-subnet"].name
32+
abfs_docker_image_uri = var.abfs_docker_image_uri
33+
abfs_license = var.abfs_license
34+
abfs_bucket_location = var.abfs_bucket_location
35+
abfs_server_machine_type = var.abfs_server_machine_type
36+
abfs_spanner_instance_config = var.abfs_spanner_instance_config
37+
abfs_spanner_database_create_tables = var.abfs_spanner_database_create_tables
3738
}
3839

3940
module "abfs_uploaders" {
40-
source = "github.com/terraform-google-modules/terraform-google-abfs//modules/uploaders?ref=v0.7.0"
41+
source = "github.com/terraform-google-modules/terraform-google-abfs//modules/uploaders?ref=v0.7.1"
4142

4243
project_id = data.google_project.project.project_id
4344
zone = var.zone

examples/simple/outputs.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,15 @@ output "license_information" {
2323

2424
output "spanner_database_schema_creation" {
2525
description = "The CLI command for creating the Spanner database schema"
26-
value = "SCHEMA_FILE=0.0.31-schema.sql; curl -O https://raw.githubusercontent.com/terraform-google-modules/terraform-google-abfs/refs/heads/main/files/schemas/$SCHEMA_FILE; gcloud --project ${data.google_project.project.project_id} spanner databases ddl update --instance ${module.abfs_server.abfs_spanner_instance.name} ${module.abfs_server.abfs_spanner_database.name} --ddl-file $SCHEMA_FILE; rm $SCHEMA_FILE"
26+
value = var.abfs_spanner_database_create_tables ? (
27+
"# The abfs_spanner_database_create_tables variable was set to true; no further action required."
28+
) : (
29+
join(" ", [
30+
"gcloud --project ${data.google_project.project.project_id}",
31+
"spanner databases ddl update",
32+
"--instance ${module.abfs_server.abfs_spanner_instance.name}",
33+
"${module.abfs_server.abfs_spanner_database.name}",
34+
"--ddl-file ${module.abfs_server.abfs_spanner_database_schema_file}",
35+
])
36+
)
2737
}

examples/simple/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ variable "abfs_spanner_instance_config" {
105105
description = "The name of the instance's configuration (similar but not quite the same as a region) which defines the geographic placement and replication of your ABFS database in this instance (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/spanner_instance.html#config-1)."
106106
}
107107

108+
variable "abfs_spanner_database_create_tables" {
109+
type = bool
110+
description = "Creates the tables in the database."
111+
default = false
112+
}
113+
108114
variable "abfs_enable_git_lfs" {
109115
type = bool
110116
description = "Enable Git LFS support"

modules/server/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ output "abfs_spanner_database" {
2626
description = "The ABFS Spanner database object"
2727
value = google_spanner_database.abfs
2828
}
29+
30+
output "abfs_spanner_database_schema_version" {
31+
description = "The schema version used for the ABFS Spanner database"
32+
value = var.abfs_spanner_database_schema_version
33+
}
34+
35+
output "abfs_spanner_database_schema_file" {
36+
description = "The ABFS Spanner database schema file"
37+
value = data.local_file.abfs_spanner_database_schema.filename
38+
}

modules/server/spanner.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ resource "google_spanner_instance" "abfs" {
3232
}
3333
}
3434

35+
data "local_file" "abfs_spanner_database_schema" {
36+
filename = "${path.module}/../../files/schemas/${var.abfs_spanner_database_schema_version}-schema.sql"
37+
}
38+
3539
resource "google_spanner_database" "abfs" {
3640
instance = google_spanner_instance.abfs.name
3741
name = var.abfs_spanner_database_name
42+
ddl = var.abfs_spanner_database_create_tables ? split(";;", data.local_file.abfs_spanner_database_schema.content) : []
3843
deletion_protection = true
44+
lifecycle {
45+
# Ignore changes after database creation to avoid accidental data loss.
46+
ignore_changes = [ddl]
47+
}
3948
}

modules/server/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ variable "abfs_spanner_database_name" {
126126
default = "abfs"
127127
}
128128

129+
variable "abfs_spanner_database_create_tables" {
130+
type = bool
131+
description = "Creates the tables in the database using the online DDL schema with the given schema version."
132+
default = false
133+
}
134+
135+
variable "abfs_spanner_database_schema_version" {
136+
type = string
137+
description = "The version of the DDL schema to use for the ABFS database."
138+
default = "0.0.31"
139+
}
140+
129141
// Marketplace requires this variable name to be declared
130142
variable "goog_cm_deployment_name" {
131143
type = string

0 commit comments

Comments
 (0)