diff --git a/.changelog/3463.txt b/.changelog/3463.txt new file mode 100644 index 00000000000..fa26c3da93f --- /dev/null +++ b/.changelog/3463.txt @@ -0,0 +1,3 @@ +```release-note:bug +cloudscheduler: Fixed permadiff for `google_cloud_scheduler_job.retry_config.*` block when API provides default values +``` diff --git a/google/resource_cloud_scheduler_job.go b/google/resource_cloud_scheduler_job.go index 54bf2e42a35..aaea80016b0 100644 --- a/google/resource_cloud_scheduler_job.go +++ b/google/resource_cloud_scheduler_job.go @@ -357,6 +357,7 @@ then it will be retried with exponential backoff according to the settings`, Schema: map[string]*schema.Schema{ "max_backoff_duration": { Type: schema.TypeString, + Computed: true, Optional: true, ForceNew: true, Description: `The maximum amount of time to wait before retrying a job after it fails. @@ -365,6 +366,7 @@ A duration in seconds with up to nine fractional digits, terminated by 's'.`, }, "max_doublings": { Type: schema.TypeInt, + Computed: true, Optional: true, ForceNew: true, Description: `The time between retries will double maxDoublings times. @@ -375,6 +377,7 @@ and finally retries retries at intervals of maxBackoffDuration up to retryCount }, "max_retry_duration": { Type: schema.TypeString, + Computed: true, Optional: true, ForceNew: true, Description: `The time limit for retrying a failed job, measured from time when an execution was first attempted. @@ -384,6 +387,7 @@ A duration in seconds with up to nine fractional digits, terminated by 's'.`, }, "min_backoff_duration": { Type: schema.TypeString, + Computed: true, Optional: true, ForceNew: true, Description: `The minimum amount of time to wait before retrying a job after it fails. @@ -392,6 +396,7 @@ A duration in seconds with up to nine fractional digits, terminated by 's'.`, }, "retry_count": { Type: schema.TypeInt, + Computed: true, Optional: true, ForceNew: true, Description: `The number of attempts that the system will make to run a diff --git a/google/resource_cloud_scheduler_job_generated_test.go b/google/resource_cloud_scheduler_job_generated_test.go index a3bc7feb067..18c9bc62159 100644 --- a/google/resource_cloud_scheduler_job_generated_test.go +++ b/google/resource_cloud_scheduler_job_generated_test.go @@ -102,6 +102,10 @@ resource "google_cloud_scheduler_job" "job" { time_zone = "America/New_York" attempt_deadline = "320s" + retry_config { + retry_count = 1 + } + http_target { http_method = "POST" uri = "https://example.com/ping" @@ -144,6 +148,13 @@ resource "google_cloud_scheduler_job" "job" { time_zone = "Europe/London" attempt_deadline = "320s" + retry_config { + min_backoff_duration = "1s" + max_retry_duration = "10s" + max_doublings = 2 + retry_count = 3 + } + app_engine_http_target { http_method = "POST" diff --git a/google/resource_cloud_scheduler_job_test.go b/google/resource_cloud_scheduler_job_test.go new file mode 100644 index 00000000000..1b03acacf03 --- /dev/null +++ b/google/resource_cloud_scheduler_job_test.go @@ -0,0 +1,95 @@ +package google + +import ( + "reflect" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func TestCloudScheduler_FlattenHttpHeaders(t *testing.T) { + + cases := []struct { + Input map[string]interface{} + Output map[string]interface{} + }{ + // simple, no headers included + { + Input: map[string]interface{}{ + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "My-Header": "my-header-value", + }, + }, + + // include the User-Agent header value Google-Cloud-Scheduler + // Tests Removing User-Agent header + { + Input: map[string]interface{}{ + "User-Agent": "Google-Cloud-Scheduler", + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "My-Header": "my-header-value", + }, + }, + + // include the User-Agent header + // Tests removing value AppEngine-Google; (+http://code.google.com/appengine) + { + Input: map[string]interface{}{ + "User-Agent": "My-User-Agent AppEngine-Google; (+http://code.google.com/appengine)", + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "User-Agent": "My-User-Agent", + "My-Header": "my-header-value", + }, + }, + + // include the Content-Type header value application/octet-stream. + // Tests Removing Content-Type header + { + Input: map[string]interface{}{ + "Content-Type": "application/octet-stream", + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "My-Header": "my-header-value", + }, + }, + + // include the Content-Length header + // Tests Removing Content-Length header + { + Input: map[string]interface{}{ + "Content-Length": 7, + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "My-Header": "my-header-value", + }, + }, + + // include the X-Google- header + // Tests Removing X-Google- header + { + Input: map[string]interface{}{ + "X-Google-My-Header": "x-google-my-header-value", + "My-Header": "my-header-value", + }, + Output: map[string]interface{}{ + "My-Header": "my-header-value", + }, + }, + } + + for _, c := range cases { + d := &schema.ResourceData{} + output := flattenCloudSchedulerJobAppEngineHttpTargetHeaders(c.Input, d, &Config{}) + if !reflect.DeepEqual(output, c.Output) { + t.Fatalf("Error matching output and expected: %#v vs %#v", output, c.Output) + } + } +} diff --git a/google/resource_cloudscheduler_job_test.go b/google/resource_cloudscheduler_job_test.go deleted file mode 100644 index 93cfad7a2a0..00000000000 --- a/google/resource_cloudscheduler_job_test.go +++ /dev/null @@ -1,3 +0,0 @@ -package google - -// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now. diff --git a/website/docs/r/cloud_scheduler_job.html.markdown b/website/docs/r/cloud_scheduler_job.html.markdown index 8e23bded719..77bfcaeca33 100644 --- a/website/docs/r/cloud_scheduler_job.html.markdown +++ b/website/docs/r/cloud_scheduler_job.html.markdown @@ -78,6 +78,10 @@ resource "google_cloud_scheduler_job" "job" { time_zone = "America/New_York" attempt_deadline = "320s" + retry_config { + retry_count = 1 + } + http_target { http_method = "POST" uri = "https://example.com/ping" @@ -100,6 +104,13 @@ resource "google_cloud_scheduler_job" "job" { time_zone = "Europe/London" attempt_deadline = "320s" + retry_config { + min_backoff_duration = "1s" + max_retry_duration = "10s" + max_doublings = 2 + retry_count = 3 + } + app_engine_http_target { http_method = "POST"