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

Add session affinity v2 #14367

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/7648.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudrunv2: added support for `session_affinity` to `google_cloud_run_v2_service`
```
22 changes: 22 additions & 0 deletions google/resource_cloud_run_v2_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ If not specified, defaults to the same value as container.ports[0].containerPort
Optional: true,
Description: `Email address of the IAM service account associated with the revision of the 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.`,
},
"session_affinity": {
Type: schema.TypeBool,
Optional: true,
Description: `Enables session affinity. For more information, go to https://cloud.google.com/run/docs/configuring/session-affinity`,
},
"timeout": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1396,6 +1401,8 @@ func flattenCloudRunV2ServiceTemplate(v interface{}, d *schema.ResourceData, con
flattenCloudRunV2ServiceTemplateEncryptionKey(original["encryptionKey"], d, config)
transformed["max_instance_request_concurrency"] =
flattenCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(original["maxInstanceRequestConcurrency"], d, config)
transformed["session_affinity"] =
flattenCloudRunV2ServiceTemplateSessionAffinity(original["sessionAffinity"], d, config)
return []interface{}{transformed}
}
func flattenCloudRunV2ServiceTemplateRevision(v interface{}, d *schema.ResourceData, config *Config) interface{} {
Expand Down Expand Up @@ -2271,6 +2278,10 @@ func flattenCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(v interface{}
return v // let terraform core handle it otherwise
}

func flattenCloudRunV2ServiceTemplateSessionAffinity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenCloudRunV2ServiceTraffic(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -2685,6 +2696,13 @@ func expandCloudRunV2ServiceTemplate(v interface{}, d TerraformResourceData, con
transformed["maxInstanceRequestConcurrency"] = transformedMaxInstanceRequestConcurrency
}

transformedSessionAffinity, err := expandCloudRunV2ServiceTemplateSessionAffinity(original["session_affinity"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedSessionAffinity); val.IsValid() && !isEmptyValue(val) {
transformed["sessionAffinity"] = transformedSessionAffinity
}

return transformed, nil
}

Expand Down Expand Up @@ -3732,6 +3750,10 @@ func expandCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(v interface{},
return v, nil
}

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

func expandCloudRunV2ServiceTraffic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
req := make([]interface{}, 0, len(l))
Expand Down
2 changes: 2 additions & 0 deletions google/resource_cloud_run_v2_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ resource "google_cloud_run_v2_service" "default" {
}
}
}
session_affinity = false
}
}

Expand Down Expand Up @@ -166,6 +167,7 @@ resource "google_cloud_run_v2_service" "default" {
connector = google_vpc_access_connector.connector.id
egress = "ALL_TRAFFIC"
}
session_affinity = true
}
traffic {
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/cloud_run_v2_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ The following arguments are supported:
(Optional)
Sets the maximum number of requests that each serving instance can receive.

* `session_affinity` -
(Optional)
Enables session affinity. For more information, go to https://cloud.google.com/run/docs/configuring/session-affinity


<a name="nested_scaling"></a>The `scaling` block supports:

Expand Down