Skip to content

claranet/terraform-azurerm-automation-stop-start

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 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 Service 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"

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

  resource_group_name = module.rg.resource_group_name

  automation_account = {
    id = module.run.automation_account_id
  }

  schedules = {
    start = {
      action = "start"
      schedule_days = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
      ]
      schedule_hour     = 20
      schedule_minute   = 54
      schedule_timezone = "Romance Standard Time"
      target_resources_ids = [
        local.mysql_id,
        local.vm_id,
        local.aks_id,
      ]
    }
    stop = {
      action = "stop"
      schedule_days = [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"
      ]
      schedule_hour     = 21
      schedule_minute   = 2
      schedule_timezone = "Romance Standard Time"
      target_resources_ids = [
        local.mysql_id,
        local.vm_id,
        local.aks_id,
      ]
    }
  }

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

  extra_tags = {
    foo = "bar"
  }
}

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

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

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

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.main 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_subscription.main data source
local_file.main data source

Inputs

Name Description Type Default Required
api_connection_custom_name Custom API connection name, generated if not set. string "" no
automation_account The ID of an existing Automation account. If null, 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 diagnostic 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 Map of schedule objects.
map(
object({
action = string
schedule_days = list(string)
schedule_hour = number
schedule_minute = number
schedule_timezone = string
target_resources_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 Automation ID.
identity_principal_id Azure Stop/Start Automation identity principal ID.
module_diagnostics Diagnostic settings module outputs.
name Azure Stop/Start Automation name.
resource Azure Stop/Start with Automation resource object.

About

Terraform module for Azure Automation with a stop/start Runbook

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •