Learn the

Provision, Secure, Connect, and Run

Any infrastructure for any application


layout: "azurerm" page_title: "Azure Resource Manager: azurerm_scheduler_job" sidebar_current: "docs-azurerm-resource-scheduler-job-x description: |-

» Manages a Scheduler Job.

» azurerm_scheduler_job

Manages a Scheduler Job.

» Example Usage (single web get now)

resource "azurerm_scheduler_job" "web-once-now" {
    name                = "tfex-web-once-now"
    resource_group_name = "${azurerm_resource_group.example.name}"
    job_collection_name = "${azurerm_scheduler_job_collection.example.name}"

    state = "enabled" //re-enable it each run

    action_web {
        url = "http://this.url.fails" //defaults to get
    }

    //default start time is now
}

» Example Usage (recurring daily with retry and basic authentication)

resource "azurerm_scheduler_job" "web-recurring-daily" {
    name                = "tfex-web-recurring-daily"
    resource_group_name = "${azurerm_resource_group.example.name}"
    job_collection_name = "${azurerm_scheduler_job_collection.example.name}"

     action_web {
        url     = "https://this.url.fails"
        method  = "put"
        body    = "this is some text"

        headers = {
            Content-Type = "text"
        }

        authentication_basic {
            username = "login"
            password = "apassword"
        }
    }

    retry {
        interval = "00:05:00" //retry every 5 min
        count    =  10        //a maximum or 10 times
    }

    recurrence {
        frequency = "day"
        count     = 1000
        hours     = [0,12]       //run every 12 hours
        minutes   = [0,15,30,45] //4 times an hour
    }

    start_time = "2018-07-07T07:07:07-07:00"
}

» Example Usage (recurring monthly with an error action and client certificate authentication)

resource "azurerm_scheduler_job" "web-recurring-daily" {
    name                = "tfex-web-recurring-daily"
    resource_group_name = "${azurerm_resource_group.example.name}"
    job_collection_name = "${azurerm_scheduler_job_collection.example.name}"

    action_web {
        url     = "https://this.url.fails"
        authentication_certificate {
            pfx      = "${base64encode(file("your_cert.pfx"))}"
            password = "cert_password"
        }
    }

    error_action_web {
        url     = "https://this.url.fails"
        method  = "put"
        body    = "The job failed"

        headers = {
            "Content-Type" = "text"
        }

        authentication_basic {
            username = "login"
            password = "apassword"
        }
    }

    recurrence {
        frequency = "monthly"
        count     = 1000
        monthly_occurrences = [
            { //first sunday
                day        = "Sunday"
                occurrence = 1
            },
            { //third sunday
                day        = "Sunday"
                occurrence = 3
            },
            { //last sunday
                day        = "Sunday"
                occurrence = -1
            }
        ]
    }

    start_time = "2018-07-07T07:07:07-07:00"
}

» Example Usage (storage queue action)

resource "azurerm_storage_account" "example" {
  name                     = "tfexstorageaccount"
  resource_group_name      = "${azurerm_resource_group.example.name}"
  location                 = "${azurerm_resource_group.example.location}"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_queue" "example" {
  name                 = "tfex-schedulerjob-storagequeue"
  resource_group_name  = "${azurerm_resource_group.example.name}"
  storage_account_name = "${azurerm_storage_account.example.name}"
}

resource "azurerm_scheduler_job" "storage-once-now" {
    name                = "tfex-storage-once-now"
    resource_group_name = "${azurerm_resource_group.example.name}"
    job_collection_name = "${azurerm_scheduler_job_collection.example.name}"

    action_storage_queue = {
        storage_account_name = "${azurerm_storage_account.example.name}"
        storage_queue_name   = "${azurerm_storage_queue.example.name}"
        sas_token            = "${azurerm_storage_account.example.primary_access_key}"
        message              = "storage message"
      }
}

» Argument Reference

The following arguments are supported:

web_action & error_web_action block supports the following:

authentication_basic block supports the following:

authentication_certificate block supports the following:

authentication_active_directory block supports the following:

action_storage_queue & error_action_storage_queue block supports the following:

retry block supports the following:

recurrence block supports the following:

monthly_occurrences block supports the following:

» Attributes Reference

The following attributes are exported:

authentication_certificate block exports the following:

» Import

Scheduler Job can be imported using a resource id, e.g.

terraform import azurerm_scheduler_job.job1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Scheduler/jobCollections/jobCollection1/jobs/job1