An open API service indexing awesome lists of open source software.

https://github.com/claranet/terraform-azurerm-autoscale

Terraform module for Azure Autoscale
https://github.com/claranet/terraform-azurerm-autoscale

azure claranet module terraform

Last synced: about 2 months ago
JSON representation

Terraform module for Azure Autoscale

Awesome Lists containing this project

README

        

# Azure Autoscale
[![Changelog](https://img.shields.io/badge/changelog-release-green.svg)](CHANGELOG.md) [![Notice](https://img.shields.io/badge/notice-copyright-blue.svg)](NOTICE) [![Apache V2 License](https://img.shields.io/badge/license-Apache%20V2-orange.svg)](LICENSE) [![OpenTofu Registry](https://img.shields.io/badge/opentofu-registry-yellow.svg)](https://search.opentofu.org/module/claranet/autoscale/azurerm/)

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.

## Global versioning rule for Claranet Azure modules

| 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 |

## Contributing

If you want to contribute to this repository, feel free to use our [pre-commit](https://pre-commit.com/) 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](./CONTRIBUTING.md#pull-request-process) file.

## Usage

This module is optimized to work with the [Claranet terraform-wrapper](https://github.com/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](https://github.com/claranet/terraform-wrapper#environment).

⚠️ Since modules version v8.0.0, we do not maintain/check anymore the compatibility with
[Hashicorp Terraform](https://github.com/hashicorp/terraform/). Instead, we recommend to use [OpenTofu](https://github.com/opentofu/opentofu/).

```hcl
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]
}
```

## Providers

| Name | Version |
|------|---------|
| azurecaf | ~> 1.2.28 |
| azurerm | ~> 4.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| diagnostics | claranet/diagnostic-settings/azurerm | ~> 8.0.0 |

## Resources

| Name | Type |
|------|------|
| [azurerm_monitor_autoscale_setting.main](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_autoscale_setting) | resource |
| [azurecaf_name.autoscale](https://registry.terraform.io/providers/claranet/azurecaf/latest/docs/data-sources/name) | data source |

## Inputs

| 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({
email = optional(object({
send_to_subscription_administrator = optional(bool, false)
send_to_subscription_co_administrator = optional(bool, false)
custom_emails = optional(list(string))
}))
webhooks = optional(list(object({
service_uri = string
properties = optional(map(string))
})), [])
})
| `null` | no |
| profile | One or more (up to 20) autoscale profile blocks. |
map(object({
capacity = object({
default = number
minimum = optional(number, 1)
maximum = optional(number, 5)
})
rules = optional(list(object({
metric_trigger = object({
metric_name = string
metric_resource_id = string
operator = string
statistic = string
time_aggregation = string
time_grain = string
time_window = string
threshold = number
metric_namespace = optional(string)
divide_by_instance_count = optional(bool)
dimensions = optional(list(object({
name = string
operator = string
values = list(string)
})), [])
})
scale_action = object({
cooldown = string
direction = string
type = string
value = number
})
})), [])
fixed_date = optional(object({
end = string
start = string
timezone = string
}))
recurrence = optional(object({
timezone = string
days = list(string)
hours = list(number)
minutes = list(number)
}))
}))
| 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 |

## Outputs

| 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. |

## Related documentation

Microsoft Azure documentation - Virtual Machine Scale Sets Autoscale: [docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-autoscale-overview](https://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](https://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](https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported)