Skip to content

Commit 158ea58

Browse files
Add session affinity v2 (#7648) (#14367)
Signed-off-by: Modular Magician <[email protected]>
1 parent 9a3bf31 commit 158ea58

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

.changelog/7648.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
cloudrunv2: added support for `session_affinity` to `google_cloud_run_v2_service`
3+
```

google/resource_cloud_run_v2_service.go

+22
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ If not specified, defaults to the same value as container.ports[0].containerPort
507507
Optional: true,
508508
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.`,
509509
},
510+
"session_affinity": {
511+
Type: schema.TypeBool,
512+
Optional: true,
513+
Description: `Enables session affinity. For more information, go to https://cloud.google.com/run/docs/configuring/session-affinity`,
514+
},
510515
"timeout": {
511516
Type: schema.TypeString,
512517
Computed: true,
@@ -1396,6 +1401,8 @@ func flattenCloudRunV2ServiceTemplate(v interface{}, d *schema.ResourceData, con
13961401
flattenCloudRunV2ServiceTemplateEncryptionKey(original["encryptionKey"], d, config)
13971402
transformed["max_instance_request_concurrency"] =
13981403
flattenCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(original["maxInstanceRequestConcurrency"], d, config)
1404+
transformed["session_affinity"] =
1405+
flattenCloudRunV2ServiceTemplateSessionAffinity(original["sessionAffinity"], d, config)
13991406
return []interface{}{transformed}
14001407
}
14011408
func flattenCloudRunV2ServiceTemplateRevision(v interface{}, d *schema.ResourceData, config *Config) interface{} {
@@ -2271,6 +2278,10 @@ func flattenCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(v interface{}
22712278
return v // let terraform core handle it otherwise
22722279
}
22732280

2281+
func flattenCloudRunV2ServiceTemplateSessionAffinity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
2282+
return v
2283+
}
2284+
22742285
func flattenCloudRunV2ServiceTraffic(v interface{}, d *schema.ResourceData, config *Config) interface{} {
22752286
if v == nil {
22762287
return v
@@ -2685,6 +2696,13 @@ func expandCloudRunV2ServiceTemplate(v interface{}, d TerraformResourceData, con
26852696
transformed["maxInstanceRequestConcurrency"] = transformedMaxInstanceRequestConcurrency
26862697
}
26872698

2699+
transformedSessionAffinity, err := expandCloudRunV2ServiceTemplateSessionAffinity(original["session_affinity"], d, config)
2700+
if err != nil {
2701+
return nil, err
2702+
} else if val := reflect.ValueOf(transformedSessionAffinity); val.IsValid() && !isEmptyValue(val) {
2703+
transformed["sessionAffinity"] = transformedSessionAffinity
2704+
}
2705+
26882706
return transformed, nil
26892707
}
26902708

@@ -3732,6 +3750,10 @@ func expandCloudRunV2ServiceTemplateMaxInstanceRequestConcurrency(v interface{},
37323750
return v, nil
37333751
}
37343752

3753+
func expandCloudRunV2ServiceTemplateSessionAffinity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
3754+
return v, nil
3755+
}
3756+
37353757
func expandCloudRunV2ServiceTraffic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
37363758
l := v.([]interface{})
37373759
req := make([]interface{}, 0, len(l))

google/resource_cloud_run_v2_service_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ resource "google_cloud_run_v2_service" "default" {
9595
}
9696
}
9797
}
98+
session_affinity = false
9899
}
99100
}
100101
@@ -166,6 +167,7 @@ resource "google_cloud_run_v2_service" "default" {
166167
connector = google_vpc_access_connector.connector.id
167168
egress = "ALL_TRAFFIC"
168169
}
170+
session_affinity = true
169171
}
170172
traffic {
171173
type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"

website/docs/r/cloud_run_v2_service.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ The following arguments are supported:
349349
(Optional)
350350
Sets the maximum number of requests that each serving instance can receive.
351351

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

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

0 commit comments

Comments
 (0)