/terraform-shell-azure-devops-elasticpool

Terraform Azure DevOps Scale Set Agent module

Primary LanguageShellMIT LicenseMIT

terraform-shell-azure-devops-elasticpool

GitHub Super-Linter

Azure DevOps VM Scale Set Elasticpool Terraform module.

Due to the fact that creating an Agent Pool - Azure virtual machine scale set is currently blocked due to not being supported by the SDK used by the Azure DevOps Terraform Provider, this module uses the Terraform shell provider as a workaround.

This module is used by the terraform-azurerm-vmss-devops-agent to create the Azure DevOps Scale Set elasticpool side of a self-hosted Azure DevOps Scale Set agent pool.

Requirements

  • An Azure subscription. Note: you can get started with a Azure free account

  • An Azure DevOps Organization. Note: you can sign up for free in the preceding link.

  • An Azure Virtual Machine Scale Set. Note: a test can can be created by using the terraform-azurerm-vmss example

  • An Azure service connection to the subscription where your Azure Virtual Machine Scale Set is located.

  • An Azure DevOps project.

  • An Azure DevOps Personal Access Token(PAT) created with at least Agent Pools (Read & manage) and Service Connections (Read & query) permissions.

  • A Linux based system is required to execute this Terraform module, with the following commands installed:

    • cat
    • curl
    • sed
    • jq

The PAT needs be passed to the Terraform configuration by any standard mechanism, for example:

 export AZURE_DEVOPS_EXT_PAT="ckusfcc8ope2soot1yuovmdvlgtfgj9nio2orfwyvv5jsgcnwwga"
export TF_VAR_ado_ext_pat="$AZURE_DEVOPS_EXT_PAT"

Note: The PAT is used for the initial creation of the agent pool and for subsequent Terraform operations. Therefore, it would be advisable to create/use a service account for this rather than a standard user account.

Basic example

provider "azurerm" {
  features {}
}

provider "shell" {
  sensitive_environment = {
    AZURE_DEVOPS_EXT_PAT = var.ado_ext_pat
  }
}

data "azurerm_virtual_machine_scale_set" "ado_pool" {
  name                = var.vmss_name
  resource_group_name = var.vmss_resource_group_name
}

module "azure-devops-elasticpool" {
  source                 = "tonyskidmore/azure-devops-elasticpool/shell"
  version                = "0.4.4"
  ado_org                = var.ado_org
  ado_project            = var.ado_project
  ado_service_connection = var.ado_service_connection
  ado_pool_name          = var.ado_pool_name
  ado_pool_desired_idle  = var.ado_pool_desired_idle
  ado_vmss_id            = data.azurerm_virtual_machine_scale_set.ado_pool.id
}

Resources

Name Type
shell_script.ado_vmss_pool resource

Inputs

Name Description Type Default Required
ado_dirty Azure DevOps pool settings are dirty bool false no
ado_org Azure DevOps Organization name string n/a yes
ado_pool_auth_all_pipelines Setting to determine if all pipelines are authorized to use this TaskAgentPool by default (at create only) string "True" no
ado_pool_auto_provision_projects Setting to automatically provision TaskAgentQueues in every project for the new pool (at create only) string "True" no
ado_pool_desired_idle Number of machines to have ready waiting for jobs number 0 no
ado_pool_desired_size The desired size of the pool number 0 no
ado_pool_max_capacity Maximum number of machines that will exist in the elastic pool number 2 no
ado_pool_max_saved_node_count Keep machines in the pool on failure for investigation number 0 no
ado_pool_name Azure DevOps agent pool name string "azdo-vmss-pool-001" no
ado_pool_os_type Operating system type of the nodes in the pool string "linux" no
ado_pool_recycle_after_use Discard machines after each job completes bool false no
ado_pool_sizing_attempts The number of sizing attempts executed while trying to achieve a desired size number 0 no
ado_pool_ttl_mins The minimum time in minutes to keep idle agents alive number 30 no
ado_project Azure DevOps project name where service connection exists and optionally where pool will only be created string n/a yes
ado_project_only Only create the agent pool in the Azure DevOps pool specified? (at create only) string "False" no
ado_service_connection Azure DevOps azure service connection name string n/a yes
ado_vmss_id Azure Virtual Machine Scale Set Resource ID if not created by the module string "" no
http_connect_timeout The maximum time in seconds before timing out a connection to the Azure DevOps REST API number 20 no
http_max_time The maximum amount of time in seconds for an Azure DevOps REST API operation to complete number 120 no
http_retries The number of retries make to the Azure DevOps REST API number 10 no
http_retries_max_time The maximum time in seconds for the retry period for a connection to the Azure DevOps REST API number 120 no
http_retry_delay The maximum time in seconds to delay before retrying a connection to the Azure DevOps REST API number 3 no

Outputs

Name Description
ado_vmss_pool_output Azure DevOps VMSS Agent Pool output

Providers

Name Version
shell 1.7.10

Troubleshooting

If an error occurs when running the module and the error is not immediately obvious then enabling a trace log prior to running the module can help to troubleshoot:

export TF_LOG=TRACE
export TF_LOG_PATH="./trace.log"

After enabling the trace log and recreating the issue look in the trace.log file and search for [DEBUG] Starting execution.... Hopefully the additional output will provide additional information to help determine the underlying cause.