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

Unable to Create azurerm_virtual_desktop_host_pool With scheduled_agent_updates #23881

Open cpc-justinbrown opened 9 months ago

cpc-justinbrown commented 9 months ago

Is there an existing issue for this?

Community Note

Terraform Version

v1.5.7

AzureRM Provider Version

v3.80.0

Affected Resource(s)/Data Source(s)

azurerm_virtual_desktop_host_pool

Terraform Configuration Files

resource "azurerm_virtual_desktop_host_pool" "this" {
  location                         = var.location
  resource_group_name              = var.resource_group_name
  name                             = var.name
  friendly_name                    = var.friendly_name
  type                             = var.type
  load_balancer_type               = var.load_balancer_type
  description                      = var.description
  validate_environment             = var.validate_environment
  start_vm_on_connect              = false
  maximum_sessions_allowed         = var.maximum_sessions_allowed
  personal_desktop_assignment_type = var.personal_desktop_assignment_type
  custom_rdp_properties            = data.local_file.custom_rdp_property.content

  scheduled_agent_updates {
    # Intent is to create the host pool with scheduled updates for Saturday 10:00 PM local time of the session host.
    enabled                   = true
    use_session_host_timezone = true
    schedule {
      day_of_week = "Saturday"
      hour_of_day = 22
    }
  }
}

Debug Output/Panic Output

2023-11-13T17:31:33.063Z [DEBUG] provider.terraform-provider-azurerm_v3.80.0_x5: AzureRM Request: 
PUT /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rgAM-DaaS-Dev/providers/Microsoft.DesktopVirtualization/hostPools/vdpoolXYZscus-Testing-Dev?api-version=2022-02-10-preview HTTP/1.1
Host: management.azure.com
User-Agent: HashiCorp/go-azure-sdk (Go-http-Client/1.1 hostpool/2022-02-10-preview) HashiCorp Terraform/1.6.3 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.80.0 pid-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Content-Length: 907
Content-Type: application/json; charset=utf-8
Accept-Encoding: gzip

{"location":"southcentralus","properties":{"agentUpdate":{"type":"Scheduled"},"customRdpProperty":"drivestoredirect:s:;audiomode:i:0;videoplaybackmode:i:1;redirectclipboard:i:1;redirectprinters:i:0;devicestoredirect:s:*;redirectcomports:i:0;redirectsmartcards:i:1;usbdevicestoredirect:s:*;enablecredsspsupport:i:1;redirectwebauthn:i:1;enablerdsaadauth:i:1;smart sizing:i:1;dynamic resolution:i:1;screen mode id:i:1;use multimon:i:1;singlemoninwindowedmode:i:1;","description":"TESTING","friendlyName":"TESTING","hostPoolType":"Pooled","loadBalancerType":"BreadthFirst","maxSessionLimit":1,"personalDesktopAssignmentType":"","preferredAppGroupType":"Desktop","startVMOnConnect":false,"validationEnvironment":true},"tags":{"CostCenter":"CostCenter","Department":"Department","Description":"Description","ManagedBy":"ManagedBy","Orchestrator":"Terraform"}}: timestamp=2023-11-13T17:31:33.063Z
2023-11-13T17:31:33.063Z [DEBUG] provider.terraform-provider-azurerm_v3.80.0_x5: PUT https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rgAM-DaaS-Dev/providers/Microsoft.DesktopVirtualization/hostPools/vdpoolXYZscus-Testing-Dev?api-version=2022-02-10-preview: timestamp=2023-11-13T17:31:33.063Z
2023-11-13T17:31:33.965Z [DEBUG] provider.terraform-provider-azurerm_v3.80.0_x5: AzureRM Response for https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rgAM-DaaS-Dev/providers/Microsoft.DesktopVirtualization/hostPools/vdpoolXYZscus-Testing-Dev?api-version=2022-02-10-preview: 
HTTP/2.0 400 Bad Request
Content-Length: 199
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Mon, 13 Nov 2023 17:31:32 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/10.0
...

