【发布时间】:2020-06-10 10:44:05
【问题描述】:
我正在尝试使用 Terraform File Provisioner 将目录上传到使用 WinRM 的 Azure VM。得到各种错误和超时。 Win2009 服务器虚拟机部署得很好,部署后,我可以使用 WinRM 对系统进行 Powershell 远程会话。但是,当我添加 File Provisioner(如下所示)时,出现以下错误之一:
Error: timeout - last error: http response error: 401 - invalid content type
还是这个错误,取决于切换到https的真/假还是不安全的真/假:
Error: timeout - last error: unknown error Post https://52.176.165.48:5985/wsman: http: server gave HTTP response to HTTPS client
有没有更好的方法来上传目录并在 VM 实例化后执行 PowerShell 部署后脚本?
这是我的 *.tf 文件:
locals {
virtual_machine_name = "${var.prefix}-dc1"
virtual_machine_fqdn = "${local.virtual_machine_name}.${var.active_directory_domain}"
custom_data_params = "Param($RemoteHostName = \"${local.virtual_machine_fqdn}\", $ComputerName = \"${local.virtual_machine_name}\")"
custom_data_content = "${local.custom_data_params} ${file("${path.module}/files/winrm.ps1")}"
}
resource "azurerm_availability_set" "dcavailabilityset" {
name = "dcavailabilityset"
resource_group_name = "${var.resource_group_name}"
location = "${var.location}"
platform_fault_domain_count = 3
platform_update_domain_count = 5
managed = true
}
resource "azurerm_virtual_machine" "domain-controller" {
name = "${local.virtual_machine_name}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
availability_set_id = "${azurerm_availability_set.dcavailabilityset.id}"
network_interface_ids = ["${azurerm_network_interface.primary.id}"]
vm_size = "Standard_A1"
delete_os_disk_on_termination = false
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
storage_os_disk {
name = "${local.virtual_machine_name}-disk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "${local.virtual_machine_name}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
custom_data = "${local.custom_data_content}"
}
os_profile_windows_config {
provision_vm_agent = true
enable_automatic_upgrades = false
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "AutoLogon"
content = "<AutoLogon><Password><Value>${var.admin_password}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.admin_username}</Username></AutoLogon>"
}
# Unattend config is to enable basic auth in WinRM, required for the provisioner stage.
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "FirstLogonCommands"
content = "${file("${path.module}/files/FirstLogonCommands.xml")}"
}
}
provisioner "file" {
source = "BadBlood"
destination = "C:/BadBlood"
connection {
host = "${azurerm_public_ip.dc1-external.ip_address}"
type = "winrm"
user = "${var.admin_username}"
password = "${var.admin_password}"
timeout = "15m"
https = false
port = "5985"
insecure = true
}
}
}
【问题讨论】:
-
你确定 WinRM 真的启用了吗?如果是,您还需要创建 NSG 规则以允许端口 5985 用于入站流量,同时存在与之关联的 NSG。
-
是的,我最终通过添加 Windows 防火墙规则以允许 https-winrm 使用端口 5986 来解决问题,并将配置程序更改为使用端口 5986 并将 https 设置为 true。
-
好的,如果您自己解决,请添加答案以显示或直接删除。
标签: terraform terraform-provider-azure