【问题标题】:How to set the virtual machine image details e.g. publisher, offer, sku and version如何设置虚拟机映像详细信息,例如出版商、报价、sku 和版本
【发布时间】:2019-12-15 03:13:32
【问题描述】:

我有一个 Terraform 脚本,它根据 Azure 市场中的这个图像在 Azure 上创建一个虚拟机: https://azuremarketplace.microsoft.com/en-us/marketplace/apps/gitlab.gitlab-ce

但我不知道如何识别要放入这些字段的值:

  • 出版商
  • 报价
  • sku
  • 版本

这是来自 Terraform 脚本的 sn-p

resource "azurerm_virtual_machine" "gitlab_vm" {
  # ... other configuration

  storage_image_reference {
    publisher = "GitLab"
    offer     = "GitLab Community Edition"
    # sku       = "???"
    version   = "latest"
  }

  # ... other configuration
}

如果我使用 terraform plan 运行之前的详细信息,例如publisher = "GitLabXXX"(不存在的东西),然后 Terraform 不会引发任何错误。当我在一段时间后运行 terraform apply 时,会引发错误并且未创建 VM 资源(尽管创建了所有其他资源,例如网络资源)。

这适用于 Azure ARM 模板的类似方式:

"imageReference": {
    "publisher": "[variables('pubName')]",
    "offer": "[variables('offerName')]",
    "sku" : "[parameters('skuName')]",
    "version":"latest"
},

我有一些虚拟机正在启动并运行,它使用我在 Internet 上找到的类似 Terraform 配置(请参阅下面的 Ubuntu 示例),但是将信息从 Azure 市场网页转换为脚本的规则是什么?

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

【问题讨论】:

    标签: azure gitlab-ci azure-virtual-machine arm-template terraform-provider-azure


    【解决方案1】:

    可能有更有效的方法来执行此操作,但我通常使用 Azure CLI 来获取发布者、优惠、SKU 和版本。首先,如果您执行以下操作:

    az vm image list --offer GitLab -o table --all

    您将获得包含报价、发布商、SKU、URN 和版本的列表。在您的情况下,gitlab-ce 应该是这样的:

    • 发布者:gitlab
    • 提供:gitlab-ce
    • SKU:gitlab-ce
    • 版本:1.0.4

    我很确定 azurerm 提供程序只是使用这些值调用 ARM,因此它应该与您从 CLI 获得的值相匹配,但如果我弄错了,我当然可以对此进行更正。

    您还需要添加plan block。可以通过 CLI 检索其详细信息,如下所示:

    az vm image show --location westus --urn gitlab:gitlab-ce:gitlab-ce:1.0.4 -o json

    所以你的计划块看起来像:

    plan {
      name = "gitlab-ce" 
      publisher = "gitlab"
      product = "gitlab-ce"
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-14
      • 2011-03-24
      • 2017-12-10
      • 2015-01-31
      • 2015-11-02
      • 2020-10-22
      • 1970-01-01
      • 2019-12-28
      • 2011-12-08
      相关资源
      最近更新 更多