Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make retryConfig computed for Cloud Scheduler jobs #6278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3463.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudscheduler: Fixed permadiff for `google_cloud_scheduler_job.retry_config.*` block when API provides default values
```
5 changes: 5 additions & 0 deletions google/resource_cloud_scheduler_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions google/resource_cloud_scheduler_job_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down
95 changes: 95 additions & 0 deletions google/resource_cloud_scheduler_job_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
3 changes: 0 additions & 3 deletions google/resource_cloudscheduler_job_test.go

This file was deleted.

11 changes: 11 additions & 0 deletions website/docs/r/cloud_scheduler_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down