Skip to content

Commit 8fbf8ac

Browse files
committed
Add cloud storage terraform
1 parent ddc267a commit 8fbf8ac

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

mithril-infra/assets/docker/docker-compose-aggregator.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ services:
5252
- RUN_INTERVAL=60000
5353
- URL_SNAPSHOT_MANIFEST=https://storage.googleapis.com/${SNAPSHOT_BUCKET_NAME}/snapshots.json
5454
- SNAPSHOT_STORE_TYPE=local
55-
- SNAPSHOT_UPLOADER_TYPE=local
55+
- SNAPSHOT_UPLOADER_TYPE=gcp
56+
- SNAPSHOT_BUCKET_NAME=${SNAPSHOT_BUCKET_NAME}
5657
- DATA_STORES_DIRECTORY=/mithril-aggregator/mithril/stores
5758
- STORE_RETENTION_LIMIT=5
5859
- CARDANO_NODE_SOCKET_PATH=/ipc/node.socket
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
resource "google_storage_bucket" "cloud_storage" {
2+
name = "${local.environment_name}-cs"
3+
location = var.google_region
4+
force_destroy = true
5+
6+
lifecycle_rule {
7+
condition {
8+
age = var.google_storage_bucket_max_age
9+
}
10+
action {
11+
type = "Delete"
12+
}
13+
}
14+
}
15+
16+
resource "google_service_account" "cloud_storage" {
17+
account_id = "${local.environment_name}-cs-sa"
18+
display_name = "${local.environment_name}-cs-sa"
19+
description = "${local.environment_name} cloud storage service account"
20+
}
21+
22+
resource "google_service_account_key" "cloud_storage" {
23+
service_account_id = google_service_account.cloud_storage.name
24+
public_key_type = "TYPE_X509_PEM_FILE"
25+
}
26+
27+
locals {
28+
google_cloud_storage_credentials_json = base64decode(google_service_account_key.cloud_storage.private_key)
29+
}
30+
31+
resource "google_storage_bucket_iam_member" "cloud_storage_viewer" {
32+
bucket = google_storage_bucket.cloud_storage.name
33+
role = "roles/storage.objectViewer"
34+
member = "serviceAccount:${google_service_account.cloud_storage.email}"
35+
}
36+
37+
resource "google_storage_bucket_iam_member" "cloud_storage_creator" {
38+
bucket = google_storage_bucket.cloud_storage.name
39+
role = "roles/storage.objectCreator"
40+
member = "serviceAccount:${google_service_account.cloud_storage.email}"
41+
}
42+
43+
resource "google_storage_bucket_iam_member" "legacy_bucket_writer" {
44+
bucket = google_storage_bucket.cloud_storage.name
45+
role = "roles/storage.legacyBucketWriter"
46+
member = "serviceAccount:${google_service_account.cloud_storage.email}"
47+
}

mithril-infra/mithril.aggregator.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ resource "null_resource" "mithril_aggregator" {
3030
"export NETWORK=${var.cardano_network}",
3131
"export IMAGE_ID=${var.mithril_image_id}",
3232
"export AGGREGATOR_HOST=${local.mithril_aggregator_host}",
33-
"export GOOGLE_APPLICATION_CREDENTIALS_JSON='${var.google_application_credentials_json}'",
33+
"export GOOGLE_APPLICATION_CREDENTIALS_JSON='${local.google_cloud_storage_credentials_json}'",
34+
"export SNAPSHOT_BUCKET_NAME='${google_storage_bucket.cloud_storage.name}'",
3435
"export GENESIS_VERIFICATION_KEY=$(wget -q -O - ${var.mithril_genesis_verification_key_url})",
3536
"export GENESIS_SECRET_KEY='${var.mithril_genesis_secret_key}'",
3637
"export CURRENT_UID=$(id -u)",

mithril-infra/output.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ output "aggregator_endpoint" {
66
value = local.mithril_aggregator_endpoint_url
77
}
88

9+
output "storage_bucket" {
10+
value = google_storage_bucket.cloud_storage.name
11+
}
12+
913
output "external-ip" {
1014
value = google_compute_address.mithril-external-address.address
1115
}

mithril-infra/variables.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ variable "google_service_credentials_json" {
3838
description = "The credentials of the GCP service account"
3939
}
4040

41-
variable "google_application_credentials_json" {
42-
type = string
43-
description = "Service account JSON key file used by aggregator to upload files to gcloud storage"
41+
variable "google_storage_bucket_max_age" {
42+
type = number
43+
description = "Number of days after which an object in the storage bucket expires"
44+
default = 14
4445
}
4546

4647
locals {

0 commit comments

Comments
 (0)