【问题标题】:Terraform File provisionerTerraform 文件配置器
【发布时间】:2021-03-04 06:45:52
【问题描述】:

创建 VM 后,我正在使用 terraform 配置文件和 remote-exec 安装 google chrome。但是在运行 terraform apply 时会出错。我还启用了 nsg 规则以允许所有端口。我不确定该错误是否与 nsg 规则有关。

Error: timeout - last error: unknown error Post "https://10.0.2.4:5986/wsman": dial tcp 10.0.2.4:5986: connectex: A connection attempt failed because the connected party did not properly respond after a 
period of time, or established connection failed because connected host has failed to respond.
resource "azurerm_virtual_machine" "myterraformvm" {

    name                  = "Test-01"
    location              = "East Us"
    resource_group_name = data.azurerm_resource_group.test.name
    network_interface_ids = ["${azurerm_network_interface.main.id}"]
    vm_size               = "Standard_DS1_v2"


    storage_os_disk {
    name              = "${azurerm_managed_disk.copy.name}"
    os_type           = "Windows"
    managed_disk_id   = "${azurerm_managed_disk.copy.id}"
    create_option     = "Attach"
    }

    provisioner "file" {
    source      = "./google_chrome_install.ps1"
    destination = "C:/"
     
     connection {
      host = "${azurerm_network_interface.main.private_ip_address}"
      type     = "winrm"
      https    = true
      port     = 5986
      use_ntlm = true
      insecure = true
      user     = "testadmin"
      password = "*******"
    }
  }



   provisioner "remote-exec" {

    connection {
      host = "${azurerm_network_interface.main.private_ip_address}"
      type     = "winrm"
      https    = true
      port     = 5986
      use_ntlm = true
      insecure = true
      user     = "testadmin"
      password = "***"
    }


inline = [
         "powershell -ExecutionPolicy Unrestricted -File C:/google_chrome_install.ps1 -Schedule"
        ]
      }
}

【问题讨论】:

  • 您是否与5986 上的10.0.2.4 实例建立了连接?您如何路由到该私有 IP 地址?
  • 您也使用 https 获取 IP。猜猜应该是http。

标签: terraform


【解决方案1】:

我在从 Terraform 到 aws ec2 实例的 ssh 连接方面遇到了类似的问题。 有几件事我想提一下。如果它们不起作用,请告诉我。

  1. 这个问题可能是因为防火墙规则。我的问题是安全组(相当于aws中的防火墙规则)请查看这篇文章是否有帮助: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal

  2. 您不应将凭据放在开放文本中。您应该始终创建私钥(我创建了一个 pem 密钥并使用了本文中提到的private_key 参数:https://github.com/DeekshithSN/Terraform/blob/master/Provisioner/file-Provisioner/main.tf

  3. 如果你用它创建一个模块,你可能会使用相同的连接块。看看这个以供参考https://learn.hashicorp.com/tutorials/terraform/module-use

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 2020-03-17
    • 2022-10-07
    • 2019-02-20
    • 2021-09-25
    相关资源
    最近更新 更多