Skip to content

Latest commit

 

History

History
110 lines (87 loc) · 4.43 KB

File metadata and controls

110 lines (87 loc) · 4.43 KB

Azure Automation Runbook Terraform module

Terraform module for creation Azure Automation Runbook

Usage

locals {
  current_date_plus_one_day = substr(timeadd(timestamp(),"24h"),0,10)
  
  automation_runbook = {
    
    # Runbook Parameters
    runbook : {
      name        = "VMStartStop"
      description = "Example VM Start/Stop script"
      content = templatefile("../scripts/vm_stop.tftpl", {
        name            = "VMStartStop"
        vm_id           = data.azurerm_virtual_machine.example.id
        subscription_id = data.azurerm_client_config.current.subscription_id
      })
    }
    
    # Parameters of Runbook's Schedules to create
    schedules : [{
      name       = "StartVM"
      start_time = format("%sT09:00:00Z", local.current_date_plus_one_day)
      parameters = {
        action = "start"
      }
    }, {
      name       = "StopVM"
      start_time = format("%sT09:00:00Z", local.current_date_plus_one_day)
      parameters = {
        action = "stop"
      }
    }]
  }
}

data "azurerm_virtual_machine" "example" {
  name                = "vm"
  resource_group_name = "example"
}

data "azurerm_automation_account" "example" {
  name                = "example"
  resource_group_name = "example"
}

module "automation-runbook" {
  source   = "data-platform-hq/automation-runbook/azurerm"
  version  = "~> 1.0"

  project                 = var.project
  env                     = var.env
  location                = var.location
  resource_group          = data.azurerm_automation_account.example.resource_group_name
  automation_account_name = data.azurerm_automation_account.example.name

  runbook  = local.automation_runbook.runbook
  schedule = local.automation_runbook.schedules
}

Requirements

Name Version
terraform >= 1.0.0
azurerm >= 4.0.1

Providers

Name Version
azurerm >= 4.0.1

Modules

No modules.

Resources

Name Type
azurerm_automation_job_schedule.this resource
azurerm_automation_runbook.this resource
azurerm_automation_schedule.this resource

Inputs

Name Description Type Default Required
automation_account_name Automation Account name string n/a yes
location Azure location string n/a yes
resource_group Resource group name where Automation Account is located string n/a yes
runbook Objects with parameters to configure Runbook
object({
name = optional(string),
description = optional(string),
script_path = optional(string),
content = optional(string)
log_verbose = optional(bool, true),
log_progress = optional(bool, true),
runbook_type = optional(string, "PowerShellWorkflow")
})
n/a yes
schedules Set of objects with parameters to configure Schedules for Runbook
set(object({
name = optional(string),
description = optional(string),
frequency = optional(string, "Week"),
interval = optional(string, "1"),
start_time = optional(string, null),
week_days = optional(list(string), ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"])
parameters = optional(any, {})
}))
[] no
tags Resource tags map(any) {} no

Outputs

Name Description
runbook_id Automation Runbook Id

License

Apache 2 Licensed. For more information please see LICENSE