Skip to content

Commit e2dd3b4

Browse files
committed
setup VM and networking for mlflow on GCP
1 parent 4263f27 commit e2dd3b4

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

src/make_infra/main.tf

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ provider "google" {
1313
region = var.region
1414
}
1515

16-
resource "google_storage_bucket" "mlflow-101-raw-data" {
16+
resource "google_storage_bucket" "mlops-101-raw-data" {
1717
name = var.gcs_raw_taxi_data_bucket_name
1818
location = var.location
1919

@@ -36,7 +36,7 @@ resource "google_storage_bucket" "mlflow-101-raw-data" {
3636
force_destroy = true
3737
}
3838

39-
resource "google_storage_bucket" "mlflow-101-processed-data" {
39+
resource "google_storage_bucket" "mlops-101-processed-data" {
4040
name = var.gcs_processed_taxi_data_bucket_name
4141
location = var.location
4242

@@ -58,3 +58,71 @@ resource "google_storage_bucket" "mlflow-101-processed-data" {
5858

5959
force_destroy = true
6060
}
61+
62+
resource "google_storage_bucket" "mlops_101_mlflow_artifacts" {
63+
name = var.mlops_101_mlflow_artifacts
64+
location = var.location
65+
66+
storage_class = var.gcs_storage_class
67+
uniform_bucket_level_access = true
68+
69+
versioning {
70+
enabled = true
71+
}
72+
73+
lifecycle_rule {
74+
action {
75+
type = "Delete"
76+
}
77+
condition {
78+
age = 30 // days
79+
}
80+
}
81+
82+
force_destroy = true
83+
}
84+
85+
resource "google_compute_instance" "mlops-101-mlflow-server" {
86+
name = "mlops-101-mlflow-server"
87+
machine_type = "e2-small"
88+
zone = var.region
89+
90+
boot_disk {
91+
initialize_params {
92+
image = "projects/ml-images/global/images/c0-deeplearning-common-cpu-v20240613-debian-11"
93+
}
94+
}
95+
96+
network_interface {
97+
network = "default"
98+
access_config {
99+
// Ephemeral IP
100+
}
101+
}
102+
103+
tags = ["mlflow"]
104+
105+
metadata_startup_script = <<-EOT
106+
#!/bin/bash
107+
echo "Startup script running..." >> /var/log/startup-script.log 2>&1
108+
apt-get update >> /var/log/startup-script.log 2>&1
109+
apt-get install -y python3-pip >> /var/log/startup-script.log 2>&1
110+
pip3 install mlflow==2.20.1 >> /var/log/startup-script.log 2>&1
111+
mlflow server -h 0.0.0.0 -p 5000 --backend-store-uri ${var.mlflow_backend_store_uri} --default-artifact-root ${var.mlflow_artifact_location} >> /var/log/startup-script.log 2>&1
112+
echo "MLflow server started" >> /var/log/startup-script.log 2>&1
113+
EOT
114+
}
115+
116+
resource "google_compute_firewall" "mlflow-server-firewall" {
117+
name = "mlflow-server-firewall"
118+
network = "default"
119+
direction = "INGRESS"
120+
121+
allow {
122+
protocol = "tcp"
123+
ports = ["5000"]
124+
}
125+
126+
target_tags = ["mlflow"]
127+
source_ranges = [ "0.0.0.0/0" ]
128+
}

src/make_infra/variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,18 @@ variable "gcs_storage_class" {
3131
description = "Bucket Storage Class"
3232
default = "STANDARD"
3333
}
34+
35+
variable "mlops_101_mlflow_artifacts" {
36+
description = "Bucket name for MLflow artifacts"
37+
default = "mlops_101_mlflow_artifacts"
38+
}
39+
40+
variable "mlflow_backend_store_uri" {
41+
description = "MLflow Backend Store URI"
42+
default = "sqlite:///mlops_101.sqlite"
43+
}
44+
45+
variable "mlflow_artifact_location" {
46+
description = "MLflow Artifact Location"
47+
default = "gs://mlops_101_mlflow_artifacts"
48+
}

0 commit comments

Comments
 (0)