Windows Terraform自定义Vsphere虚拟机监控程序中配置的VM
我可以使用Vsphere provider配置VM并加入域,但当我尝试将文件或执行powershell命令复制到配置的服务器时,它失败了。 在我的模板中,我启用了计数Windows Terraform自定义Vsphere虚拟机监控程序中配置的VM,windows,powershell,terraform,customization,vsphere,Windows,Powershell,Terraform,Customization,Vsphere,我可以使用Vsphere provider配置VM并加入域,但当我尝试将文件或执行powershell命令复制到配置的服务器时,它失败了。 在我的模板中,我启用了计数 resource "vsphere_virtual_machine" "vm" { count = var.vm_count resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id .... } 这将允许基于输入验证创建多个vm
resource "vsphere_virtual_machine" "vm" {
count = var.vm_count
resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
....
}
这将允许基于输入验证创建多个vm
在windows自定义中
customize {
windows_options {
computer_name = "${var.host_prefix}${count.index + 1}"
join_domain = "domainname"
domain_admin_user = "username"
domain_admin_password = "password"
time_zone = "004"
}
已为启用DHCP
通过上面的代码,我能够创建虚拟机并成功地将它们添加到域控制器
在此之后,我想在每个vm中启用iis,我已经编写了以下代码
resource "null_resource" "example_provisioner" {
connection {
host = "${var.host_prefix}${count.index + 1}"
type = "winrm"
user = "username"
password = "password"
insecure = false
agent = true
}
// copy our example script to the server
provisioner "file" {
source = "e://iis.ps1"
destination = "c://iis.ps1"
}
// change permissions to executable and pipe its output into a new file
provisioner "remote-exec" {
inline = [
"powershell.exe c://iis.ps1",
]
}
}
下面是当我使用hostname=“${var.host\u prefix}${count.index+1}”时null规定的错误。
PS E:\terraform\vmware>terraform计划
变量主机前缀
输入一个值:abchostname
var.vm\u计数
输入一个值:1
错误:在非计数上下文中引用“计数”
在base.tf第140行的resource中的“null\u resource”示例\u provisioner:
“计数”对象只能在“资源”和“数据”块中使用,并且只能在
设置“count”参数时
有人能帮我在新配置的vm上运行powershell命令吗?使用带有count参数的vpshere资源。您忘了在
null\u资源中添加count=var.vm\u count
。这将使您前进。这将引发一个错误,在null资源下不应出现此错误
resource "null_resource" "example_provisioner" {
connection {
host = "${var.host_prefix}${count.index + 1}"
type = "winrm"
user = "username"
password = "password"
insecure = false
agent = true
}
// copy our example script to the server
provisioner "file" {
source = "e://iis.ps1"
destination = "c://iis.ps1"
}
// change permissions to executable and pipe its output into a new file
provisioner "remote-exec" {
inline = [
"powershell.exe c://iis.ps1",
]
}
}
140: host = "${var.host_prefix}${count.index + 1}"