Terraform-provider-azurerm: New resouce/feature. Link a azurerm schedule with a runbook

Created on 20 Sep 2018  ·  13Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Hi team,
This request comes from the following thread #1711

From powershell it is possible to link runbooks with a schedule created in an automation account, as suggested @holmesb.
With terraform I can not find any resource that can do it.

To be able to close the minimum cycle of possibilities that an automation account allows, I think it is necessary to have this resource available,

  • Create automation account
  • Create runbooks
  • Create schedule
  • Create link between runbook and schedule
  • To future, others features
new-resource servicautomation upstream-microsoft

Most helpful comment

As a workaround, I have used "azurerm_template_deployment" resource to implement this functionality, here is a code that works completely fine for me:

resource "random_uuid" "test" { }

resource "azurerm_template_deployment" "template_deployment" {
  name                = "DeploymentTemplateName"
  resource_group_name = "${data.azurerm_resource_group.example.name}"
  deployment_mode     = "Incremental"
  template_body = <<DEPLOY
{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Automation/automationAccounts/jobSchedules",
      "apiVersion": "2015-10-31",
      "name": "${azurerm_automation_account.example.name}/${random_uuid.test.result}",      
      "properties": {
          "runbook": {
              "name": "${azurerm_automation_runbook.example.name}"
          },
          "schedule": {
              "name": "${azurerm_automation_schedule.hour.name}"
          }
      }
    }
  ]
}
DEPLOY
}

Do let me know if this helps!
Cheers!

All 13 comments

:(

I was a bit curious why this wasn't supported, as well. I suppose the best we can do at this point, is to add a :+1: and a me too

I've had a go at fleshing out the required resource.

New or Affected Resource(s)

  • azurerm_automation_job_schedule

Potential Terraform Configuration

resource "azurerm_automation_job_schedule" "example" {
    name = "${azurerm_automation_schedule.my_schedule.name}"
    runbook = "${azurerm_automation_runbook.my_runbook.name}"
    parameters {
        foo = "bar"
        baz = "thing"      
    }
}
  • parameters is optional and could potentially be called runbook_parameters
  • jobScheduleId could be an attribute of the resource.

Subscribed to get to know when will be available. Very useful feature.

Opened a PR to add this resource as I'm needing this (and a few other automation resources) myself.

Watching this one closely as this would be a very useful addition to the automation suite.

Also watching for a solution for this issue

@odee30 @ @Matasiete this is currently blocked on an upstream issue with the API

That's a shame. Thanks for checking it out @katbyte

As a workaround, I have used "azurerm_template_deployment" resource to implement this functionality, here is a code that works completely fine for me:

resource "random_uuid" "test" { }

resource "azurerm_template_deployment" "template_deployment" {
  name                = "DeploymentTemplateName"
  resource_group_name = "${data.azurerm_resource_group.example.name}"
  deployment_mode     = "Incremental"
  template_body = <<DEPLOY
{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Automation/automationAccounts/jobSchedules",
      "apiVersion": "2015-10-31",
      "name": "${azurerm_automation_account.example.name}/${random_uuid.test.result}",      
      "properties": {
          "runbook": {
              "name": "${azurerm_automation_runbook.example.name}"
          },
          "schedule": {
              "name": "${azurerm_automation_schedule.hour.name}"
          }
      }
    }
  ]
}
DEPLOY
}

Do let me know if this helps!
Cheers!

In addition to what @pranavdesai1900 has posted, if it happens that you get an error like this one:

    404 - File or directory not found.     

404 - File or directory not found.

The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Is probably because you want to use a fancy name for the resource. This Azure API really likes this form (with the uuid):

"name": "${azurerm_automation_account.example.name}/${random_uuid.test.result}",

This has been released in version 1.36.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 1.36.0"
}
# ... other configuration ...

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings