Skip to content

Commit 69cb367

Browse files
committed
Add base terraform deployment
1 parent 50ee10b commit 69cb367

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed

mithril-infra/main.backend.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
terraform {
2+
backend "gcs" {
3+
4+
}
5+
}

mithril-infra/main.dns.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "google_dns_managed_zone" "mithril-api-zone" {
2+
name = "${local.environment_name}-dns"
3+
dns_name = "${local.environment_name_short}.${var.mithril_api_domain}."
4+
description = "DNS zone to manage Mithril API"
5+
visibility = "public"
6+
}
7+
8+
resource "google_dns_record_set" "mithril-aggregator-endpoint" {
9+
name = "aggregator.${google_dns_managed_zone.mithril-api-zone.dns_name}"
10+
managed_zone = google_dns_managed_zone.mithril-api-zone.name
11+
type = "A"
12+
ttl = 300
13+
rrdatas = [google_compute_address.mithril-external-address.address]
14+
}
15+
16+
locals {
17+
mithril_aggregator_host = trimsuffix(google_dns_record_set.mithril-aggregator-endpoint.name, ".")
18+
mithril_aggregator_endpoint_url = format("https://%s/aggregator", local.mithril_aggregator_host)
19+
}

mithril-infra/main.firewall.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "google_compute_firewall" "mithril-vm-firewall" {
2+
name = "${local.environment_name}-firewall"
3+
network = google_compute_network.vpc_network.id
4+
5+
allow {
6+
protocol = "tcp"
7+
ports = ["22", "80", "443"]
8+
}
9+
10+
source_ranges = ["0.0.0.0/0"]
11+
target_tags = [local.environment_name]
12+
}

mithril-infra/main.vm.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "hashicorp/google"
5+
version = "3.5.0"
6+
}
7+
}
8+
}
9+
10+
provider "google" {
11+
credentials = file(var.google_service_credentials_json)
12+
project = local.google_project_id
13+
region = var.google_region
14+
zone = var.google_zone
15+
}
16+
17+
resource "google_compute_network" "vpc_network" {
18+
name = "${local.environment_name}-network"
19+
}
20+
21+
resource "google_compute_instance" "vm_instance" {
22+
name = "${local.environment_name}-vm"
23+
machine_type = var.google_machine_type
24+
tags = ["mithril", local.environment_name, var.environment_prefix, var.cardano_network]
25+
26+
allow_stopping_for_update = true
27+
28+
metadata = {
29+
sshKeys = file("./assets/ssh_keys")
30+
}
31+
32+
metadata_startup_script = file("./assets/startup-vm.sh")
33+
34+
boot_disk {
35+
initialize_params {
36+
size = 200
37+
image = "ubuntu-os-cloud/ubuntu-2204-lts"
38+
}
39+
}
40+
41+
network_interface {
42+
network = google_compute_network.vpc_network.name
43+
access_config {
44+
nat_ip = google_compute_address.mithril-external-address.address
45+
}
46+
}
47+
}
48+
49+
resource "google_compute_address" "mithril-external-address" {
50+
name = "${local.environment_name}-ip"
51+
}
52+

mithril-infra/output.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "google_project" {
2+
value = local.google_project_id
3+
}
4+
5+
output "aggregator_endpoint" {
6+
value = local.mithril_aggregator_endpoint_url
7+
}
8+
9+
output "external-ip" {
10+
value = google_compute_address.mithril-external-address.address
11+
}
12+
13+
output "api_subdomain" {
14+
value = google_dns_managed_zone.mithril-api-zone.dns_name
15+
}
16+
17+
output "name_servers" {
18+
value = google_dns_managed_zone.mithril-api-zone.name_servers
19+
}

mithril-infra/variables.tf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
variable "environment_prefix" {
2+
type = string
3+
description = "The environment prefix to deploy: testing, pre-release or release"
4+
}
5+
6+
variable "environment_suffix" {
7+
type = string
8+
description = "The environment suffix to deploy"
9+
}
10+
11+
variable "cardano_network" {
12+
type = string
13+
description = "The Cardano network name to attach: preview, preprod or mainnet"
14+
}
15+
16+
locals {
17+
environment_name_short = format("%s%s", "${var.environment_prefix}-${var.cardano_network}", var.environment_suffix != "" ? "-${var.environment_suffix}" : "")
18+
environment_name = "mithril-${local.environment_name_short}"
19+
}
20+
21+
variable "google_region" {
22+
type = string
23+
description = "The region on GCP"
24+
}
25+
26+
variable "google_zone" {
27+
type = string
28+
description = "The zone on GCP"
29+
}
30+
31+
variable "google_machine_type" {
32+
type = string
33+
description = "The machine type on which to run the VM on GCP"
34+
}
35+
36+
variable "google_service_credentials_json" {
37+
type = string
38+
description = "The credentials of the GCP service account"
39+
}
40+
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"
44+
}
45+
46+
locals {
47+
google_service_credentials_json_decoded = jsondecode(file(var.google_service_credentials_json))
48+
google_service_account_private_key = local.google_service_credentials_json_decoded.private_key
49+
google_project_id = local.google_service_credentials_json_decoded.project_id
50+
}
51+
52+
variable "mithril_api_domain" {
53+
type = string
54+
description = "The Mithril api (sub)domain name of service to deploy"
55+
}
56+
57+
variable "mithril_image_id" {
58+
type = string
59+
description = "The Mithril image tag of service to deploy"
60+
}
61+
62+
variable "mithril_genesis_verification_key_url" {
63+
type = string
64+
description = "The url of the Mithril genesis verification key used by to verify a genesis certificate"
65+
}
66+
variable "mithril_genesis_secret_key" {
67+
type = string
68+
description = "The Mithril genesis secret key used by the aggregator to bootstrap a genesis certificate (test only)"
69+
}
70+
71+
variable "mithril_signers" {
72+
type = map(object({
73+
pool_id = string
74+
}))
75+
}

0 commit comments

Comments
 (0)