From 7c774a26e8237a796a4a0d9d417cdf13dbe1e513 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 7 Jul 2018 00:20:35 -0700 Subject: [PATCH] azurern_scheduler_job - Added storage queue support --- azurerm/resource_arm_scheduler_job.go | 126 +++++++++++++++-- azurerm/resource_arm_scheduler_job_test.go | 156 +++++++++++++++++++-- examples/scheduler-jobs/main.tf | 69 ++++++--- examples/scheduler-jobs/outputs.tf | 2 +- website/docs/r/scheduler_job.html.markdown | 57 +++++++- 5 files changed, 361 insertions(+), 49 deletions(-) diff --git a/azurerm/resource_arm_scheduler_job.go b/azurerm/resource_arm_scheduler_job.go index 4ecc68121598..b0858d0d414b 100644 --- a/azurerm/resource_arm_scheduler_job.go +++ b/azurerm/resource_arm_scheduler_job.go @@ -56,18 +56,36 @@ func resourceArmSchedulerJob() *schema.Resource { //actions "action_web": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: resourceArmSchedulerJobActionWebSchema("action_web"), + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: resourceArmSchedulerJobActionWebSchema("action_web"), + ConflictsWith: []string{"action_storage_queue"}, + }, + + "action_storage_queue": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: resourceArmSchedulerJobActionStorageSchema(), + ConflictsWith: []string{"action_web"}, }, //actions "error_action_web": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: resourceArmSchedulerJobActionWebSchema("error_action_web"), + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: resourceArmSchedulerJobActionWebSchema("error_action_web"), + ConflictsWith: []string{"error_action_storage_queue"}, + }, + + "error_action_storage_queue": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: resourceArmSchedulerJobActionStorageSchema(), + ConflictsWith: []string{"error_action_web"}, }, //retry policy @@ -397,11 +415,45 @@ func resourceArmSchedulerJobActionWebSchema(propertyName string) *schema.Resourc } } +func resourceArmSchedulerJobActionStorageSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + + "storage_account_name": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validateArmStorageAccountName, + }, + + "storage_queue_name": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validateArmStorageQueueName, + }, + + "sas_token": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + }, + + "message": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + }, + }, + } +} + func resourceArmSchedulerJobCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error { _, hasWeb := diff.GetOk("action_web") - if !hasWeb { - return fmt.Errorf("One of `action_web`, `action_servicebus` or `action_storagequeue` must be set") + _, hasStorage := diff.GetOk("action_storage_queue") + if !hasWeb && !hasStorage { + return fmt.Errorf("One of `action_web` or `action_storage_queue` must be set") } if b, ok := diff.GetOk("recurrence"); ok { @@ -501,18 +553,29 @@ func resourceArmSchedulerJobRead(d *schema.ResourceData, meta interface{}) error action := properties.Action if action != nil { actionType := strings.ToLower(string(action.Type)) + if strings.EqualFold(actionType, string(scheduler.HTTP)) || strings.EqualFold(actionType, string(scheduler.HTTPS)) { if err := d.Set("action_web", flattenAzureArmSchedulerJobActionRequest(d, "action_web", action.Request)); err != nil { return err } + } else if strings.EqualFold(actionType, string(scheduler.StorageQueue)) { + if err := d.Set("action_storage_queue", flattenAzureArmSchedulerJobActionQueueMessage(d, "action_storage_queue", action.QueueMessage)); err != nil { + return err + } } //error action if errorAction := action.ErrorAction; errorAction != nil { - if strings.EqualFold(actionType, string(scheduler.HTTP)) || strings.EqualFold(actionType, string(scheduler.HTTPS)) { + errorActionType := strings.ToLower(string(errorAction.Type)) + + if strings.EqualFold(errorActionType, string(scheduler.HTTP)) || strings.EqualFold(errorActionType, string(scheduler.HTTPS)) { if err := d.Set("error_action_web", flattenAzureArmSchedulerJobActionRequest(d, "error_action_web", errorAction.Request)); err != nil { return err } + } else if strings.EqualFold(errorActionType, string(scheduler.StorageQueue)) { + if err := d.Set("error_action_storage_queue", flattenAzureArmSchedulerJobActionQueueMessage(d, "error_action_storage_queue", errorAction.QueueMessage)); err != nil { + return err + } } } @@ -578,12 +641,19 @@ func expandAzureArmSchedulerJobAction(d *schema.ResourceData, meta interface{}) //action if b, ok := d.GetOk("action_web"); ok { action.Request, action.Type = expandAzureArmSchedulerJobActionRequest(b, meta) + } else if b, ok := d.GetOk("action_storage_queue"); ok { + action.QueueMessage = expandAzureArmSchedulerJobActionStorage(b) + action.Type = scheduler.StorageQueue } //error action if b, ok := d.GetOk("error_action_web"); ok { action.ErrorAction = &scheduler.JobErrorAction{} action.ErrorAction.Request, action.ErrorAction.Type = expandAzureArmSchedulerJobActionRequest(b, meta) + } else if b, ok := d.GetOk("error_action_storage_queue"); ok { + action.ErrorAction = &scheduler.JobErrorAction{} + action.ErrorAction.QueueMessage = expandAzureArmSchedulerJobActionStorage(b) + action.ErrorAction.Type = scheduler.StorageQueue } //retry policy @@ -670,6 +740,19 @@ func expandAzureArmSchedulerJobActionRequest(b interface{}, meta interface{}) (* return &request, jobType } +func expandAzureArmSchedulerJobActionStorage(b interface{}) *scheduler.StorageQueueMessage { + block := b.([]interface{})[0].(map[string]interface{}) + + message := scheduler.StorageQueueMessage{ + StorageAccount: utils.String(block["storage_account_name"].(string)), + QueueName: utils.String(block["storage_queue_name"].(string)), + SasToken: utils.String(block["sas_token"].(string)), + Message: utils.String(block["message"].(string)), + } + + return &message +} + func expandAzureArmSchedulerJobActionRetry(b interface{}) *scheduler.RetryPolicy { block := b.([]interface{})[0].(map[string]interface{}) retry := scheduler.RetryPolicy{ @@ -829,6 +912,27 @@ func flattenAzureArmSchedulerJobActionRequest(d *schema.ResourceData, blockName return []interface{}{block} } +func flattenAzureArmSchedulerJobActionQueueMessage(d *schema.ResourceData, blockName string, qm *scheduler.StorageQueueMessage) []interface{} { + block := map[string]interface{}{} + + if v := qm.StorageAccount; v != nil { + block["storage_account_name"] = *v + } + if v := qm.QueueName; v != nil { + block["storage_queue_name"] = *v + } + if v := qm.Message; v != nil { + block["message"] = *v + } + + //sas_token is not returned by the API + if v, ok := d.GetOk(fmt.Sprintf("%s.0.sas_token", blockName)); ok { + block["sas_token"] = v.(string) + } + + return []interface{}{block} +} + func flattenAzureArmSchedulerJobActionRetry(retry *scheduler.RetryPolicy) []interface{} { block := map[string]interface{}{} diff --git a/azurerm/resource_arm_scheduler_job_test.go b/azurerm/resource_arm_scheduler_job_test.go index ff5f64c1360a..189846f060d7 100644 --- a/azurerm/resource_arm_scheduler_job_test.go +++ b/azurerm/resource_arm_scheduler_job_test.go @@ -3,6 +3,7 @@ package azurerm import ( "fmt" "os" + "strconv" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -37,6 +38,66 @@ func TestAccAzureRMSchedulerJob_web_basic(t *testing.T) { }) } +func TestAccAzureRMSchedulerJob_storageQueue(t *testing.T) { + resourceName := "azurerm_scheduler_job.test" + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMSchedulerJobDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSchedulerJob_storageQueue(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMSchedulerJobExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.storage_account_name"), + resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.storage_queue_name"), + resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.sas_token"), + resource.TestCheckResourceAttr(resourceName, "action_storage_queue.0.message", "storage message"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"action_storage_queue.0.sas_token"}, + }, + }, + }) +} + +func TestAccAzureRMSchedulerJob_storageQueue_errorAction(t *testing.T) { + resourceName := "azurerm_scheduler_job.test" + ri := acctest.RandInt() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMSchedulerJobDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSchedulerJob_storageQueue_errorAction(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMSchedulerJobExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.storage_account_name"), + resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.storage_queue_name"), + resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.sas_token"), + resource.TestCheckResourceAttr(resourceName, "error_action_storage_queue.0.message", "storage message"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"error_action_storage_queue.0.sas_token"}, + }, + }, + }) +} + func TestAccAzureRMSchedulerJob_web_put(t *testing.T) { resourceName := "azurerm_scheduler_job.test" ri := acctest.RandInt() @@ -479,7 +540,7 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_scheduler_job_collection" "test" { - name = "acctestRG-%[1]d-job_collection" + name = "acctest-%[1]d-job_collection" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "standard" @@ -492,7 +553,7 @@ func testAccAzureRMSchedulerJob_web_basic(rInt int, location string) string { //need a valid URL here otherwise on a slow connection job might fault before the test check return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -506,7 +567,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_put(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -526,7 +587,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_authBasic(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -546,7 +607,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_authCert(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -566,7 +627,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_authAd(rInt int, location, tenantId, clientId, secret, audience string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -588,7 +649,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_retry(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -609,7 +670,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_recurring(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -631,7 +692,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_recurringDaily(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -654,7 +715,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_recurringWeekly(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -676,7 +737,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_recurringMonthly(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -698,7 +759,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -733,7 +794,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_errorAction(rInt int, location string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -754,7 +815,7 @@ resource "azurerm_scheduler_job" "test" { func testAccAzureRMSchedulerJob_web_complete(rInt int, location, time string) string { return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { - name = "acctestRG-%d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -784,3 +845,70 @@ resource "azurerm_scheduler_job" "test" { }`, testAccAzureRMSchedulerJob_template(rInt, location), rInt, time) } + +func testAccAzureRMSchedulerJob_storageQueue(rInt int, location string) string { + //need a valid URL here otherwise on a slow connection job might fault before the test check + return fmt.Sprintf(`%[1]s +resource "azurerm_storage_account" "test" { + name = "acctest%[2]s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_queue" "test" { + name = "acctest-%[3]d-job" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" +} + +resource "azurerm_scheduler_job" "test" { + name = "acctest-%[3]d-job" + resource_group_name = "${azurerm_resource_group.test.name}" + job_collection_name = "${azurerm_scheduler_job_collection.test.name}" + + action_storage_queue = { + storage_account_name = "${azurerm_storage_account.test.name}" + storage_queue_name = "${azurerm_storage_queue.test.name}" + sas_token = "${azurerm_storage_account.test.primary_access_key}" + message = "storage message" + } +}`, testAccAzureRMSchedulerJob_template(rInt, location), strconv.Itoa(rInt)[0:5], rInt) +} + +func testAccAzureRMSchedulerJob_storageQueue_errorAction(rInt int, location string) string { + //need a valid URL here otherwise on a slow connection job might fault before the test check + return fmt.Sprintf(`%[1]s +resource "azurerm_storage_account" "test" { + name = "acctest%[2]s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_queue" "test" { + name = "acctest-%[3]d-job" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" +} + +resource "azurerm_scheduler_job" "test" { + name = "acctest-%[3]d-job" + resource_group_name = "${azurerm_resource_group.test.name}" + job_collection_name = "${azurerm_scheduler_job_collection.test.name}" + + action_web { + url = "http://example.com" + method = "get" + } + + error_action_storage_queue = { + storage_account_name = "${azurerm_storage_account.test.name}" + storage_queue_name = "${azurerm_storage_queue.test.name}" + sas_token = "${azurerm_storage_account.test.primary_access_key}" + message = "storage message" + } +}`, testAccAzureRMSchedulerJob_template(rInt, location), strconv.Itoa(rInt)[0:5], rInt) +} diff --git a/examples/scheduler-jobs/main.tf b/examples/scheduler-jobs/main.tf index f277a945b96a..a09d994f66e8 100644 --- a/examples/scheduler-jobs/main.tf +++ b/examples/scheduler-jobs/main.tf @@ -1,26 +1,26 @@ -resource "azurerm_resource_group" "rg" { +resource "azurerm_resource_group" "example" { name = "${var.resource_group_name}" location = "${var.resource_group_location}" } -resource "azurerm_scheduler_job_collection" "jc" { +resource "azurerm_scheduler_job_collection" "example" { name = "tfex-scheduler-job-collection" - location = "${azurerm_resource_group.rg.location}" - resource_group_name = "${azurerm_resource_group.rg.name}" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" sku = "standard" state = "enabled" quota { - max_job_count = 5 - max_recurrence_interval = 5 + max_job_count = 10 + max_recurrence_interval = 10 max_recurrence_frequency = "minute" } } resource "azurerm_scheduler_job" "web-once-now" { name = "tfex-web-once-now" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" state = "enabled" @@ -40,8 +40,8 @@ resource "azurerm_scheduler_job" "web-once-now" { resource "azurerm_scheduler_job" "web-recurring" { name = "tfex-web-recurring" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" action_web { url = "http://example.com" @@ -69,8 +69,8 @@ resource "azurerm_scheduler_job" "web-recurring" { resource "azurerm_scheduler_job" "web-recurring_daily-auth_basic" { name = "tfex-web-recurring_daily-auth_basic" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" state = "enabled" @@ -96,8 +96,8 @@ resource "azurerm_scheduler_job" "web-recurring_daily-auth_basic" { resource "azurerm_scheduler_job" "web-recurring_weekly-auth_cert" { name = "tfex-web-recurring_weekly-auth_cert" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" state = "enabled" @@ -120,10 +120,47 @@ resource "azurerm_scheduler_job" "web-recurring_weekly-auth_cert" { start_time = "2019-07-07T07:07:07-07:00" } +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-queue" { + name = "tfex-schedulerjob-storage_queue" + 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" + } + + recurrence { + frequency = "week" + count = 1000 + week_days = ["Sunday"] + } + + start_time = "2019-07-07T07:07:07-07:00" +} + + resource "azurerm_scheduler_job" "web-recurring_monthly-error_action" { name = "tfex-web-recurring_monthly-auth_ad" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" state = "enabled" diff --git a/examples/scheduler-jobs/outputs.tf b/examples/scheduler-jobs/outputs.tf index f8ed3606c353..e13d249d2452 100644 --- a/examples/scheduler-jobs/outputs.tf +++ b/examples/scheduler-jobs/outputs.tf @@ -1,5 +1,5 @@ output "job_collection-id" { - value = "${azurerm_scheduler_job_collection.jc.id}" + value = "${azurerm_scheduler_job_collection.example.id}" } output "job-web-once-url" { diff --git a/website/docs/r/scheduler_job.html.markdown b/website/docs/r/scheduler_job.html.markdown index 94b5c4ee825a..9f2c7919e1f9 100644 --- a/website/docs/r/scheduler_job.html.markdown +++ b/website/docs/r/scheduler_job.html.markdown @@ -15,8 +15,8 @@ Manages a Scheduler Job. ```hcl resource "azurerm_scheduler_job" "web-once-now" { name = "tfex-web-once-now" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" state = "enabled" //re-enable it each run @@ -33,8 +33,8 @@ resource "azurerm_scheduler_job" "web-once-now" { ```hcl resource "azurerm_scheduler_job" "web-recurring-daily" { name = "tfex-web-recurring-daily" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" action_web { url = "https://this.url.fails" @@ -72,8 +72,8 @@ resource "azurerm_scheduler_job" "web-recurring-daily" { ```hcl resource "azurerm_scheduler_job" "web-recurring-daily" { name = "tfex-web-recurring-daily" - resource_group_name = "${azurerm_resource_group.rg.name}" - job_collection_name = "${azurerm_scheduler_job_collection.jc.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + job_collection_name = "${azurerm_scheduler_job_collection.example.name}" action_web { url = "https://this.url.fails" @@ -121,6 +121,37 @@ resource "azurerm_scheduler_job" "web-recurring-daily" { } ``` +## Example Usage (storage queue action) + +```hcl +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: @@ -131,10 +162,16 @@ The following arguments are supported: * `job_collection_name` - (Required) Specifies the name of the Scheduler Job Collection in which the Job should exist. Changing this forces a new resource to be created. -* `action_web` - (Required) A `action_web` block defining the job action as described below. Note this is identical to an `error_action_web` block. +* `action_web` - (Optional) A `action_web` block defining the job action as described below. Note this is identical to an `error_action_web` block. + +~> **NOTE** At least one of `error_action_web` or `action_storage_queue` needs to be set. + +* `action_storage_queue` - (Optional) A `action_storage_queue` block defining a storage queue job action as described below. Note this is identical to an `error_action_storage_queue` block. * `error_action_web` - (Optional) A `error_action_web` block defining the action to take on an error as described below. Note this is identical to an `action_web` block. +* `error_action_storage_queue` - (Optional) A `error_action_storage_queue` block defining the a web action to take on an error as described below. Note this is identical to an `action_storage_queue` block. + * `retry` - (Optional) A `retry` block defining how to retry as described below. * `recurrence` - (Optional) A `recurrence` block defining a job occurrence schedule. @@ -174,6 +211,12 @@ The following arguments are supported: * `client_secret` - (Required) Specifies the secret to use. * `audience` - (Optional) Specifies the audience. +`action_storage_queue` & `error_action_storage_queue` block supports the following: + +* `storage_account_name` - (Required) Specifies the the storage account name. +* `storage_queue_name` - (Required) Specifies the the storage account queue. +* `sas_token` - (Required) Specifies a SAS token/key to authenticate with. +* `message` - (Required) The message to send into the queue. `retry` block supports the following: