使用Terraform部署时Azure自定义脚本扩展超时

tmb3ates  于 2022-11-30  发布在  其他
关注(0)|答案(2)|浏览(146)

在Azure中为VM部署自定义脚本扩展时,它会在15分钟后超时。超时块设置为2小时。我不明白它为什么一直超时。有人能给我指出正确的方向吗?谢谢。
要部署的资源(https://i.stack.imgur.com/lIfKj.png
错误(https://i.stack.imgur.com/GFYRL.png

rqqzpn5f

rqqzpn5f1#

在Azure中,每个资源将花费特定的时间进行设置。对于虚拟网络网关/虚拟机,超时最多为2小时,如terraform超时中所述。
因此,我们为任何虚拟机提供的timeout块必须小于two hours(2h)。
我尝试使用下面的terraform代码为azure vm extension资源创建一个replica,并且成功部署。
timeout数据块

timeouts {
    create =  "1h30m"
    delete =  "20m"
  }

Azure虚拟机扩展

resource "azurerm_virtual_machine_extension" "xxxxx" {
  name                 = "xxxxname"
  virtual_machine_id   = azurerm_virtual_machine.example.id
  publisher            = "Microsoft.Azure.Extensions"
  type                 = "CustomScript"
  type_handler_version = "2.0"
   settings = <<SETTINGS
 {
  "commandToExecute": "hostname && uptime"
 }
SETTINGS
  tags = {
    environment = "Production"
  }
timeouts {
    create =  "1h30m"
    delete =  "20m"
  }
}

通过在资源组下添加所需配置创建了虚拟机
主文件格式

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.0.0"
    }
  }
}
provider "azurerm" {
  features {}
}
resource "azurerm_resource_group" "xxxxxRG" {
  name     = "xxxxx-RG"
  location = "xxxxxx"
}
resource "azurerm_virtual_network" "example" {
  name                = "xxxxx"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
  name                 = "xxxxx"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "example" {
  name                = "xxxxxx"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_configuration {
    name                          = "xxxxconfiguration"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}
resource "azurerm_storage_account" "example" {
  name                     = "xxxxx"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
  tags = {
    environment = "staging"
  }
}
resource "azurerm_storage_container" "example" {
  name                  = "xxxxxx"
  storage_account_name  = azurerm_storage_account.example.name
  container_access_type = "private"
}

resource "azurerm_virtual_machine" "example" {
  name                  = "xxxxxxVM"
  location              = azurerm_resource_group.example.location
  resource_group_name   = azurerm_resource_group.example.name
  network_interface_ids = [azurerm_network_interface.example.id]
  vm_size               = "Standard_F2"

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  storage_os_disk {
    name          = "xxxxx"
    vhd_uri       = "${azurerm_storage_account.example.primary_blob_endpoint}${azurerm_storage_container.example.name}/myosdisk1.vhd"
    caching       = "ReadWrite"
    create_option = "FromImage"
  }

  os_profile {
    computer_name  = "xxxxxname"
    admin_username = "xxxx"
    admin_password = "xxxxxx"
  }
  os_profile_linux_config {
    disable_password_authentication = false
  }

  tags = {
    environment = "staging"
  }
}
resource "azurerm_virtual_machine_extension" "example" {
  name                 = "hostname"
  virtual_machine_id   = azurerm_virtual_machine.example.id
  publisher            = "Microsoft.Azure.Extensions"
  type                 = "CustomScript"
  type_handler_version = "2.0"
   settings = <<SETTINGS
 {
  "commandToExecute": "hostname && uptime"
 }
SETTINGS
  tags = {
    environment = "Production"
  }
timeouts {
    create =  "1h30m"
    delete =  "20m"
  }
}

已执行:

  1. terraform init

  1. terraform plan

  1. terraform apply

部署后成功添加扩展

  • 如果要使用扩展,您可以升级状态。*
hfsqlsce

hfsqlsce2#

我通过将type_handler_version更改为1.9解决了该问题。

相关问题