AVD host pool and scaling plan assignment issues

Viewed 9

I am fairly new to Terraform so I'm still learning the more advanced elements of the language.

I have created a template that creates 4 azure virtual desktop host pools. I have also created within the same template scaling plans and was trying to create a for_each loop, on the scaling plan, however when it comes to the hostpool_id requirement on the scaling plan I am not sure how to get it to cycle through the 4 hostpool ids that will be created.

MAIN

#############
# HOSTPOOLS #
#############
resource "azurerm_virtual_desktop_host_pool" "developer_dev" {
    name = var.developer_dev_hostpool.name
    resource_group_name = var.rg_avd_name
    location = var.rg_avd_location
    friendly_name = var.developer_dev_hostpool.friendly_name
    description = var.developer_dev_hostpool.description
    type = var.developer_dev_hostpool.type
    maximum_sessions_allowed = var.developer_dev_hostpool.max_sessions
    load_balancer_type = var.developer_dev_hostpool.lb_type

    scheduled_agent_updates {
      enabled = true
      timezone = "GMT Standard Time"
      schedule {
        day_of_week = "Saturday"
        hour_of_day = "02"
      }
    }
}

resource "azurerm_virtual_desktop_host_pool" "developer_prod" {
    name = var.developer_prod_hostpool.name
    resource_group_name = var.rg_avd_name
    location = var.rg_avd_location
    friendly_name = var.developer_prod_hostpool.friendly_name
    description = var.developer_prod_hostpool.description
    type = var.developer_prod_hostpool.type
    maximum_sessions_allowed = var.developer_prod_hostpool.max_sessions
    load_balancer_type = var.developer_prod_hostpool.lb_type

    scheduled_agent_updates {
      enabled = true
      timezone = "GMT Standard Time"
      schedule {
        day_of_week = "Saturday"
        hour_of_day = "02"
      }
    }
}

resource "azurerm_virtual_desktop_host_pool" "front_office" {
    name = var.front_office_hostpool.name
    resource_group_name = var.rg_avd_name
    location = var.rg_avd_location
    friendly_name = var.front_office_hostpool.friendly_name
    description = var.front_office_hostpool.description
    type = var.front_office_hostpool.type
    maximum_sessions_allowed = var.front_office_hostpool.max_sessions
    load_balancer_type = var.front_office_hostpool.lb_type

    scheduled_agent_updates {
      enabled = true
      timezone = "GMT Standard Time"
      schedule {
        day_of_week = "Saturday"
        hour_of_day = "02"
      }
    }
}

resource "azurerm_virtual_desktop_host_pool" "back_office" {
    name = var.back_office_hostpool.name
    resource_group_name = var.rg_avd_name
    location = var.rg_avd_location
    friendly_name = var.back_office_hostpool.friendly_name
    description = var.back_office_hostpool.description
    type = var.back_office_hostpool.type
    maximum_sessions_allowed = var.back_office_hostpool.max_sessions
    load_balancer_type = var.back_office_hostpool.lb_type

    scheduled_agent_updates {
      enabled = true
      timezone = "GMT Standard Time"
      schedule {
        day_of_week = "Saturday"
        hour_of_day = "02"
      }
    }
}

#################
# SCALING PLANS #
#################
resource "azurerm_virtual_desktop_scaling_plan" "sp_weekdays_developer" {
for_each = var.sp_weekdays
    name = each.value.sp_name
    resource_group_name = var.rg_avd_name
    location = var.rg_avd_location
    friendly_name = each.value.sp_friendly_name
    description = each.value.sp_description
    time_zone = "GMT Standard Time"

    schedule {
      name = each.value.sch_name
      days_of_week = ["Monday","Tuesday","Wednesday","Thursday","Friday"]
      ramp_up_start_time = "07:30"
      ramp_up_load_balancing_algorithm = each.value.lb_alg
      ramp_up_minimum_hosts_percent = each.value.ramp_up_min_hosts
      ramp_up_capacity_threshold_percent = each.value.ramp_up_cap_threshold
      peak_start_time = "08:00"
      peak_load_balancing_algorithm = each.value.lb_alg
      ramp_down_start_time = "18:00"
      ramp_down_load_balancing_algorithm = each.value.lb_alg
      ramp_down_minimum_hosts_percent = "80"
      ramp_down_force_logoff_users = true
      ramp_down_wait_time_minutes = "60"
      ramp_down_notification_message = "Your session will be logged off shortly, please save your work."
      ramp_down_capacity_threshold_percent = "20"
      ramp_down_stop_hosts_when = "ZeroActiveSessions"
      off_peak_start_time = "20:00"
      off_peak_load_balancing_algorithm = each.value.lb_alg
    }

    host_pool {
      hostpool_id = azurerm_virtual_desktop_host_pool.developer_dev.id
      scaling_plan_enabled = true
    }
}

variables

######################
# HOSTPOOL VARIABLES #
######################
variable "developer_dev_hostpool" {
    default = {
        name = "avdhp-developer-dev-uks-001"
        friendly_name = "Developer – Development"
        description = "Hostpool for developers and contractors working in the development environment"
        type = "Pooled"
        max_sessions = "8"
        lb_type = "DepthFirst" 
    }
}

variable "developer_prod_hostpool" {
    default = {
        name = "avdhp-developer-prod-uks-001"
        friendly_name = "Developer – Production"
        description = "Hostpool for developers and contractors working in the production environment"
        type = "Pooled"
        max_sessions = "8"
        lb_type = "DepthFirst"
    }
}

variable "front_office_hostpool" {
    default = {
        name = "avdhp-front-office-uks-001"
        friendly_name = "Front Office"
        description = "Hostpool for front office staff"
        type = "Pooled"
        max_sessions = "16"
        lb_type = "BreadthFirst"
    }
}

variable "back_office_hostpool" {
    default = {
        name = "avdhp-back-office-uks-001"
        friendly_name = "Back Office    "
        description = "Hostpool for back office staff"
        type = "Pooled"
        max_sessions = "12"
        lb_type = "DepthFirst"
    }
}

##########################
# SCALING PLAN VARIABLES #
##########################
variable "sp_weekdays" {
    description = "scaling plan for weekdays"
    default = {
        developer_dev = {
            sp_name = "avdsp1"
            sp_friendly_name = "Developer Weekday Scaling Plan"
            sp_description = "This scaling plan is for the developers during the week."
            sch_name = "Weekdays"
            lb_alg = "DepthFirst"
            ramp_up_min_hosts = "50"
            ramp_up_cap_threshold = "60"
        }
        developer_prod = {
            sp_name = "avdsp3"
            sp_friendly_name = "Developer Weekday Scaling Plan"
            sp_description = "This scaling plan is for the developers during the week."
            sch_name = "Weekdays"
            lb_alg = "DepthFirst"
            ramp_up_min_hosts = "50"
            ramp_up_cap_threshold = "60"
        }
        back_office = {
            sp_name = "avdsp4"
            sp_friendly_name = "Back Office Weekday Scaling Plan"
            sp_description = "This scaling plan is for the back office during the week."
            sch_name = "Weekdays"
            lb_alg = "DepthFirst"
            ramp_up_min_hosts = "50"
            ramp_up_cap_threshold = "60"
        }
        front_office = {
            sp_name = "avdsp5"
            sp_friendly_name = "Front Office Weekday Scaling Plan"
            sp_description = "This scaling plan is for the front office during the week."
            sch_name = "Weekdays"
            lg_alg = "BreadthFirst"
            ramp_up_min_hosts = "30"
            ramp_up_cap_threshold = "75"
        }
    }
}
0 Answers
Related