Skip to content

Commit

Permalink
Updated terraform configuration to initialize empty input and ouput d…
Browse files Browse the repository at this point in the history
…irectories (datacommonsorg#4843)

New variables:

```
gcs_data_bucket_output_folder = "output"
gcs_data_bucket_input_folder = "input"
```

Renamed `dc_gcs_data_bucket_path_override` to `gcs_data_bucket_name`
Renamed `dc_gcs_data_bucket_location` to `gcs_data_bucket_location`
  • Loading branch information
dwnoble authored Jan 17, 2025
1 parent f52e8b8 commit 1359256
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions deploy/terraform-custom-datacommons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Once the deployment is complete, terraform should output something like:
cloud_run_service_name = "<namespace>-datacommons-web-service"
cloud_run_service_url = "https://<namespace>-datacommons-web-service-abc123-uc.a.run.app"
dc_api_key = <sensitive>
dc_gcs_data_bucket_path = "<namespace>-datacommons-data-<project-id>"
gcs_data_bucket_name = "<namespace>-datacommons-data-<project-id>"
maps_api_key = <sensitive>
mysql_instance_connection_name = "<project-id>:us-central1:<namespace>-datacommons-mysql-instance"
mysql_instance_public_ip = "<mysql_ip>"
Expand All @@ -178,7 +178,7 @@ redis_instance_port = 6379

### 6. Load custom data

Upload custom sample data to the GCS bucket specified by the terraform output `dc_gcs_data_bucket_path` (`gs://<your-namespace>-datacommons-data-<your-project-id>`).
Upload custom sample data to the GCS bucket specified by the terraform output `gcs_data_bucket_name` (`gs://<your-namespace>-datacommons-data-<your-project-id>`).
From the `website` repository's root directory, run:

```
Expand Down
4 changes: 2 additions & 2 deletions deploy/terraform-custom-datacommons/modules/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

locals {
# Data Commons Data Bucket
dc_gcs_data_bucket_path = var.dc_gcs_data_bucket_path_override != "" ? var.dc_gcs_data_bucket_path_override : "${var.namespace}-datacommons-data-${var.project_id}"
gcs_data_bucket_name = var.gcs_data_bucket_name != "" ? var.gcs_data_bucket_name : "${var.namespace}-datacommons-data-${var.project_id}"
# VPC Connector CIDR block
vpc_connector_cidr = cidrsubnet(var.vpc_base_cidr_block, 4, 0) # Generates the first /28 subnet from the /24 block

Expand Down Expand Up @@ -56,7 +56,7 @@ locals {
},
{
name = "OUTPUT_DIR"
value = "gs://${local.dc_gcs_data_bucket_path}/output"
value = "gs://${local.gcs_data_bucket_name}/${var.gcs_data_bucket_output_folder}"
},
{
name = "FORCE_RESTART"
Expand Down
22 changes: 18 additions & 4 deletions deploy/terraform-custom-datacommons/modules/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,26 @@ resource "google_sql_user" "mysql_user" {
}

# Data commons storage bucket
resource "google_storage_bucket" "dc_gcs_data_bucket" {
name = local.dc_gcs_data_bucket_path
location = var.dc_gcs_data_bucket_location
resource "google_storage_bucket" "gcs_data_bucket" {
name = local.gcs_data_bucket_name
location = var.gcs_data_bucket_location
uniform_bucket_level_access = true
}

# Input 'folder' for the data loading job.
resource "google_storage_bucket_object" "gcs_data_bucket_input_folder" {
name = "${var.gcs_data_bucket_input_folder}/"
content = "Input folder"
bucket = "${google_storage_bucket.gcs_data_bucket.name}"
}

# Output 'folder' for the data loading job.
resource "google_storage_bucket_object" "gcs_data_bucket_output_folder" {
name = "${var.gcs_data_bucket_output_folder}/"
content = "Output folder"
bucket = "${google_storage_bucket.gcs_data_bucket.name}"
}

# Generate a random suffix to append to api keys.
# A deleted API key fully expires 30 days after deletion, and in the 30-day
# window the ID remains taken. This suffix allows terraform to give API
Expand Down Expand Up @@ -360,7 +374,7 @@ resource "google_cloud_run_v2_job" "dc_data_job" {

env {
name = "INPUT_DIR"
value = "gs://${local.dc_gcs_data_bucket_path}/input"
value = "gs://${local.gcs_data_bucket_name}/${var.gcs_data_bucket_input_folder}"
}
}
execution_environment = "EXECUTION_ENVIRONMENT_GEN2"
Expand Down
4 changes: 2 additions & 2 deletions deploy/terraform-custom-datacommons/modules/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ output "mysql_user_password" {
sensitive = true
}

output "dc_gcs_data_bucket_path" {
value = local.dc_gcs_data_bucket_path
output "gcs_data_bucket_name" {
value = local.gcs_data_bucket_name
}

output "cloud_run_service_name" {
Expand Down
18 changes: 15 additions & 3 deletions deploy/terraform-custom-datacommons/modules/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,25 @@ variable "google_analytics_tag_id" {
# Data Commons Cloud Storage bucket variables

# If not set, the default is <namespace>-datacommons-data-<project_id>
variable "dc_gcs_data_bucket_path_override" {
description = "Custom GCS data bucket path."
variable "gcs_data_bucket_name" {
description = "Custom GCS data bucket name."
type = string
default = ""
}

variable "dc_gcs_data_bucket_location" {
variable "gcs_data_bucket_input_folder" {
description = "Input data folder in the GCS data bucket"
type = string
default = "input"
}

variable "gcs_data_bucket_output_folder" {
description = "Output data folder in the GCS data bucket"
type = string
default = "output"
}

variable "gcs_data_bucket_location" {
description = "Data Commons GCS data bucket location"
type = string
default = "US"
Expand Down

0 comments on commit 1359256

Please sign in to comment.