Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ uv run datacommons admin init

The command will prompt for:
- GCP project id
- namespace
- instance name
- Data Commons API key

It then creates a new folder with `main.tf`, `terraform.tfvars`, and a deployment `README.md`.
Expand Down
12 changes: 6 additions & 6 deletions infra/dcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cp terraform.tfvars.template terraform.tfvars

Edit `terraform.tfvars` and fill in at least the following required variables:
* `project_id`: Your GCP Project ID.
* `namespace`: A unique identifier for resource naming (e.g., your name or team name).
* `instance_name`: A unique identifier for resource naming (e.g., your name or team name).

### 2. Run the Setup Script

Expand Down Expand Up @@ -103,26 +103,26 @@ Upon successful apply, Terraform displays key endpoints and resource names:
After successful deployment with `deploy_ingestion_workflow = true`, you can run the automated ingestion pipeline.

### Step 1: Upload your Schema file
Upload your custom graph nodes file (`.mcf`) to the provisioned ingestion bucket. By default, the bucket name format is: `<namespace>-ingestion-bucket-<project_id>`.
Upload your custom graph nodes file (`.mcf`) to the provisioned ingestion bucket. By default, the bucket name format is: `<instance-name>-ingestion-bucket-<project_id>`.

```bash
gcloud storage cp path/to/your/sample.mcf gs://<namespace>-ingestion-bucket-<project_id>/imports/sample.mcf
gcloud storage cp path/to/your/sample.mcf gs://<instance-name>-ingestion-bucket-<project_id>/imports/sample.mcf
```

### Step 2: Trigger the Workflow Orchestrator
Trigger the Cloud Workflow to start the Dataflow job that will read the file and insert it into Spanner.

```bash
gcloud workflows run <namespace>-ingestion-orchestrator \
gcloud workflows run <instance-name>-ingestion-orchestrator \
--project=<project_id> \
--location=<region> \
--data='{
"templateLocation": "gs://datcom-templates/templates/flex/ingestion.json",
"region": "<region>",
"spannerInstanceId": "<spanner-instance-id>",
"spannerDatabaseId": "<spanner-database-id>",
"importList": "[{\"importName\": \"SampleTestCase\", \"graphPath\": \"gs://<namespace>-ingestion-bucket-<project_id>/imports/sample.mcf\"}]",
"tempLocation": "gs://<namespace>-ingestion-bucket-<project_id>/temp"
"importList": "[{\"importName\": \"SampleTestCase\", \"graphPath\": \"gs://<instance-name>-ingestion-bucket-<project_id>/imports/sample.mcf\"}]",
"tempLocation": "gs://<instance-name>-ingestion-bucket-<project_id>/temp"
}'
```

Expand Down
5 changes: 4 additions & 1 deletion infra/dcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ resource "google_project_service" "apis" {
}

locals {
# For backward compatibility, fallback to namespace if instance_name is empty
effective_instance_name = var.instance_name != "" ? var.instance_name : var.namespace

# Redirect abandoned 'latest' alias to 'stable' for Dataflow templates
df_template_version = var.dcp_version == "latest" ? "stable" : var.dcp_version

global_config = {
project_id = var.project_id
region = var.region
namespace = var.namespace
instance_name = local.effective_instance_name
stateful_deletion_protection = var.stateful_deletion_protection
stateless_deletion_protection = var.stateless_deletion_protection
}
Expand Down
4 changes: 2 additions & 2 deletions infra/dcp/modules/auth/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
google_maps_api_key_value = var.google_maps_api_key != null ? var.google_maps_api_key : try(google_apikeys_key.maps_api_key[0].key_string, "")
}

