简体   繁体   English

Creating an Azure Linux VM with Ubuntu 20.04 with Terraform

[英]Creating an Azure Linux VM with Ubuntu 20.04 with Terraform

I am trying to create a Linux VM, with Terraform, in the West Europe Azure region, with a Ubuntu Server 20.04 LTS image.我正在尝试在西欧 Azure 区域创建一个 Linux VM,其中 Terraform 具有 Ubuntu Server 20.04 LTS 映像。 I can do this just fine from within the Azure Portal, but Terraform complains that the image doesn't exist:我可以在 Azure 门户中很好地执行此操作,但 Terraform 抱怨图像不存在:

The platform image 'Canonical:UbuntuServer:20.04-LTS:latest' is not available.平台映像“Canonical:UbuntuServer:20.04-LTS:latest”不可用。

Indeed, az vm image list --location westeurope confirms this;事实上, az vm image list --location westeurope证实了这一点; 18.04 LTS exists, but no 20.04 LTS.存在 18.04 LTS,但没有 20.04 LTS。

I am using the azurerm_linux_virtual_machine resource, with the following source_image_reference :我正在使用azurerm_linux_virtual_machine资源,具有以下source_image_reference

source_image_reference {
  publisher = "Canonical"
  offer     = "UbuntuServer"
  sku       = "20.04-LTS"  # FIXME SKU doesn't exist in westeurope
  version   = "latest"
}

I'm utterly confused by this?我对此完全困惑? How does one access the images in the Azure Marketplace in Terraform?如何在 Terraform 中访问 Azure Marketplace 中的图像? I've seen suggestions that the plan block is needed, but have no idea (nor have I found any documentation) on how to configure this.我已经看到需要plan块的建议,但不知道(我也没有找到任何文档)如何配置它。

I too was confused at first when I found out that it is available but under a different name, it is indeed kind of hidden.一开始我也很困惑,当我发现它可用但名称不同时,它确实有点隐藏。

offer                 = "0001-com-ubuntu-server-focal"
publisher             = "Canonical"
sku                   = "20_04-lts-gen2"

I used this inside packer so I am guessing it is the same in terraform, but you can let me know.我在内部使用了这个加壳器,所以我猜它在 terraform 中是一样的,但你可以告诉我。

for anyone else having this issue and having tried the above but still find it to be unhelpful.对于遇到此问题并尝试过上述方法但仍然无济于事的任何其他人。 Here is an addition to the above answer:这是对上述答案的补充:

login to azure cli and run the follwing command to list all your existing VMs based on your needs. login to azure cli并运行以下命令以根据您的需要列出所有现有的 VM。

az vm image list --all --publisher="Canonical" --sku="20_04-lts-gen2"

you should see an output like this:你应该看到这样的 output:

{
"architecture": "x64",
"offer": "0001-com-ubuntu-server-focal",
"publisher": "Canonical",
"sku": "20_04-lts-gen2",
"urn": "Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:20.04.202209050",
"version": "20.04.202209050"

}, },

{
    "architecture": "x64",
    "offer": "0001-com-ubuntu-server-focal",
    "publisher": "Canonical",
    "sku": "20_04-lts-gen2",
    "urn": "Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:20.04.202209200",
    "version": "20.04.202209200"
  }

in my case, I was having issues with my version.就我而言,我的版本有问题。 in this case, had to change my code from this ->在这种情况下,必须从此更改我的代码->

source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-focal"
    sku       = "20_04-lts-gen2"
    version   = "latest"
  }

to this ->对此->

source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-focal"
    sku       = "20_04-lts-gen2"
    version   = "20.04.202209200"
  }

As you can see, I used the version based on the output from the az command.如您所见,我使用了基于az命令中的 output 的版本。 enjoy terraform享受 terraform

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM