From 13b47c47ba23d9534e0717ea4d475527666dc235 Mon Sep 17 00:00:00 2001 From: guillaume blaquiere Date: Thu, 16 Jan 2020 19:44:22 +0000 Subject: [PATCH] Added attempt deadline to scheduler resource Signed-off-by: Modular Magician --- google-beta/resource_cloud_scheduler_job.go | 31 +++++++++++++ ...urce_cloud_scheduler_job_generated_test.go | 36 ++++++++------- .../docs/r/cloud_scheduler_job.html.markdown | 46 ++++++++++++------- 3 files changed, 81 insertions(+), 32 deletions(-) diff --git a/google-beta/resource_cloud_scheduler_job.go b/google-beta/resource_cloud_scheduler_job.go index 770dffe13e..7373108869 100644 --- a/google-beta/resource_cloud_scheduler_job.go +++ b/google-beta/resource_cloud_scheduler_job.go @@ -189,6 +189,20 @@ Headers can be set when the job is created.`, }, ExactlyOneOf: []string{"pubsub_target", "http_target", "app_engine_http_target"}, }, + "attempt_deadline": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: emptyOrDefaultStringSuppress("180s"), + Description: `The deadline for job attempts. If the request handler does not respond by this deadline then the request is +cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in +execution logs. Cloud Scheduler will retry the job according to the RetryConfig. +The allowed duration for this deadline is: +* For HTTP targets, between 15 seconds and 30 minutes. +* For App Engine HTTP targets, between 15 seconds and 24 hours. +A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"`, + Default: "180s", + }, "description": { Type: schema.TypeString, Optional: true, @@ -440,6 +454,12 @@ func resourceCloudSchedulerJobCreate(d *schema.ResourceData, meta interface{}) e } else if v, ok := d.GetOkExists("time_zone"); !isEmptyValue(reflect.ValueOf(timeZoneProp)) && (ok || !reflect.DeepEqual(v, timeZoneProp)) { obj["timeZone"] = timeZoneProp } + attemptDeadlineProp, err := expandCloudSchedulerJobAttemptDeadline(d.Get("attempt_deadline"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("attempt_deadline"); !isEmptyValue(reflect.ValueOf(attemptDeadlineProp)) && (ok || !reflect.DeepEqual(v, attemptDeadlineProp)) { + obj["attemptDeadline"] = attemptDeadlineProp + } retryConfigProp, err := expandCloudSchedulerJobRetryConfig(d.Get("retry_config"), d, config) if err != nil { return err @@ -533,6 +553,9 @@ func resourceCloudSchedulerJobRead(d *schema.ResourceData, meta interface{}) err if err := d.Set("time_zone", flattenCloudSchedulerJobTimeZone(res["timeZone"], d)); err != nil { return fmt.Errorf("Error reading Job: %s", err) } + if err := d.Set("attempt_deadline", flattenCloudSchedulerJobAttemptDeadline(res["attemptDeadline"], d)); err != nil { + return fmt.Errorf("Error reading Job: %s", err) + } if err := d.Set("retry_config", flattenCloudSchedulerJobRetryConfig(res["retryConfig"], d)); err != nil { return fmt.Errorf("Error reading Job: %s", err) } @@ -614,6 +637,10 @@ func flattenCloudSchedulerJobTimeZone(v interface{}, d *schema.ResourceData) int return v } +func flattenCloudSchedulerJobAttemptDeadline(v interface{}, d *schema.ResourceData) interface{} { + return v +} + func flattenCloudSchedulerJobRetryConfig(v interface{}, d *schema.ResourceData) interface{} { if v == nil { return nil @@ -895,6 +922,10 @@ func expandCloudSchedulerJobTimeZone(v interface{}, d TerraformResourceData, con return v, nil } +func expandCloudSchedulerJobAttemptDeadline(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func expandCloudSchedulerJobRetryConfig(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/resource_cloud_scheduler_job_generated_test.go b/google-beta/resource_cloud_scheduler_job_generated_test.go index c80153d2d6..c82179cb19 100644 --- a/google-beta/resource_cloud_scheduler_job_generated_test.go +++ b/google-beta/resource_cloud_scheduler_job_generated_test.go @@ -97,10 +97,11 @@ func TestAccCloudSchedulerJob_schedulerJobHttpExample(t *testing.T) { func testAccCloudSchedulerJob_schedulerJobHttpExample(context map[string]interface{}) string { return Nprintf(` resource "google_cloud_scheduler_job" "job" { - name = "test-job%{random_suffix}" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job%{random_suffix}" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "POST" @@ -138,10 +139,11 @@ func TestAccCloudSchedulerJob_schedulerJobAppEngineExample(t *testing.T) { func testAccCloudSchedulerJob_schedulerJobAppEngineExample(context map[string]interface{}) string { return Nprintf(` resource "google_cloud_scheduler_job" "job" { - name = "test-job%{random_suffix}" - schedule = "*/4 * * * *" - description = "test app engine job" - time_zone = "Europe/London" + name = "test-job%{random_suffix}" + schedule = "*/4 * * * *" + description = "test app engine job" + time_zone = "Europe/London" + attempt_deadline = "320s" app_engine_http_target { http_method = "POST" @@ -191,10 +193,11 @@ data "google_compute_default_service_account" "default" { } resource "google_cloud_scheduler_job" "job" { - name = "test-job%{random_suffix}" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job%{random_suffix}" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "GET" @@ -239,10 +242,11 @@ data "google_compute_default_service_account" "default" { } resource "google_cloud_scheduler_job" "job" { - name = "test-job%{random_suffix}" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job%{random_suffix}" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "GET" diff --git a/website/docs/r/cloud_scheduler_job.html.markdown b/website/docs/r/cloud_scheduler_job.html.markdown index 1ee4c67cd2..a4d7e9ac01 100644 --- a/website/docs/r/cloud_scheduler_job.html.markdown +++ b/website/docs/r/cloud_scheduler_job.html.markdown @@ -72,10 +72,11 @@ resource "google_cloud_scheduler_job" "job" { ```hcl resource "google_cloud_scheduler_job" "job" { - name = "test-job" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "POST" @@ -93,10 +94,11 @@ resource "google_cloud_scheduler_job" "job" { ```hcl resource "google_cloud_scheduler_job" "job" { - name = "test-job" - schedule = "*/4 * * * *" - description = "test app engine job" - time_zone = "Europe/London" + name = "test-job" + schedule = "*/4 * * * *" + description = "test app engine job" + time_zone = "Europe/London" + attempt_deadline = "320s" app_engine_http_target { http_method = "POST" @@ -124,10 +126,11 @@ data "google_compute_default_service_account" "default" { } resource "google_cloud_scheduler_job" "job" { - name = "test-job" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "GET" @@ -152,10 +155,11 @@ data "google_compute_default_service_account" "default" { } resource "google_cloud_scheduler_job" "job" { - name = "test-job" - description = "test http job" - schedule = "*/8 * * * *" - time_zone = "America/New_York" + name = "test-job" + description = "test http job" + schedule = "*/8 * * * *" + time_zone = "America/New_York" + attempt_deadline = "320s" http_target { http_method = "GET" @@ -199,6 +203,16 @@ The following arguments are supported: Specifies the time zone to be used in interpreting schedule. The value of this field must be a time zone name from the tz database. +* `attempt_deadline` - + (Optional) + The deadline for job attempts. If the request handler does not respond by this deadline then the request is + cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in + execution logs. Cloud Scheduler will retry the job according to the RetryConfig. + The allowed duration for this deadline is: + * For HTTP targets, between 15 seconds and 30 minutes. + * For App Engine HTTP targets, between 15 seconds and 24 hours. + A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s" + * `retry_config` - (Optional) By default, if a job does not complete successfully,