github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/terraform/main.tf (about)

     1  terraform {
     2      required_providers {
     3          google = {
     4            source = "hashicorp/google"
     5          }
     6      }
     7  }
     8  
     9  variable "project_id" {
    10      type = string
    11      description = "project id"
    12  }
    13  
    14  variable "region" {
    15      type = string
    16      default = "us-central1"
    17      description = "region"
    18  }
    19  
    20  variable "creds_file" {
    21      type = string
    22      description = "credentials json file"
    23  }
    24  
    25  variable "ssh_public_file" {
    26      type = string
    27      description = "path to public key file"
    28  }
    29  
    30  variable "ssh_private_file" {
    31      type = string
    32      description = "path to private key file"
    33  }
    34  
    35  variable "zone" {
    36      type = string
    37      default = "us-central1-c"
    38      description = "zone"
    39  }
    40  
    41  variable "ansible_file" {
    42      type = string
    43      default = "../../prod/ansible/setupnodes.yml"
    44      description = "path to ansible config (.yml) file"
    45  }
    46  
    47  provider "google" {
    48      version = "3.5.0"
    49      credentials = file(var.creds_file)
    50      project = var.project_id
    51      region  = var.region
    52      zone    = var.zone
    53  }
    54  
    55  resource "google_compute_instance" "vm_instance" {
    56      name         = "${var.project_id}-instance"
    57      machine_type = "g1-small"
    58      scheduling {
    59          preemptible       = true
    60          automatic_restart = false
    61      }
    62  
    63      boot_disk {
    64          initialize_params {
    65            image = "ubuntu-1804-bionic-v20200317"
    66          }
    67      }
    68      tags = ["ssh"]
    69  
    70      metadata = {
    71          ssh-keys = "ubuntu:${file(var.ssh_public_file)}"
    72      }
    73  
    74      network_interface {
    75          network = google_compute_network.vpc_network.name
    76          access_config {
    77          }
    78      }
    79  }
    80  
    81  # Ansible AIStore deployment
    82  resource "null_resource" "ansible" {
    83      depends_on = [google_compute_instance.vm_instance]
    84  
    85      connection {
    86          user = "ubuntu"
    87          private_key = file(var.ssh_private_file)
    88          host = google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip
    89      }
    90  
    91      # ensure instance is ready
    92      provisioner "remote-exec" {
    93          script = "scripts/wait_for_instance.sh"
    94      }
    95  
    96      provisioner "local-exec" {
    97           command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu -i '${google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip},' --private-key ${var.ssh_private_file} ${var.ansible_file}"
    98      }
    99  
   100      provisioner "remote-exec" {
   101          script = "scripts/deploy_ais.sh"
   102      }
   103  }
   104  
   105  output "external_ip" {
   106      value = google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip
   107      description = "external ip address of the instance"
   108  }