{"error":{"code":"400","message":"ActivityId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Error: Agent update UseSessionHostLocalTime must be set., MaintenanceWindows must have one MaintenanceWindow set."}}: timestamp=2023-11-13T17:31:33.965Z
2023-11-13T17:31:33.965Z [TRACE] provider.terraform-provider-azurerm_v3.80.0_x5: Called downstream: @module=sdk.helper_schema tf_provider_addr=provider tf_req_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx tf_resource_type=azurerm_virtual_desktop_host_pool @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.29.0/helper/schema/resource.go:910 tf_rpc=ApplyResourceChange timestamp=2023-11-13T17:31:33.965Z
2023-11-13T17:31:33.965Z [TRACE] provider.terraform-provider-azurerm_v3.80.0_x5: Received downstream response: tf_rpc=ApplyResourceChange diagnostic_error_count=1 diagnostic_warning_count=0 tf_proto_version=5.4 tf_req_duration_ms=1157 tf_req_id=03b8162d-b9d4-9e1f-de38-f16055eed8e3 tf_resource_type=azurerm_virtual_desktop_host_pool @module=sdk.proto tf_provider_addr=provider @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 timestamp=2023-11-13T17:31:33.965Z
2023-11-13T17:31:33.965Z [ERROR] provider.terraform-provider-azurerm_v3.80.0_x5: Response contains error diagnostic: @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov5/internal/diag/diagnostics.go:58
  diagnostic_summary=
  | creating Host Pool (Subscription: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  | Resource Group Name: "rgAM-DaaS-Dev"
  | Host Pool Name: "vdpoolXYZscus-Testing-Dev"): unexpected status 400 with error: 400: ActivityId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Error: Agent update UseSessionHostLocalTime must be set., MaintenanceWindows must have one MaintenanceWindow set.
   @module=sdk.proto tf_rpc=ApplyResourceChange tf_proto_version=5.4 tf_provider_addr=provider tf_resource_type=azurerm_virtual_desktop_host_pool diagnostic_detail="" diagnostic_severity=ERROR tf_req_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx timestamp=2023-11-13T17:31:33.965Z

Expected Behaviour

"agentUpdate":{"type":"Scheduled"} is expected to specify required attributes UseSessionHostLocalTime and MaintenanceWindows per error message.

Actual Behaviour

The Terraform plan correctly shows the intended scheduled update configuration. image

This looks to be the PUT request with incompletely formed agentUpdate attribute:

PUT /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rgAM-DaaS-Dev/providers/Microsoft.DesktopVirtualization/hostPools/vdpoolXYZscus-Testing-Dev?api-version=2022-02-10-preview HTTP/1.1
{"location":"southcentralus","properties":{"agentUpdate":{"type":"Scheduled"},"customRdpProperty":"...","description":"TESTING","friendlyName":"TESTING","hostPoolType":"Pooled","loadBalancerType":"BreadthFirst","maxSessionLimit":1,"personalDesktopAssignmentType":"","preferredAppGroupType":"Desktop","startVMOnConnect":false,"validationEnvironment":true},"tags":{"CostCenter":"CostCenter","Department":"Department","Description":"Description","ManagedBy":"ManagedBy","Orchestrator":"Terraform"}}

Applying returns an HTTP 400 from Azure with message "Error: Agent update UseSessionHostLocalTime must be set., MaintenanceWindows must have one MaintenanceWindow set."

Steps to Reproduce

  1. Apply a new host pool with scheduled update block. Observe error.
  2. Comment out the scheduled update block and apply. Observe creation succeeded.
  3. Uncomment out the block (with no modification) and observe the plan to modify in-place to add scheduled updates. Apply the plan and observe successful update in-place.

Important Factoids

No response

References

API Reference: https://learn.microsoft.com/en-us/rest/api/desktopvirtualization/host-pools/create-or-update?view=rest-desktopvirtualization-2022-02-10-preview&tabs=HTTP#agentupdateproperties Related Feature Request: https://github.com/hashicorp/terraform-provider-azurerm/issues/16542 Related PR: https://github.com/hashicorp/terraform-provider-azurerm/pull/17489

FalcoSuessgott commented 7 months ago

Hi, it works with use_session_hosts_timezone=false:

resource "azurerm_virtual_desktop_host_pool" "this" {
  name          = var.name

  type                     = "Pooled"
  load_balancer_type       = "DepthFirst"
  validate_environment     = false
  maximum_sessions_allowed = 2
  start_vm_on_connect      = true

  resource_group_name = var.resource_group
  location            = var.location

  scheduled_agent_updates {
    enabled                   = true
    timezone                  = "UTC"
    use_session_host_timezone = false

    dynamic "schedule" {
      for_each = var.agent_update_maintenance_window

      content {
        day_of_week = schedule.value["day_of_week"]
        hour_of_day = schedule.value["hour_of_day"]
      }
    }
  }

  custom_rdp_properties = try(join(";", var.custom_rdp_properties), null)

  tags = var.tags
}

see: https://github.com/hashicorp/terraform-provider-azurerm/blob/03e49514b01ebfe11bf7c430f834b2c901991e12/internal/services/desktopvirtualization/virtual_desktop_host_pool_resource.go#L435

I dont know if its supposed to be like this tho ...