Skip to content

Commit

Permalink
Add timeoutSeconds to cloud run (#3622) (#6575)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jun 11, 2020
1 parent 6fce313 commit 40144ed
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/3622.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrun: added `template.spec.timeout_seconds` to `google_cloud_run_service`
```
36 changes: 36 additions & 0 deletions google/resource_cloud_run_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ service. The service account represents the identity of the running revision,
and determines what permissions the revision has. If not provided, the revision
will use the project's default service account.`,
},
"timeout_seconds": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: `TimeoutSeconds holds the max duration the instance is allowed for responding to a request.`,
},
"serving_state": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -995,6 +1001,8 @@ func flattenCloudRunServiceSpecTemplateSpec(v interface{}, d *schema.ResourceDat
flattenCloudRunServiceSpecTemplateSpecContainers(original["containers"], d, config)
transformed["container_concurrency"] =
flattenCloudRunServiceSpecTemplateSpecContainerConcurrency(original["containerConcurrency"], d, config)
transformed["timeout_seconds"] =
flattenCloudRunServiceSpecTemplateSpecTimeoutSeconds(original["timeoutSeconds"], d, config)
transformed["service_account_name"] =
flattenCloudRunServiceSpecTemplateSpecServiceAccountName(original["serviceAccountName"], d, config)
transformed["serving_state"] =
Expand Down Expand Up @@ -1204,6 +1212,23 @@ func flattenCloudRunServiceSpecTemplateSpecContainerConcurrency(v interface{}, d
return v // let terraform core handle it otherwise
}

func flattenCloudRunServiceSpecTemplateSpecTimeoutSeconds(v interface{}, d *schema.ResourceData, config *Config) interface{} {
// Handles the string fixed64 format
if strVal, ok := v.(string); ok {
if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return intVal
}
}

// number values are represented as float64
if floatVal, ok := v.(float64); ok {
intVal := int(floatVal)
return intVal
}

return v // let terraform core handle it otherwise
}

func flattenCloudRunServiceSpecTemplateSpecServiceAccountName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -1605,6 +1630,13 @@ func expandCloudRunServiceSpecTemplateSpec(v interface{}, d TerraformResourceDat
transformed["containerConcurrency"] = transformedContainerConcurrency
}

transformedTimeoutSeconds, err := expandCloudRunServiceSpecTemplateSpecTimeoutSeconds(original["timeout_seconds"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTimeoutSeconds); val.IsValid() && !isEmptyValue(val) {
transformed["timeoutSeconds"] = transformedTimeoutSeconds
}

transformedServiceAccountName, err := expandCloudRunServiceSpecTemplateSpecServiceAccountName(original["service_account_name"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1937,6 +1969,10 @@ func expandCloudRunServiceSpecTemplateSpecContainerConcurrency(v interface{}, d
return v, nil
}

func expandCloudRunServiceSpecTemplateSpecTimeoutSeconds(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandCloudRunServiceSpecTemplateSpecServiceAccountName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
9 changes: 5 additions & 4 deletions google/resource_cloud_run_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccCloudRunService_cloudRunServiceUpdate(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudRunService_cloudRunServiceUpdate(name, project, "10"),
Config: testAccCloudRunService_cloudRunServiceUpdate(name, project, "10", "600"),
},
{
ResourceName: "google_cloud_run_service.default",
Expand All @@ -27,7 +27,7 @@ func TestAccCloudRunService_cloudRunServiceUpdate(t *testing.T) {
ImportStateVerifyIgnore: []string{"metadata.0.resource_version", "status.0.conditions"},
},
{
Config: testAccCloudRunService_cloudRunServiceUpdate(name, project, "50"),
Config: testAccCloudRunService_cloudRunServiceUpdate(name, project, "50", "300"),
},
{
ResourceName: "google_cloud_run_service.default",
Expand All @@ -39,7 +39,7 @@ func TestAccCloudRunService_cloudRunServiceUpdate(t *testing.T) {
})
}

func testAccCloudRunService_cloudRunServiceUpdate(name, project, concurrency string) string {
func testAccCloudRunService_cloudRunServiceUpdate(name, project, concurrency, timeoutSeconds string) string {
return fmt.Sprintf(`
resource "google_cloud_run_service" "default" {
name = "%s"
Expand All @@ -56,6 +56,7 @@ resource "google_cloud_run_service" "default" {
args = ["arrgs"]
}
container_concurrency = %s
timeout_seconds = %s
}
}
Expand All @@ -64,5 +65,5 @@ resource "google_cloud_run_service" "default" {
latest_revision = true
}
}
`, name, project, concurrency)
`, name, project, concurrency, timeoutSeconds)
}
4 changes: 4 additions & 0 deletions website/docs/r/cloud_run_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ The `spec` block supports:
- `1` not-thread-safe. Single concurrency
- `2-N` thread-safe, max concurrency of N

* `timeout_seconds` -
(Optional)
TimeoutSeconds holds the max duration the instance is allowed for responding to a request.

* `service_account_name` -
(Optional)
Email address of the IAM service account associated with the revision of the
Expand Down

0 comments on commit 40144ed

Please sign in to comment.