【问题标题】:"Future#WaitForCompletion" while running a powershell script from GitHub - Terraform从 GitHub 运行 powershell 脚本时出现“Future#WaitForCompletion” - Terraform
【发布时间】:2022-01-08 16:18:34
【问题描述】:

我在 GitHub 中有一个 powershell 脚本,并在“azurerm_virtual_machine_extension”内的“设置”块中使用它来配置 Windows Server VM。下面是代码。

resource "azurerm_virtual_machine_extension" "iis-windows-vm" {
 depends_on           = [azurerm_windows_virtual_machine.web-windows-vm]
 name                 = "win-${random_string.random-win-vm.result}-vm-extn"
 virtual_machine_id   = azurerm_windows_virtual_machine.web-windows-vm.id
 publisher            = "Microsoft.Compute"
 type                 = "CustomScriptExtension"
 type_handler_version = "1.9"

   settings = <<SETTINGS
    {
        "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File demo.ps1",
        "fileUris": ["https://raw.githubusercontent.com/Configure/app/master/demo.ps1"]
    }
SETTINGS
}

以下是“demo.ps1”的内容

New-LocalUser "ansible" -Password (ConvertTo-SecureString -AsPlainText -Force ) -AccountNeverExpires:$true -PasswordNeverExpires:$true -FullName "ansible" | Add-LocalGroupMember -Group administrators

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\ConfigureRemotingForAnsible.ps1"

(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)

powershell.exe -ExecutionPolicy ByPass -File $file

Install-WindowsFeature -Name Web-Server -IncludeAllSubFeature -IncludeManagementTools

当我执行“terraform apply”时,会显示以下错误。

Error: Future#WaitForCompletion: context has been cancelled: StatusCode=200 -- Original Error: context deadline exceeded

到目前为止,代码运行良好。无法在这里找出问题所在。请求您协助我完成这项工作。

【问题讨论】:

    标签: azure powershell terraform cloud


    【解决方案1】:

    错误Original Error: context deadline exceeded 表示我们遇到了给定操作未在预期时间范围内完成的情况。

    因此,您遇到执行超时的原因可能有很多,例如网络延迟、慢 I/O、防火墙规则 等等。我认为一个可能的原因是 URL 没有按预期响应,或者响应时间过长。

    在能够解决问题之前,您需要确定实际失败的原因。我建议检查详细的 terraform 日志文件以查找超时原因。

    但即使在检查后发现它很好并且您仍然面临问题,然后使用 v2.0 of the AzureRM Provider 可以使用 timeouts 块添加自定义超时,如下面以 sn-p 为例。

    resource "azurerm_resource_group" "example" {
      name     = "example-resource-group"
      location = "West Europe"
    
      timeouts {
        create = "10m"
        delete = "30m"
      }
    }
    

    有关更多信息,请查看 terraform 文档的 Custom Timeouts for Resources 部分。

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 2014-07-23
      • 2016-09-13
      • 2020-11-06
      • 1970-01-01
      • 2019-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多