fortytwoservices / terraform-azurerm-selfhostedrunnervmss

Module for creating a simple virtual machine scale set for Azure DevOps and GitHub self hosted runners
MIT License
2 stars 2 forks source link

Self Hosted Runners Virtual Machine Scale Set

:exclamation: NB!
Due to the renaming of Company, the Github organization has changed name from "amestofortytwo" to "fortytwoservices". Pre-existing Terraform code would need to change that in code.

This module deploys a virtual machine scale set for self hosted runners for Azure DevOps and GitHub.

provider "azurerm" {
  features {}
}

module "vmss" {
  source                         = "fortytwoservices/selfhostedrunnervmss/azurerm"
  operating_system               = "ubuntu"       # windows or ubuntu
  runner_platform                = "azure_devops" # azure_devops or github
}

After deploying the virtual machine scale set, you need to configure the Azure DevOps or GitHub side of things according to our documentation:

Requirements

The following requirements are needed by this module:

Examples

Basic example

terraform {
  required_version = ">=1.4.6"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">=3.100.0"
    }
  }
}

provider "azurerm" {
  features {}
}

module "vmss" {
  source               = "fortytwoservices/selfhostedrunnervmss/azurerm"
  version              = "1.6.0"
  operating_system     = "ubuntu"       # windows or ubuntu
  runner_platform      = "azure_devops" # azure_devops or github
  deploy_load_balancer = true
}

output "password" {
  value = nonsensitive(module.vmss.password)
}

Advanced Example

terraform {
  required_version = ">=1.4.6"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = ">=3.100.0"
    }
  }
}

provider "azurerm" {
  features {}
}

# Create custom rg
resource "azurerm_resource_group" "rg" {
  location = "westeurope"
  name     = "runners"
}

# Create custom vnet
resource "azurerm_virtual_network" "vmss" {
  name                = "runner-network"
  address_space       = ["10.0.0.0/24"]
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_subnet" "vmss" {
  name                 = "vmss"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vmss.name
  address_prefixes     = azurerm_virtual_network.vmss.address_space
}

module "vmss" {
  source                          = "fortytwoservices/selfhostedrunnervmss/azurerm"
  version                         = "1.6.0"
  operating_system                = "ubuntu"       # windows or ubuntu
  runner_platform                 = "azure_devops" # azure_devops or github
  resource_group_name             = azurerm_resource_group.rg.name
  use_existing_resource_group     = true
  location                        = azurerm_resource_group.rg.location
  virtual_machine_scale_set_name  = "runners"
  sku                             = "Standard_D2s_v3"
  ssh_public_keys                 = ["ssh-rsa AAAAB3NzaC1yc2EAAAADA....QFv2PJ0= marius@42device"]
  subnet_id                       = azurerm_subnet.vmss.id
  use_custom_subnet               = true
  vmss_encryption_at_host_enabled = true
}

output "password" {
  value = nonsensitive(module.vmss.password)
}

Providers

The following providers are used by this module:

Resources

The following resources are used by this module:

Required Inputs

No required inputs.

Optional Inputs

The following input variables are optional (have default values):

deploy_load_balancer

Description: (Optional) When using the built-in network (use_custom_subnet is false), should we create a NAT gateway? This will be required in the future. Defaults to false.

Type: bool

Default: false

enable_accelerated_networking

Description: (Optional) Does this Network Interface support Accelerated Networking? Possible values are true and false. Defaults to false.

Type: bool

Default: false

enable_automatic_instance_repair

Description: Enable automatic instance repair for the VMSS. This will automatically repair instances that fail health checks.

Type: bool

Default: false

enable_termination_notifications

Description: Enable termination notifications for the VMSS. This will send a notification to the Azure Instance Metadata Service (IMDS) when the VMSS is scheduled for maintenance or when the VMSS is deleted.

Type: bool

Default: false

identity

Description: (Optional) If SystemAssigned, UserAssigned or both should be enabled for the Virtual Machine Scale Set

Type:

object({
    type         = string
    identity_ids = optional(list(string))
  })

Default: null

load_balancer_backend_address_pool_id

Description: (Optional) Value of the backend address pool id to use for the load balancer. I.e. for static outbound NAT.

Type: string

Default: ""

location

Description: The Azure region to create the scale set in

Type: string

Default: "westeurope"

network_security_group_id

Description: (Optional) Use an existing network security group on the VMSS network interface card. Defaults to null.

Type: string

Default: null

operating_system

Description: The OS of the runners

Type: string

Default: "ubuntu"

password

Description: Password of the local user acocunt

Type: string

Default: null

resource_group_name

Description: The resource group name to create

Type: string

Default: "self-hosted-runners"

runner_platform

Description: Whether it is github or azure_devops used for runners

Type: string

Default: "azure_devops"

scale_in

Description: object({
force_deletion_enabled = (Optional) If true, the VMSS will force delete the VM instance when it is being scaled in. Defaults to false.
rule = (Optional) Scale-in policy for the VMSS. If not provided, the default scale-in policy will be used. Possible values are Default, NewestVM, OldestVM, and Custom. Defaults to Default. })

Type:

object({
    force_deletion_enabled = optional(bool, false)
    rule                   = optional(string, "Default")
  })

Default: null

sku

Description: The sku to create virtual machines with

Type: string

Default: "Standard_D2s_v3"

ssh_public_keys

Description: n/a

Type: list(string)

Default: []

subnet_id

Description: When provided, this subnet will be used for the scale set, rather than creating a new virtual network and subnet

Type: string

Default: null

tags

Description: n/a

Type: map(any)

Default: {}

use_custom_subnet

Description: Set to true if subnet_id is provided in order to actually use it (works around a TF issue)

Type: bool

Default: false

use_existing_resource_group

Description: Whether to use an existing resource group or not

Type: bool

Default: false

username

Description: Username of the local user account

Type: string

Default: "runneradmin"

virtual_machine_scale_set_name

Description: n/a

Type: string

Default: "self-hosted-runners"

vmss_encryption_at_host_enabled

Description: Enables encryption at host for the VMSS virtual machines. In order to use this option, the EncryptionAtHost feature must be enabled for Microsoft.Compue resource provider must be enabled for the subscription. To enable, use this PowerShell command: Register-AzProviderFeature -FeatureName 'EncryptionAtHost' -ProviderNamespace 'Microsoft.Compute'.

Type: bool

Default: false

Outputs

The following outputs are exported:

password

Description: n/a

subnet_id

Description: n/a

virtual_machine_scale_set_id

Description: n/a

virtual_machine_scale_set_identity_principal_id

Description: n/a

Modules

No modules.