Skip to content

claranet/terraform-azurerm-automation-stop-start

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Stop/Start with Automation

Changelog Notice Apache V2 License OpenTofu Registry

Azure module to deploy an Azure Stop/Start workbook with an Automation Account.

Supported Azure resources which can be managed by this module:

  • Azure Virtual Machine (both Linux or Windows)
  • Azure Kubernetes Cluster
  • Azure MySQL Flexible Server

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

Usage

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.

⚠️ Since modules version v8.0.0, we do not maintain/check anymore the compatibility with Hashicorp Terraform. Instead, we recommend to use OpenTofu.

locals {
  mysql_id = "/subscriptions/12345678-abcd-1111-2222-000000000000/resourceGroups/rg-app-dha-dev/providers/Microsoft.DBforMySQL/flexibleServers/mydha"
  vm_id    = "/subscriptions/12345678-abcd-1111-2222-000000000000/resourceGroups/dha-test/providers/Microsoft.Compute/virtualMachines/dhavm"
  aks_id   = "/subscriptions/12345678-abcd-1111-2222-000000000000/resourcegroups/rg-kub-dha-dev/providers/Microsoft.ContainerService/managedClusters/aks-kub-dha-euw-dev"
}

module "stop_start" {
  source  = "claranet/automation-stop-start/azurerm"
  version = "x.x.x"

  resource_group_name = module.rg.resource_group_name
  client_name         = var.client_name
  location            = module.azure_region.location
  location_short      = module.azure_region.location_short
  location_cli        = module.azure_region.location_cli
  environment         = var.environment
  stack               = var.stack

  automation_account = {
    id = module.run.automation_account_id
  }

  schedules = {
    start = {
      action = "start",
      schedule_days = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
      ],
      schedule_hours    = 20,
      schedule_minutes  = 54,
      schedule_timezone = "Romance Standard Time",
      target_resource_ids = [
        local.mysql_id,
        local.vm_id,
        local.aks_id
      ],

    }
    stop = {
      action = "stop",
      schedule_days = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
      ],
      schedule_hours    = 21,
      schedule_minutes  = 02,
      schedule_timezone = "Romance Standard Time",
      target_resource_ids = [
        local.mysql_id,
        local.vm_id,
        local.aks_id
      ],
    }
  }

  logs_destinations_ids = [
    module.run.logs_storage_account_id,
    module.run.log_analytics_workspace_id
  ]

  extra_tags = {
    foo = "bar"
  }
}

resource "azurerm_role_assignment" "automation_vm" {
  scope                = local.vm_id
  role_definition_name = "Virtual Machine Contributor"
  principal_id         = module.stop_start.identity_principal_id
}

resource "azurerm_role_assignment" "automation_mysql" {
  scope                = local.mysql_id
  role_definition_name = "Contributor"
  principal_id         = module.stop_start.identity_principal_id
}

resource "azurerm_role_assignment" "automation_aks" {
  scope                = local.aks_id
  role_definition_name = "Contributor"
  principal_id         = module.stop_start.identity_principal_id
}

Providers

Name Version
azapi ~> 1.13
azurecaf ~> 1.2.28
azurerm ~> 3.100
local ~> 2.4

Modules

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

Resources

Name Type
azapi_resource.automation_connection resource
azapi_update_resource.workflow_init resource
azapi_update_resource.workflow_update resource
azurerm_automation_account.main resource
azurerm_automation_runbook.start_stop resource
azurerm_logic_app_workflow.main resource
azurerm_role_assignment.main resource
azurecaf_name.api_connection data source
azurecaf_name.automation data source
azurecaf_name.runbook data source
azurecaf_name.workflow data source
azurerm_resource_group.main data source
azurerm_subscription.main data source
local_file.start_stop data source

Inputs

Name Description Type Default Required
api_connection_custom_name Custom api connection account name, generated if not set. string "" no
automation_account The ID of the existing Automation Account. If null is specified, a new Automation Account will be created.
object({
id = string
})
null no
client_name Client name/account used in naming. string n/a yes
custom_name Custom automation account name, 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 add on resources. map(string) {} no
identity Identity block information.
object({
type = optional(string, "SystemAssigned")
identity_ids = optional(list(string))
})
{} no
location Azure region to use. string n/a yes
location_cli Short string for Azure location in CLI format. 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
rbac_assignment_enabled Enable RBAC assignment, allows Automation Account to trigger Logic App. bool true no
resource_group_name Name of the resource group. string n/a yes
runbook_custom_name Custom runbook name, generated if not set. string "" no
schedules Schedules
map(
object({
action = string
schedule_days = list(string)
schedule_hours = number
schedule_minutes = number
schedule_timezone = string
target_resource_ids = list(string)
})
)
n/a yes
sku_name The SKU name of the Automation Account. string "Basic" no
stack Project stack name. string n/a yes
workflow_custom_name Custom workflow name, generated if not set. string "" no

Outputs

Name Description
id Azure Stop/Start with Automation ID.
identity_principal_id Azure Stop/Start with Automation system identity principal ID.
module_diagnostics Diagnostics settings module outputs.
name Azure Stop/Start with Automation name.
resource Azure Stop/Start with Automation resource object.

Related documentation