This Terraform module manage autoscaling configuration on a given Azure resource.
This module comes with a default profile working with Virtual Machine Scale Sets and App Service Plans based on Azure Monitor CPU and memory metrics. Also, this module allows to override it with custom profiles and rules.
Module version | Terraform version | OpenTofu version | AzureRM version |
---|---|---|---|
>= 8.x.x | Unverified | 1.8.x | >= 4.0 |
>= 7.x.x | 1.3.x | >= 3.0 | |
>= 6.x.x | 1.x | >= 3.0 | |
>= 5.x.x | 0.15.x | >= 2.0 | |
>= 4.x.x | 0.13.x / 0.14.x | >= 2.0 | |
>= 3.x.x | 0.12.x | >= 2.0 | |
>= 2.x.x | 0.12.x | < 2.0 | |
< 2.x.x | 0.11.x | < 2.0 |
If you want to contribute to this repository, feel free to use our pre-commit git hook configuration which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.
More details are available in the CONTRIBUTING.md file.
This module is optimized to work with the Claranet terraform-wrapper tool
which set some terraform variables in the environment needed by this module.
More details about variables set by the terraform-wrapper
available in the documentation.
module "linux_scaleset" {
source = "claranet/linux-scaleset/azurerm"
version = "x.x.x"
client_name = var.client_name
environment = var.environment
stack = var.stack
location = module.azure_region.location
location_short = module.azure_region.location_short
resource_group_name = module.rg.name
admin_username = "myusername"
ssh_public_key = var.ssh_public_key
vm_size = "Standard_B2s"
subnet = {
id = module.subnet.id
}
source_image_reference = {
publisher = "Debian"
offer = "debian-10"
sku = "10"
version = "latest"
}
azure_monitor_data_collection_rule = {
id = module.run.data_collection_rule_id
}
identity = {
type = "SystemAssigned"
}
}
module "autoscale" {
source = "claranet/autoscale/azurerm"
version = "x.x.x"
client_name = var.client_name
environment = var.environment
stack = var.stack
location = module.azure_region.location
location_short = module.azure_region.location_short
resource_group_name = module.rg.name
target_resource_id = module.linux_scaleset.id
profile = {
"default" = {
capacity = {
default = 2
minimum = 2
maximum = 5
}
rules = [
{
metric_trigger = {
metric_name = "Percentage CPU"
metric_resource_id = module.linux_scaleset.id
time_grain = "PT1M"
time_window = "PT5M"
time_aggregation = "Average"
statistic = "Average"
operator = "GreaterThanOrEqual"
threshold = 75
metric_namespace = "microsoft.compute/virtualmachinescalesets"
}
scale_action = {
direction = "Increase"
type = "ChangeCount"
value = "1"
cooldown = "PT1M"
}
},
{
metric_trigger = {
metric_name = "Percentage CPU"
metric_resource_id = module.linux_scaleset.id
time_grain = "PT1M"
time_window = "PT5M"
time_aggregation = "Average"
statistic = "Average"
operator = "LessThan"
threshold = 25
metric_namespace = "microsoft.compute/virtualmachinescalesets"
}
scale_action = {
direction = "Decrease"
type = "ChangeCount"
value = "1"
cooldown = "PT1M"
}
}
]
}
}
notification = {
email = {
custom_emails = ["[email protected]"]
}
}
logs_destinations_ids = [module.run.log_analytics_workspace_id]
}
Name | Version |
---|---|
azurecaf | ~> 1.2.28 |
azurerm | ~> 4.0 |
Name | Source | Version |
---|---|---|
diagnostics | claranet/diagnostic-settings/azurerm | ~> 8.0.0 |
Name | Type |
---|---|
azurerm_monitor_autoscale_setting.main | resource |
azurecaf_name.autoscale | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
autoscale_enabled | Specifies whether automatic scaling is enabled for the target resource. | bool |
true |
no |
client_name | Client name/account used in naming. | string |
n/a | yes |
custom_name | Custom name for Autoscale setting, generated if not set. | string |
"" |
no |
default_tags_enabled | Option to enable or disable default tags. | bool |
true |
no |
diagnostic_settings_custom_name | Custom name of the diagnostics settings, name will be 'default' if not set. | string |
"default" |
no |
environment | Project environment. | string |
n/a | yes |
extra_tags | Additional tags to associate with your autoscale setting. | map(string) |
{} |
no |
location | Azure location/region to use. | string |
n/a | yes |
location_short | Short string for Azure location. | string |
n/a | yes |
logs_categories | Log categories to send to destinations. | list(string) |
null |
no |
logs_destinations_ids | List of destination resources IDs for logs diagnostic destination. Can be Storage Account , Log Analytics Workspace and Event Hub . No more than one of each can be set.If you want to use Azure EventHub as a destination, you must provide a formatted string containing both the EventHub Namespace authorization send ID and the EventHub name (name of the queue to use in the Namespace) separated by the | character. |
list(string) |
n/a | yes |
logs_metrics_categories | Metrics categories to send to destinations. | list(string) |
null |
no |
name_prefix | Optional prefix for the generated name. | string |
"" |
no |
name_suffix | Optional suffix for the generated name. | string |
"" |
no |
notification | Manage emailing and webhooks for sending notifications. | object({ |
null |
no |
profile | One or more (up to 20) autoscale profile blocks. | map(object({ |
n/a | yes |
resource_group_name | Custom resource group name to attach autoscale configuration to. Target resource group by default. | string |
null |
no |
stack | Project stack name. | string |
n/a | yes |
target_resource_id | ID of the resource to apply the autoscale setting to. | string |
n/a | yes |
Name | Description |
---|---|
id | ID of the Azure Autoscale setting. |
module_diagnostics | Diagnostics Settings module output. |
name | Name of the Azure Autoscale setting. |
resource | Azure Autoscale setting resource object. |
Microsoft Azure documentation - Virtual Machine Scale Sets Autoscale: docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-autoscale-overview
Microsoft Azure documentation - App Services Autoscale: docs.microsoft.com/en-us/azure/app-service/manage-scale-up
Microsoft Azure documentation - Metrics supported: docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported