hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.51k stars 4.6k forks source link

Azure Virtual Desktop #16852

Open rosenbaaronAR opened 2 years ago

rosenbaaronAR commented 2 years ago

Is there an existing issue for this?

Community Note

Hi, I'm not sure what happened but every time I updated anything in my azure virtual desktop I get this message here. It seems an update like changing the scale plan requires that the host pool be deleted and re-created resulting in the following message. I have to destroy and then re-apply all of my resources to get it to work correctly. My provider is. provider "registry.terraform.io/hashicorp/azurerm" version = "2.98.0" ╷ │ Error: deleting Host Pool: (Name "test-hp" / Resource Group "rg-test"): desktopvirtualization.HostPoolsClient#Delete: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="400" Message="ActivityId: 4b7776dc-27c5-4be8-8664-cec1dbbeeaee Error: The SessionHostPool test-hp could not be deleted because it still has ApplicationGroups associated with it. Please remove all ApplicationGroups from the SessionHostPool and retry the operation." │ │

Terraform Version

1.1.9

AzureRM Provider Version

2.98.0

Affected Resource(s)/Data Source(s)

azurerm_virtual_desktop_host_pool

Terraform Configuration Files

##Create AVD Session Hosts resource Group

resource "time_rotating" "wvd_token" {
  rotation_days = 30
}

#Create WVD workspace
resource "azurerm_virtual_desktop_workspace" "ws" {
  name                = "${var.avd.name}-avd-ws"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
  friendly_name       = "${var.avd.name} /Greenway Agency"
  description         = "${var.avd.name} AVD PCS"
}

# Create WVD host pool
resource "azurerm_virtual_desktop_host_pool" "hp" {
  resource_group_name      = azurerm_resource_group.rg.name
  name                     = "${var.avd.name}-hp"
  location                 = azurerm_resource_group.rg.location
  validate_environment     = false
  start_vm_on_connect      = true
  custom_rdp_properties    = "audiocapturemode:i:1;audiomode:i:0;targetisaadjoined:i:1;"
  type                     = "Personal"
  maximum_sessions_allowed = 5
  load_balancer_type       = "DepthFirst" #[BreadthFirst DepthFirst]
  friendly_name            = "AVD HostPool"
  tags = {
    "environment" = var.tags
  }

}

resource "azurerm_virtual_desktop_host_pool_registration_info" "hpinfo" {
  hostpool_id     = azurerm_virtual_desktop_host_pool.hp.id
  expiration_date = time_rotating.wvd_token.rotation_rfc3339
}

# Create WVD DAG
resource "azurerm_virtual_desktop_application_group" "fd" {
  resource_group_name = azurerm_resource_group.rg.name
  host_pool_id        = azurerm_virtual_desktop_host_pool.hp.id
  location            = azurerm_resource_group.rg.location
  type                = "Desktop"
  name                = "fd-${var.avd.name}-avd"
  friendly_name       = "AVD Full Desktop"
  description         = "AVD Full Desktop"
  depends_on          = [azurerm_virtual_desktop_host_pool.hp]
}

Debug Output/Panic Output

│ Error: deleting Host Pool: (Name "test-hp" / Resource Group "rg-test"): desktopvirtualization.HostPoolsClient#Delete: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="400" Message="ActivityId: 4b7776dc-27c5-4be8-8664-cec1dbbeeaee Error: The SessionHostPool test-hp could not be deleted because it still has ApplicationGroups associated with it. Please remove all ApplicationGroups from the SessionHostPool and retry the operation

Expected Behaviour

No response

Actual Behaviour

No response

Steps to Reproduce

change something like the scale plan and terraform apply

Important Factoids

No response

References

No response

sinbai commented 2 years ago

@rosenbaaronAR thank you for opening this issue here. For "changing something like a scale plan", Could you explain which property in the tf config is modified?

rosenbaaronAR commented 2 years ago

When I changed the scale plan from .. resource "azurerm_virtual_desktop_scaling_plan" "scale_plan" { name = "${var.avd.name}-scale_plan" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name friendly_name = "Scaling Plan " description = "Scaling Plan" time_zone = "Central Standard Time" schedule { name = "Weekdays" days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] ramp_up_start_time = "05:00" ramp_up_load_balancing_algorithm = "BreadthFirst" ramp_up_minimum_hosts_percent = 0 ramp_up_capacity_threshold_percent = 10 peak_start_time = "09:00" peak_load_balancing_algorithm = "BreadthFirst" ramp_down_start_time = "19:00" ramp_down_load_balancing_algorithm = "DepthFirst" ramp_down_minimum_hosts_percent = 0 ramp_down_force_logoff_users = false ramp_down_wait_time_minutes = 45 ramp_down_notification_message = "Please log off in the next 45 minutes..." ramp_down_capacity_threshold_percent = 5 ramp_down_stop_hosts_when = "ZeroSessions" off_peak_start_time = "22:00" off_peak_load_balancing_algorithm = "DepthFirst" } host_pool { hostpool_id = azurerm_virtual_desktop_host_pool.hp.id scaling_plan_enabled = true } }