Expand All @@ -24,7 +24,7 @@ resource "google_apikeys_key" "maps_api_key" {
count = var.google_maps_api_key == null && var.create_google_maps_key ? 1 : 0

name = "${local.name_prefix}dc-google-maps-key-${random_id.api_key_suffix.hex}"
display_name = "Maps API Key for ${var.namespace != "" ? var.namespace : "Data Commons"}"
display_name = "Maps API Key for ${var.instance_name != "" ? var.instance_name : "Data Commons"}"
project = var.project_id

restrictions {
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/auth/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ variable "project_id" {
type = string
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/datacommons_services/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
}

resource "google_service_account" "serving_sa" {
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/datacommons_services/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ variable "project_id" {
type = string
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
4 changes: 2 additions & 2 deletions infra/dcp/modules/ingestion/dataflow/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
display_name_prefix = var.namespace != "" ? "(${var.namespace}) " : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
display_name_prefix = var.instance_name != "" ? "(${var.instance_name}) " : ""
}

resource "google_service_account" "dataflow_sa" {
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/dataflow/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "project_id" {
type = string
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/helper_service/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
}

resource "google_service_account" "helper_sa" {
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/helper_service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "project_id" {
type = string
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/postprocessing_job/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
}

resource "google_service_account" "postprocessing_sa" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "project_id" { type = string }
variable "namespace" { type = string }
variable "instance_name" { type = string }
variable "region" { type = string }
variable "stateless_deletion_protection" {
type = bool
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/preprocessing_job/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
}

resource "google_service_account" "preprocessing_sa" {
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/ingestion/preprocessing_job/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "project_id" { type = string }
variable "namespace" { type = string }
variable "instance_name" { type = string }
variable "region" { type = string }
variable "stateless_deletion_protection" {
type = bool
Expand Down
6 changes: 4 additions & 2 deletions infra/dcp/modules/ingestion/workflow/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
should_run_postprocessing = var.enable_bigquery_postprocessing || var.enable_embeddings_generation
clean_namespace_prefix = var.namespace != "" ? "${replace(lower(var.namespace), "_", "-")}-" : ""
clean_namespace_prefix = var.instance_name != "" ? "${replace(lower(var.instance_name), "_", "-")}-" : ""
}

resource "google_service_account" "workflow_sa" {
Expand Down Expand Up @@ -31,6 +31,8 @@ resource "google_workflows_workflow" "ingestion_orchestrator" {
dataflow_subnetwork = var.dataflow_subnetwork
embeddings_timeout = var.embeddings_timeout
clean_namespace_prefix = local.clean_namespace_prefix


enable_redis_cache_clearing = var.enable_redis_cache_clearing
preprocessing_job_name = var.preprocessing_job_name
postprocessing_job_name = var.postprocessing_job_name
Expand Down
4 changes: 3 additions & 1 deletion infra/dcp/modules/ingestion/workflow/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ variable "deploy" {
type = bool
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down Expand Up @@ -47,6 +47,8 @@ variable "embeddings_timeout" {
default = 1800
}



variable "ingestion_helper_service_name" {
type = string
description = "Name of the ingestion helper Cloud Run service"
Expand Down
6 changes: 3 additions & 3 deletions infra/dcp/modules/redis/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
display_name_prefix = var.namespace != "" ? "(${var.namespace}) " : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
display_name_prefix = var.instance_name != "" ? "(${var.instance_name}) " : ""
}

resource "google_redis_instance" "redis_instance" {
name = var.instance_name != "" ? "${local.name_prefix}${var.instance_name}" : "${local.name_prefix}dc-redis-instance"
name = var.redis_instance_name != "" ? "${local.name_prefix}${var.redis_instance_name}" : "${local.name_prefix}dc-redis-instance"
memory_size_gb = var.memory_size_gb
tier = var.tier
region = var.region
Expand Down
4 changes: 2 additions & 2 deletions infra/dcp/modules/redis/variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
variable "namespace" {
variable "instance_name" {
type = string
}

variable "region" {
type = string
}

variable "instance_name" {
variable "redis_instance_name" {
type = string
default = ""
}
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/spanner/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
effective_instance_id = var.create_instance ? (var.instance_id != "" ? "${local.name_prefix}${var.instance_id}" : "${local.name_prefix}dc-instance") : var.instance_id
effective_database_id = var.create_database ? (var.database_id != "" ? "${local.name_prefix}${var.database_id}" : "${local.name_prefix}dc-db") : var.database_id
}
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/spanner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "project_id" {
description = "GCP Project ID"
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
27 changes: 14 additions & 13 deletions infra/dcp/modules/stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module "spanner" {
count = var.spanner_config.enable ? 1 : 0

project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
create_instance = var.spanner_config.create_instance
create_database = var.spanner_config.create_db
Expand All @@ -106,16 +106,16 @@ module "storage" {
stateful_deletion_protection = var.global.stateful_deletion_protection

# Shared vars
project_id = var.global.project_id
namespace = var.global.namespace
project_id = var.global.project_id
instance_name = var.global.instance_name
}

module "ingestion_preprocessing_job" {
source = "../ingestion/preprocessing_job"
count = var.ingestion_config.enable_ingestion ? 1 : 0

project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
stateless_deletion_protection = var.global.stateless_deletion_protection
image = var.ingestion_config.preprocessing_job_image
Expand Down Expand Up @@ -149,7 +149,7 @@ module "ingestion_postprocessing_job" {
count = var.ingestion_config.enable_ingestion ? 1 : 0

project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
stateless_deletion_protection = var.global.stateless_deletion_protection
image = var.ingestion_config.postprocessing_job_image
Expand All @@ -171,7 +171,7 @@ module "ingestion_dataflow" {

deploy = var.ingestion_config.enable_ingestion
project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
ingestion_bucket_name = module.storage.artifacts_bucket_name
use_spanner = var.spanner_config.enable
}
Expand All @@ -181,7 +181,7 @@ module "ingestion_helper_service" {

deploy = var.ingestion_config.enable_ingestion
project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
stateless_deletion_protection = var.global.stateless_deletion_protection
# Use index [0] because module.spanner is conditional. Fallback to empty string if disabled.
Expand All @@ -207,7 +207,7 @@ module "ingestion_workflow" {
source = "../ingestion/workflow"

deploy = var.ingestion_config.enable_ingestion
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
stateless_deletion_protection = var.global.stateless_deletion_protection
project_id = var.global.project_id
Expand All @@ -216,7 +216,7 @@ module "ingestion_workflow" {
dataflow_service_account_email = module.ingestion_dataflow.service_account_email
enable_bigquery_postprocessing = var.ingestion_config.workflow_enable_bigquery_postprocessing
enable_embeddings_generation = var.spanner_config.enable_embeddings_generation
ingestion_helper_service_name = "${var.global.namespace != "" ? "${var.global.namespace}-" : ""}dc-ingestion-helper"
ingestion_helper_service_name = "${var.global.instance_name != "" ? "${var.global.instance_name}-" : ""}dc-ingestion-helper"
enable_redis_cache_clearing = var.redis_config.enable
ingestion_artifacts_path = "${var.ingestion_config.ingestion_artifacts_path}/metadata"
dataflow_ip_configuration = var.ingestion_config.dataflow_ip_configuration
Expand All @@ -228,13 +228,14 @@ module "ingestion_workflow" {
depends_on = [module.ingestion_helper_service]
}


module "redis" {
source = "../redis"
count = var.redis_config.enable ? 1 : 0

namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
instance_name = var.redis_config.instance_name
redis_instance_name = var.redis_config.instance_name
memory_size_gb = var.redis_config.memory_size_gb
tier = var.redis_config.tier
location_id = var.redis_config.location_id
Expand All @@ -249,7 +250,7 @@ module "auth" {
source = "../auth"

project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
dc_api_key = var.auth_config.google_datacommons_api_key
google_maps_api_key = var.auth_config.google_maps_api_key
create_google_maps_key = var.auth_config.create_google_maps_key
Expand All @@ -260,7 +261,7 @@ module "datacommons_services" {
count = var.datacommons_services_config.enable ? 1 : 0

project_id = var.global.project_id
namespace = var.global.namespace
instance_name = var.global.instance_name
region = var.global.region
stateless_deletion_protection = var.global.stateless_deletion_protection
image = var.datacommons_services_config.image
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/stack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ variable "global" {
type = object({
project_id = string
region = string
namespace = string
instance_name = string
stateful_deletion_protection = bool
stateless_deletion_protection = bool
})
Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/storage/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
name_prefix = var.namespace != "" ? "${var.namespace}-" : ""
name_prefix = var.instance_name != "" ? "${var.instance_name}-" : ""
artifacts_bucket_name = var.artifacts_bucket_name != "" ? var.artifacts_bucket_name : "${local.name_prefix}dc-artifacts-${var.project_id}"
}

Expand Down
2 changes: 1 addition & 1 deletion infra/dcp/modules/storage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ variable "project_id" {
type = string
}

variable "namespace" {
variable "instance_name" {
type = string
}

Expand Down
6 changes: 3 additions & 3 deletions infra/dcp/terraform.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# =============================================================================
# Global Configuration
# =============================================================================
project_id = "$$PROJECT_ID$$"
namespace = "$$NAMESPACE$$"
region = "us-central1"
project_id = "$$PROJECT_ID$$"
instance_name = "$$INSTANCE_NAME$$"
region = "us-central1"

# Deletion protection for stateful resources holding persistent data
# (Spanner and Cloud Storage).
Expand Down
Loading
Loading