diff --git a/terraform/google/.terraform.lock.hcl b/terraform/google/.terraform.lock.hcl new file mode 100644 index 0000000..ff14b94 --- /dev/null +++ b/terraform/google/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "4.14.0" + constraints = "4.14.0" + hashes = [ + "h1:JzIffu+H0h1MX7SuMa1Hheh39xEKaic43fU21twbUrQ=", + "zh:05219b3539e13eeb2bbd8775bfa0644aeaf975c30d734a24e06ec2ae0fa6aea1", + "zh:0d472a9c11d4f91c1fcbe053eca42bd895c400f9e9783c049d8c67e140ed274c", + "zh:2e38c632ac3289b31a4f4868e42f3ced4c9acbb79b43376209d7a51154a94b41", + "zh:7ed048c9c18e9e92836f9a82c2c9aea956a82a178b7a3e33f94a4a94f7e20797", + "zh:8f92259b3c37c1bf161d70048cc1b23517864626f0d277189657f5158da3728c", + "zh:a815b8670808e12a82c1d9fe40f4223138df39e2b9ed70b93647190586f515f0", + "zh:adcee3a69b081cf0da555d344453b3ecbde7bb34770f026fd4ed84d936c48895", + "zh:d2da37422ce3a197fa03d9e96ef9c0dfe3ee5c247ff82c272f2958c5d6cf3396", + "zh:e28be41d19f44c9012fc7909625d4dc67a75fb00f5b69fe1295fe07cb04f1b37", + "zh:ece149ec2e5c7d1727665c1f8834bfa71e99405a60a5f6ea384dced52ace2def", + "zh:f59bac8454a97794d2378393b6bb2cbeb61983306de0f13be06956b87d22efd5", + ] +} diff --git a/terraform/google/output.tf b/terraform/google/output.tf new file mode 100644 index 0000000..4329682 --- /dev/null +++ b/terraform/google/output.tf @@ -0,0 +1,4 @@ +output "public_ipv4" { + value = google_compute_instance.server.network_interface.0.access_config.0.nat_ip +} + diff --git a/terraform/google/provider.tf b/terraform/google/provider.tf new file mode 100644 index 0000000..8186b5f --- /dev/null +++ b/terraform/google/provider.tf @@ -0,0 +1,16 @@ +terraform { + required_providers { + google = { + source = "hashicorp/google" + version = "=4.14.0" + } + } +} + +# Configure the Google Provider +provider "google" { + project = var.project + region = var.region + zone = var.zone + credentials = file("/home/noble/.config/gcloud/gcloud-terraform-key.json") +} diff --git a/terraform/google/server.tf b/terraform/google/server.tf new file mode 100644 index 0000000..8c5799d --- /dev/null +++ b/terraform/google/server.tf @@ -0,0 +1,45 @@ +data "google_compute_image" "image" { + family = "common-cu113-debian-10" + project = "deeplearning-platform-release" +} + +resource "google_compute_instance" "server" { + name = "ml-server" + #machine_type = "f1-micro" + machine_type = var.machine_type + zone = var.zone + + tags = ["ml", "gpu"] + + guest_accelerator { + type = var.guest_accelerator + count = 1 + } + + boot_disk { + initialize_params { + image = data.google_compute_image.image.self_link + # image = "debian-cloud/debian-10" + } + } + + // Local SSD disk + scratch_disk { + interface = "SCSI" + } + + network_interface { + network = "default" + + access_config { + } + } + + scheduling { + on_host_maintenance = "TERMINATE" + } + + #metadata_startup_script = file("${path.module}/startup_script.sh") + metadata_startup_script = templatefile("${path.module}/startup_script.sh", var.startup_script_vars) + +} diff --git a/terraform/google/startup_script.sh b/terraform/google/startup_script.sh new file mode 100644 index 0000000..fc44d88 --- /dev/null +++ b/terraform/google/startup_script.sh @@ -0,0 +1,6 @@ +#!/bin/bash +useradd -m -G sudo -s /bin/bash noble +mkdir /home/noble/.ssh +echo "${SSH_PUBLIC_KEY}" > /home/noble/.ssh/authorized_keys +apt update -y && apt install -y tmux +bash /opt/deeplearning/install-driver.sh \ No newline at end of file diff --git a/terraform/google/vars.tf b/terraform/google/vars.tf new file mode 100644 index 0000000..9075075 --- /dev/null +++ b/terraform/google/vars.tf @@ -0,0 +1,30 @@ +# Name variable definition +variable "name" { + default = "ml" +} + +# Definition of an instance type variable depending on the choice of tariff +variable "machine_type" { + default = "custom-8-30720" +} + +variable "project" { + default = "project" +} + +# Definition of the region in which the instance will be created +variable "region" { + default = "europe-west4" +} + +variable "zone" { + default = "europe-west4-a" +} + +variable "guest_accelerator" { + default = "nvidia-tesla-v100" +} + +variable "startup_script_vars" { + type = map +}