通过 Terraform 创建 Azure Windows VM [英] Creating a Azure Windows VM through Terraform

查看:23
本文介绍了通过 Terraform 创建 Azure Windows VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Azure 中,我正在尝试使用 Terraform 创建一个 Windows VM.我之前使用 Template.json 文件通过 Powershell 完成了此操作.现在我必须处理 terraform,我对它完全陌生.所以我搜索了一些在 Azure 中创建 VM 的示例脚本,发现 这个.

In Azure, I'm trying to create a Windows VM using Terraform. I have done this through Powershell previously using Template.json file. Now I have to do with terraform, which I'm completely new to. So I have searched for some Sample scripts which creates VM in Azure and found this.

在此链接中,有一个用于旋转 Linux VM 的示例 Terraform 脚本.但我需要从图像中旋转 Windows VM.我应该在哪里提供图像详细信息.我的完整要求是:

In this link, there is a sample Terraform script to spin a Linux VM. But I need to spin a windows VM from an Image. Where should I give the Image details. My complete requirement is:

  1. 从映像创建 Windows VM(具有资源 ID)
  2. 我已经创建了资源组、虚拟网络、子网.我只需要传递这些值并创建它们.
  3. 我们已经从门户本身定义了子网地址前缀、Vnet 地址空间.所以我必须在脚本中再次给出还是可以跳过它.
  4. 业务要求是虚拟机不应该有公共 IP 和 DNS 名称,所以如果我删除# Create public IPs"部分,那会不会创建公共 IP?

创建 Linux 机器的脚本是 here,我将其作为参考.

The script for creating a Linux machine is here, which I'm taking it as reference.

推荐答案

从 Terraform 的角度来看,Windows VM 与 Linux VM 非常相似.在我看来,第一个区别是 Windows VM 需要 os_profile_windows_config 属性,而 Linux VM 需要 os_profile_linux_config.

From Terraform's perspective, a Windows VM is really quite similar to a Linux VM. The #1 difference in my opinion is that the Windows VM requires a os_profile_windows_config attribute, while the Linux VM needs os_profile_linux_config.

您在 Microsoft 网站上找到的 TF 代码是一个很好的开始.此外,您可以查看 Terraform Registry.例如,这是一个 Linux VM 的模块.

The TF code you found on the Microsoft site is a fine start. Additionally, you may look in the Terraform Registry. For example, here's a module for a Linux VM.

我强烈建议通读 VM 资源中的所有选项.我知道这很多,但你应该明白你有什么选择.

I strongly recommend reading through all of the options in the VM resource. I know it's a lot, but you should understand what choices you have.

最后,编写一些代码并对其进行测试是无可替代的.如果您做错了什么,Terraform 和/或 Azure API 会告诉您,如果不清楚,网络搜索会弹出答案或指向正确方向的指针.

Lastly, there's no substitute for writing some code and testing it. If you do something wrong, either Terraform and/or the Azure API will tell you, and if it's unclear, a web search will pop up an answer or a pointer in the right direction.

这篇关于通过 Terraform 创建 Azure Windows VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