Azure / terraform-azurerm-virtual-machine

Terraform Azure RM Virtual Machine Module
MIT License
36 stars 36 forks source link

add a flag to support waiting for all vm extensions to finish installing #50

Closed esdccs1 closed 1 year ago

esdccs1 commented 1 year ago

Is there an existing issue for this?

Description

When installing network_watcher extension,

I have an azure connection monitor resource that I later use with the VM.

somtimes when I provision the vm using this module, the azurerm_network_connection_monitor that depends ont hsi module then fails and says the underlying network_watcher extension isn't installed yet

example failur:

Connection Monitor Name: "my-Site-Monitor"): performing CreateOrUpdate: unexpected status 400 with error: NetworkWatcherVmExtensionNotInstalled: Network Watcher VM extension Type: NetworkWatcherAgent Publisher: Microsoft.Azure.NetworkWatcher is not installed, VM: id /subscriptions/***/resourceGroups/myRg/providers/Microsoft.Compute/virtualMachines/my-azurerm-virtual-machine-vm1. Retry operation after installing the extension.

Not sure how to solve this, whether a flag saying 'wait for all things to finish' , or exposing an array inthe outputs to all the extension objects.

For now I have used external extension resources, and added an explicit dependency on my conection monitors

resource "azurerm_network_connection_monitor" "my_monitor" {
  depends_on = [  azurerm_virtual_machine_extension.network_watcher_agent_linux_vm1,
                            azurerm_virtual_machine_extension.network_watcher_agent_linux_vm2]

New or Affected Resource(s)/Data Source(s)

azurerm_network_connection_monitor

Potential Terraform Configuration

No response

References

No response

lonegunmanb commented 1 year ago

Hi @esdccs1 thanks for opening this issue, have you tried the following depends_on?:

depends_on = [module.virtual_machine]
esdccs1 commented 1 year ago

I will try that, I had provisoned two VMs in an availability set then referenced each one inside the endpoints block as such, but perhaps that wasnt enough for terraform to infer it needed to wait for other stuff inside module to finish


resource "azurerm_network_connection_monitor" "my_connection_mon" {

  name               = "Monitor"
  network_watcher_id = var.network_watcher_id
  location           = local.location

  endpoint {
    name = "source-1"
    target_resource_id = module.virtual_machine["1"].vm_id
  }

  endpoint {
    name = "source-2"
    target_resource_id = module.virtual_machine["2"].vm_id
  }

  dynamic "endpoint" {
    for_each = var.sites
    content {
      name         = "destination-${endpoint.value.name}"
      address      = endpoint.value.fqdn
    }
  }

  test_configuration {
    name                      = "my-test-config"
    protocol                  = "Http"
    test_frequency_in_seconds = 30
    http_configuration {
      port = 443
    }
  }

  test_group {
    name                     = "my-test-group"
    destination_endpoints    = [for entry in var.sites: "destination-${entry.name}"]
    source_endpoints         = ["source-1"]
    test_configuration_names = ["HTTPTestConfig"]
  }

  test_group {
    name                     = "my-test-group"
    destination_endpoints    = [for entry in var.sites: "destination-${entry.name}"]
    source_endpoints         = ["source-2"]
    test_configuration_names = ["HTTPTestConfig"]
  }

  output_workspace_resource_ids = [data.azurerm_log_analytics_workspace.my_law.id]
}
esdccs1 commented 1 year ago

@lonegunmanb I added the entire module as dependency and that resolved the problem, thank you for your prompt reply

resource "azurerm_network_connection_monitor" "my_connection_mon" {
  depends_on = [module.virtual_machine]

  ...