Skip to content

Commit 577093d

Browse files
committed
feat(edge-services): add support for include_cookies on cache stage (scaleway#3184)
* feat(edge-services): add support for include_cookies on cache stage * fix GetEndOfServiceDate test
1 parent 8c2a4ac commit 577093d

File tree

8 files changed

+464
-276
lines changed

8 files changed

+464
-276
lines changed

docs/resources/edge_services_cache_stage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ resource "scaleway_edge_services_cache_stage" "main" {
4040
- `waf_stage_id` - (Optional) The WAF stage ID the cache stage will be linked to. Only one of `backend_stage_id`, `route_stage_id` and `waf_stage_id` should be specified.
4141
- `fallback_ttl` - (Optional) The Time To Live (TTL) in seconds. Defines how long content is cached.
4242
- `refresh_cache` - (Optional) Trigger a refresh of the cache by changing this field's value.
43+
- `include_cookies` - (Optional) Defines whether responses to requests with cookies must be stored in the cache.
4344
- `purge_requests` - (Optional) The Scaleway Object Storage origin bucket (S3) linked to the backend stage.
4445
- `pipeline_id` - The pipeline ID in which the purge request will be created.
4546
- `assets` - The list of asserts to purge.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/nats-io/jwt/v2 v2.7.4
2929
github.com/nats-io/nats.go v1.38.0
3030
github.com/robfig/cron/v3 v3.0.1
31-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250613133518-6987cd48643b
31+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250625143510-4421125d41b9
3232
github.com/stretchr/testify v1.10.0
3333
golang.org/x/crypto v0.38.0
3434
gopkg.in/dnaeon/go-vcr.v3 v3.2.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
447447
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
448448
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
449449
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
450-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250613133518-6987cd48643b h1:7V7T9XzUl+B/6zHeNxyX0DV3OVjCSedA0stHo0BNKZw=
451-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250613133518-6987cd48643b/go.mod h1:zFWiHphneiey3s8HOtAEnGrRlWivNaxW5T6d5Xfco7g=
450+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250625143510-4421125d41b9 h1:9twhtdDBC2hYdNk6dhdOUWyx+quP0MTsMyub8r6K86U=
451+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.33.0.20250625143510-4421125d41b9/go.mod h1:zFWiHphneiey3s8HOtAEnGrRlWivNaxW5T6d5Xfco7g=
452452
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
453453
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
454454
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=

internal/services/edgeservices/cache_stage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func ResourceCacheStage() *schema.Resource {
8686
Optional: true,
8787
Description: "Trigger a refresh of the cache by changing this field's value",
8888
},
89+
"include_cookies": {
90+
Type: schema.TypeBool,
91+
Optional: true,
92+
Description: "Defines whether responses to requests with cookies must be stored in the cache",
93+
},
8994
"created_at": {
9095
Type: schema.TypeString,
9196
Computed: true,
@@ -110,6 +115,7 @@ func ResourceCacheStageCreate(ctx context.Context, d *schema.ResourceData, m any
110115
RouteStageID: types.ExpandStringPtr(d.Get("route_stage_id").(string)),
111116
WafStageID: types.ExpandStringPtr(d.Get("waf_stage_id").(string)),
112117
FallbackTTL: &scw.Duration{Seconds: int64(d.Get("fallback_ttl").(int))},
118+
IncludeCookies: types.ExpandBoolPtr(d.Get("include_cookies").(bool)),
113119
}, scw.WithContext(ctx))
114120
if err != nil {
115121
return diag.FromErr(err)
@@ -143,6 +149,7 @@ func ResourceCacheStageRead(ctx context.Context, d *schema.ResourceData, m any)
143149
_ = d.Set("route_stage_id", types.FlattenStringPtr(cacheStage.RouteStageID))
144150
_ = d.Set("waf_stage_id", types.FlattenStringPtr(cacheStage.WafStageID))
145151
_ = d.Set("fallback_ttl", cacheStage.FallbackTTL.Seconds)
152+
_ = d.Set("include_cookies", cacheStage.IncludeCookies)
146153

147154
return nil
148155
}
@@ -176,6 +183,11 @@ func ResourceCacheStageUpdate(ctx context.Context, d *schema.ResourceData, m any
176183
hasChanged = true
177184
}
178185

186+
if d.HasChange("include_cookies") {
187+
updateRequest.IncludeCookies = types.ExpandBoolPtr(d.Get("include_cookies").(bool))
188+
hasChanged = true
189+
}
190+
179191
if hasChanged {
180192
_, err := api.UpdateCacheStage(updateRequest, scw.WithContext(ctx))
181193
if err != nil {

internal/services/edgeservices/cache_stage_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ func TestAccEdgeServicesCache_Basic(t *testing.T) {
3333
"scaleway_edge_services_pipeline.main", "id",
3434
"scaleway_edge_services_cache_stage.main", "pipeline_id"),
3535
resource.TestCheckResourceAttr("scaleway_edge_services_cache_stage.main", "fallback_ttl", "3600"),
36+
resource.TestCheckResourceAttr("scaleway_edge_services_cache_stage.main", "include_cookies", "false"),
37+
resource.TestCheckResourceAttrSet("scaleway_edge_services_cache_stage.main", "created_at"),
38+
resource.TestCheckResourceAttrSet("scaleway_edge_services_cache_stage.main", "updated_at"),
39+
),
40+
},
41+
{
42+
Config: `
43+
resource "scaleway_edge_services_pipeline" "main" {
44+
name = "my-edge_services-pipeline"
45+
description = "pipeline description"
46+
}
47+
48+
resource "scaleway_edge_services_cache_stage" "main" {
49+
pipeline_id = scaleway_edge_services_pipeline.main.id
50+
include_cookies = true
51+
fallback_ttl = 7200
52+
}
53+
`,
54+
Check: resource.ComposeTestCheckFunc(
55+
edgeservicestestfuncs.CheckEdgeServicesCacheExists(tt, "scaleway_edge_services_cache_stage.main"),
56+
resource.TestCheckResourceAttrPair(
57+
"scaleway_edge_services_pipeline.main", "id",
58+
"scaleway_edge_services_cache_stage.main", "pipeline_id"),
59+
resource.TestCheckResourceAttr("scaleway_edge_services_cache_stage.main", "fallback_ttl", "7200"),
60+
resource.TestCheckResourceAttr("scaleway_edge_services_cache_stage.main", "include_cookies", "true"),
3661
resource.TestCheckResourceAttrSet("scaleway_edge_services_cache_stage.main", "created_at"),
3762
resource.TestCheckResourceAttrSet("scaleway_edge_services_cache_stage.main", "updated_at"),
3863
),

0 commit comments

Comments
 (0)