Skip to content

Instantly share code, notes, and snippets.

@arcotek-ltd
Last active April 23, 2020 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arcotek-ltd/389d3d74572ac1b1f74038c429a0c8c6 to your computer and use it in GitHub Desktop.
Save arcotek-ltd/389d3d74572ac1b1f74038c429a0c8c6 to your computer and use it in GitHub Desktop.
azurerm_automation_runbook
"automation_account_data" : {
"0" : [
{
"sku_name" : "Basic",
"custom_tags" : {
"purpose" : "Does something",
"createdBy" : "John Smith"
},
"modules" : [
{
"name" : "Az.Accounts",
"uri" : "https://psg-prod-eastus.azureedge.net/packages/az.accounts.1.7.3.nupkg"
}
],
"runbooks" : [
{
"name" : "myScript",
"description" : "Does something",
"type" : "PowerShell",
"uri" : "https://foo.blob.core.windows.net/runbooks/myScript.ps1",
"custom_tags" : {
"purpose" : "Does something",
"createdBy" : "John Smith"
}
}
]
}
]
}
# #################################################################################################
# LOCALS
# #################################################################################################
locals {
resource_data = flatten([
for product_key, product in var.automation_account_data : [
for resource_key, resource in product : [
for runbook in resource.runbooks : {
name = runbook.name
description = runbook.description
uri = runbook.uri
type = runbook.type
id = "${product_key}.${resource_key}"
automation_account_name = var.automation_account_object.object["${product_key}.${resource_key}"].name
resource_group_name = var.automation_account_object.object["${product_key}.${resource_key}"].resource_group_name
location = var.automation_account_object.object["${product_key}.${resource_key}"].location
}
]
]
])
}
# #################################################################################################
# RESOURCES
# #################################################################################################
resource "azurerm_automation_runbook" "pool" {
for_each = {
for resource in local.resource_data :
resource.id => resource
}
name = each.value.name
description = each.value.location
automation_account_name = each.value.automation_account_name
resource_group_name = each.value.resource_group_name
location = each.value.location
runbook_type = each.value.type
log_verbose = true
log_progress = true
publish_content_link {
uri = each.value.uri
}
#content = ""
}
#Relevant section
module "automation_runbook" {
source = "../azurerm_automation_runbook"
resource_group_object = module.resource_group
automation_account_object = module.automation_account
automation_account_data = var.automation_account_data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment