如何通过terraform从gcp市场声明gcp计算引擎映像

时间:2020-06-29 19:13:15

标签: google-cloud-platform google-compute-engine terraform-provider-gcp gcp-ai-platform-training

我有公司的要求写一个terraform脚本来部署GCP市场中的计算引擎映像吗?这很可能是一个深度学习的图像。谁能帮忙吗?

示例图片-https://console.cloud.google.com/marketplace/details/click-to-deploy-images/deeplearning?q=compute%20engine%20images&id=8857b4a3-f60f-40b2-9b32-22b4428fd256

1 个答案:

答案 0 :(得分:2)

请查看以下示例here

resource "random_id" "instance_id" {
  byte_length = 8
}

resource "google_compute_instance" "default" {
  name         = "vm-${random_id.instance_id.hex}"
  machine_type = var.instance_type
  zone         = var.zone

  boot_disk {
    initialize_params {
      image = "deeplearning-platform-release/tf-ent-latest-gpu" # TensorFlow Enterprise
      size  = 50                                                // 50 GB Storage
    }
  }

  network_interface {
    network = "default"
    access_config {}
  }

  guest_accelerator {
    type  = var.gpu_type
    count = var.gpu_count
  }

  scheduling {
    automatic_restart   = true
    on_host_maintenance = "TERMINATE"
  }

  metadata = {
    install-nvidia-driver = "True"
    proxy-mode            = "service_account"
  }

  tags = ["deeplearning-vm"]

  service_account {
    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
  }
}

我最近以well的形式添加了对Terraform中的AI平台笔记本的支持。