skip to Main Content

When deploying a custom script extension for a VM in Azure, it times out after 15 minutes. The timeout block is set to 2hrs. I cannot figure out why it keeps timing out. Could anyone point me in the right direction please? Thanks.

Resource to deploy (https://i.stack.imgur.com/lIfKj.png)

Error (https://i.stack.imgur.com/GFYRL.png)

2

Answers


  1. Chosen as BEST ANSWER

    I resolved the issue by changing the type_handler_version to 1.9.


  2. In Azure, each resource will take a particular amount of time for provisioning. For Virtual Network Gateway’s/ Virtual machines, timeout is up to 2 hours as mentioned in terraform timeouts.

    Therefore, the timeout block we provide for any virtual machine has to be less than two hours (2h).

    I tried creating a replica for azure vm extension resource by using below terraform code and it deployed successfully.

    timeout block:

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

    azure_VM_extension:

    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"
      }
    }
    

    Created a virtual machine by adding required configurations under resource group.

    main.tf:

    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"
      }
    }
    
    

    Executed:

    1. terraform init:

    enter image description here

    1. terraform plan:

    enter image description here

    1. terraform apply:

    enter image description here

    Extension added successfully after deployment:

    enter image description here

    You can upgrade status if you want to use extensions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search