Skip to content

Instantly share code, notes, and snippets.

@nik-hil
Created March 4, 2020 16:36
Show Gist options
  • Save nik-hil/d6aa7f1c6f4da7d931c4ab841f0e0f74 to your computer and use it in GitHub Desktop.
Save nik-hil/d6aa7f1c6f4da7d931c4ab841f0e0f74 to your computer and use it in GitHub Desktop.
create fastai server on gcp using terraform.
provider "google" {
credentials = file("CREDENTIALS_FILE.json")
project = "famous-muse-247206"
region = "us-west1"
}
# TF-UPGRADE-TODO: Block type was not recognized, so this block and its contents were not automatically upgraded.
resource "random_id" "instance_id" {
byte_length = 8
}
// A single Google Cloud Engine instance
resource "google_compute_instance" "default" {
name = "famous-muse-${random_id.instance_id.hex}"
machine_type = "n1-standard-4"
zone = "us-west1-b"
boot_disk {
initialize_params {
image = "deeplearning-platform-release/pytorch-latest-gpu"
size = 50
}
}
attached_disk {
source = google_compute_disk.default.name
mode = "READ_WRITE"
}
// Make sure flask is installed on all new instances for later steps
metadata_startup_script = "sudo apt-get update; sudo apt-get install -yq build-essential python-pip rsync; pip install flask"
network_interface {
network = "default"
access_config {
// Include this section to give the VM an external ip address
}
}
guest_accelerator{
type = "nvidia-tesla-k80" // Type of GPU attahced
count = 1 // Num of GPU attached
}
scheduling{
on_host_maintenance = "TERMINATE" // Need to terminate GPU on maintenance
}
tags = ["allow-teraform"]
}
resource "google_compute_firewall" "allow-teraform" {
name = "allow-teraform"
network = "default"
allow {
protocol = "tcp"
ports = ["22", "80", "8080", "8888"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["allow-teraform"]
}
resource "google_compute_disk" "default" {
name = "disk-teraform"
type = "pd-ssd"
zone = "us-west1-b"
image = "debian-8-jessie-v20170523"
labels = {
environment = "dev"
}
physical_block_size_bytes = 4096
}
output "ip" {
value = "${google_compute_instance.default.network_interface.0.access_config.0.nat_ip}"
}
@nik-hil
Copy link
Author

nik-hil commented Mar 4, 2020

not able to do ssh. WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment