【问题标题】:Where would I get a listing of the actual Compute Engine image names?我在哪里可以获得实际 Compute Engine 映像名称的列表?
【发布时间】:2019-07-13 16:46:55
【问题描述】:

我正在尝试使用 Terraform 进行第一次 Compute Engine 实例的配置。

需要的参数之一是正在使用的图像名称。通过控制台手动配置实例时,我可以看到图像列表,但这些是图像的人类可读标签(例如“CentOS 6”、“Ubuntu 16.04 LTS”等)我试图了解我会在哪里获取我将在“resource”指令的“boot_disk”部分中使用的实际 Compute Engine 映像名称的列表。

resource "google_compute_instance" "default" {
  name         = "Test_CE"
  machine_type = "n1-standard-1"
  zone         = "us-east1-b"

  boot_disk {
    initialize_params {
      image = "<actual image name goes here>"
    }
  }
}

【问题讨论】:

    标签: google-cloud-platform google-compute-engine terraform


    【解决方案1】:

    CLI gcloud 将列出可用的图像。

    gcloud compute images list
    

    Documentation: gcloud compute images list

    以下是返回列表的第一部分。将NAME 下的字符串用于 Terraform。

    NAME                                                  PROJECT            FAMILY                            DEPRECATED  STATUS
    centos-6-v20190213                                    centos-cloud       centos-6                                      READY
    centos-7-v20190213                                    centos-cloud       centos-7                                      READY
    coreos-alpha-2051-0-0-v20190211                       coreos-cloud       coreos-alpha                                  READY
    coreos-beta-2023-3-0-v20190219                        coreos-cloud       coreos-beta                                   READY
    coreos-stable-1967-6-0-v20190213                      coreos-cloud       coreos-stable                                 READY
    cos-69-10895-138-0                                    cos-cloud          cos-69-lts                                    READY
    cos-beta-73-11647-35-0                                cos-cloud          cos-beta                                      READY
    cos-dev-74-11758-0-0                                  cos-cloud          cos-dev                                       READY
    cos-stable-72-11316-136-0                             cos-cloud          cos-stable                                    READY
    debian-9-stretch-v20190213                            debian-cloud       debian-9                                      READY
    

    【讨论】:

      【解决方案2】:

      您可能会发现改用 google_compute_image data source 更容易,因此您可以在那里通过它的人类可读名称来引用它,并且只需在您的 google_compute_instance 资源中使用 self_link 输出。

      google_compute_image 数据源文档提供了一个很好的例子:

      data "google_compute_image" "my_image" {
        name    = "debian-9"
        project = "debian-cloud"
      }
      
      resource "google_compute_instance" "default" {
        # ...
      
        boot_disk {
          initialize_params {
            image = data.google_compute_image.my_image.self_link
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2014-03-17
        • 2013-09-06
        • 2023-03-18
        • 1970-01-01
        • 1970-01-01
        • 2020-08-28
        • 2011-02-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多