to

/ scale plan / resource "random_uuid" "scale_plan" { }

resource "azurerm_role_definition" "scale_plan" { name = "${var.avd.name}-autoscale" scope = azurerm_resource_group.rg.id description = "AVD AutoScale Role" permissions { actions = [ "Microsoft.Insights/eventtypes/values/read", "Microsoft.Compute/virtualMachines/deallocate/action", "Microsoft.Compute/virtualMachines/restart/action", "Microsoft.Compute/virtualMachines/powerOff/action", "Microsoft.Compute/virtualMachines/start/action", "Microsoft.Compute/virtualMachines/read", "Microsoft.DesktopVirtualization/hostpools/read", "Microsoft.DesktopVirtualization/hostpools/write", "Microsoft.DesktopVirtualization/hostpools/sessionhosts/read", "Microsoft.DesktopVirtualization/hostpools/sessionhosts/write",

"Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/delete" ,

"Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/read",

"Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/sendMessage/action" ,

"Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/read" ] not_actions = [] } assignable_scopes = [ azurerm_resource_group.rg.id, azurerm_virtual_desktop_host_pool.hp.id ] }

data azurerm_role_definition scale_plan { role_definition_id= "" scope = data.azurerm_subscription.current.id }

data "azuread_service_principal" "scale_plan" { display_name = "Windows Virtual Desktop" }

resource "azurerm_role_assignment" "scale_plan" { name = random_uuid.scale_plan.id

scope = trimsuffix(

data_azurerm_role_definition.scale_plan.id, "|${azurerm_role_definition.scale_plan.scope}") scope = azurerm_resource_group.rg.id role_definition_id = data.azurerm_role_definition.scale_plan .id principal_id = data.azuread_service_principal. scale_plan.application_id skip_service_principal_aad_check = true } / resource "azurerm_role_assignment" "scale_plan_hp" { name = random_uuid.scale_plan.id scope = data.azurerm_subscription.current.id role_definition_id = azurerm_role_definition.scale_plan.role_definition_resource_id principal_id = data.azuread_service_principal.scale_plan.application_id skip_service_principal_aad_check = true } / resource "azurerm_virtual_desktop_scaling_plan" "scale_plan" { name = "${var.avd.name}-scale_plan" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name friendly_name = "Scaling Plan " description = "Scaling Plan" time_zone = "Central Standard Time" schedule { name = "Weekdays" days_of_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] ramp_up_start_time = "05:00" ramp_up_load_balancing_algorithm = "DepthFirst" ramp_up_minimum_hosts_percent = 0 ramp_up_capacity_threshold_percent = 90 peak_start_time = "09:00" peak_load_balancing_algorithm = "DepthFirst" ramp_down_start_time = "19:00" ramp_down_load_balancing_algorithm = "DepthFirst" ramp_down_minimum_hosts_percent = 0 ramp_down_force_logoff_users = false ramp_down_wait_time_minutes = 45 ramp_down_notification_message = "Please log off in the next 45 minutes..." ramp_down_capacity_threshold_percent = 5 ramp_down_stop_hosts_when = "ZeroSessions" off_peak_start_time = "22:00" off_peak_load_balancing_algorithm = "DepthFirst" } host_pool { hostpool_id = azurerm_virtual_desktop_host_pool.hp.id scaling_plan_enabled = true } }

I get this error message.

│ Error: deleting Host Pool: (Name "cdcddgw-hp" / Resource Group "rg-cdcddgw"): desktopvirtualization.HostPoolsClient#Delete: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="400" Message="ActivityId: 0324190d-cd92-47b1-8207-0a92337e17ae Error: The SessionHostPool cdcddgw-hp could not be deleted because it still has ApplicationGroups associated with it. Please remove all ApplicationGroups from the SessionHostPool and retry the operation." │

On Sun, May 22, 2022 at 9:07 PM Elena Xin @.***> wrote:

@rosenbaaronAR https://github.com/rosenbaaronAR thank you for opening this issue here. For "changing something like a scale plan", Could you explain which property in the tf config is modified?

— Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-provider-azurerm/issues/16852#issuecomment-1134088644, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHARVKHRA4W5PAOZ2RYJWBDVLLR4TANCNFSM5WJMNSSA . You are receiving this because you were mentioned.Message ID: @.***>

-- Sincerely,

Aaron Rosenberg