Skip to content

Commit d557ca5

Browse files
committed
feat(edge-services): support route and waf references on cache and tls stages
1 parent 410bdbd commit d557ca5

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

docs/resources/edge_services_cache_stage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ resource "scaleway_edge_services_cache_stage" "main" {
3636

3737
- `pipeline_id` - (Required) The ID of the pipeline.
3838
- `backend_stage_id` - (Optional) The backend stage ID the cache stage will be linked to.
39+
- `route_stage_id` - (Optional) The route stage ID the cache stage will be linked to.
40+
- `waf_stage_id` - (Optional) The WAF stage ID the cache stage will be linked to.
3941
- `fallback_ttl` - (Optional) The Time To Live (TTL) in seconds. Defines how long content is cached.
4042
- `refresh_cache` - (Optional) Trigger a refresh of the cache by changing this field's value.
4143
- `purge_requests` - (Optional) The Scaleway Object Storage origin bucket (S3) linked to the backend stage.

docs/resources/edge_services_pipeline.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ resource "scaleway_edge_services_pipeline" "main" {
2626
description = "pipeline description"
2727
}
2828
29-
resource "scaleway_edge_services_backend_stage" "main" {
30-
pipeline_id = scaleway_edge_services_pipeline.main.id
31-
s3_backend_config {
32-
bucket_name = "my-bucket-name"
33-
bucket_region = "fr-par"
34-
}
29+
resource "scaleway_edge_services_dns_stage" "main" {
30+
pipeline_id = scaleway_edge_services_pipeline.main.id
31+
tls_stage_id = scaleway_edge_services_tls_stage.main.id
32+
fqdns = ["subdomain.example.com"]
3533
}
3634
3735
resource "scaleway_edge_services_tls_stage" "main" {
@@ -40,20 +38,45 @@ resource "scaleway_edge_services_tls_stage" "main" {
4038
managed_certificate = true
4139
}
4240
43-
resource "scaleway_edge_services_dns_stage" "main" {
44-
pipeline_id = scaleway_edge_services_pipeline.main.id
45-
tls_stage_id = scaleway_edge_services_tls_stage.main.id
46-
fqdns = ["subdomain.example.com"]
41+
resource "scaleway_edge_services_cache_stage" "main" {
42+
pipeline_id = scaleway_edge_services_pipeline.main.id
43+
route_stage_id = scaleway_edge_services_route_stage.main.id
4744
}
4845
49-
resource "scaleway_edge_services_head_stage" "main" {
46+
resource "scaleway_edge_services_route_stage" "main" {
5047
pipeline_id = scaleway_edge_services_pipeline.main.id
51-
head_stage_id = scaleway_edge_services_dns_stage.main.id
48+
waf_stage_id = scaleway_edge_services_waf_stage.main.id
49+
50+
rule {
51+
backend_stage_id = scaleway_edge_services_backend_stage.main.id
52+
rule_http_match {
53+
method_filters = ["get", "post"]
54+
path_filter {
55+
path_filter_type = "regex"
56+
value = ".*"
57+
}
58+
}
59+
}
5260
}
5361
54-
resource "scaleway_edge_services_cache_stage" "main" {
62+
resource "scaleway_edge_services_waf_stage" "main" {
5563
pipeline_id = scaleway_edge_services_pipeline.main.id
5664
backend_stage_id = scaleway_edge_services_backend_stage.main.id
65+
mode = "enable"
66+
paranoia_level = 3
67+
}
68+
69+
resource "scaleway_edge_services_backend_stage" "main" {
70+
pipeline_id = scaleway_edge_services_pipeline.main.id
71+
s3_backend_config {
72+
bucket_name = "my-bucket-name"
73+
bucket_region = "fr-par"
74+
}
75+
}
76+
77+
resource "scaleway_edge_services_head_stage" "main" {
78+
pipeline_id = scaleway_edge_services_pipeline.main.id
79+
head_stage_id = scaleway_edge_services_dns_stage.main.id
5780
}
5881
```
5982

docs/resources/edge_services_tls_stage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ resource "scaleway_edge_services_tls_stage" "main" {
3535
- `pipeline_id` - (Required) The ID of the pipeline.
3636
- `backend_stage_id` - (Optional) The backend stage ID the TLS stage will be linked to.
3737
- `cache_stage_id` - (Optional) The cache stage ID the TLS stage will be linked to.
38+
- `route_stage_id` - (Optional) The route stage ID the TLS stage will be linked to.
39+
- `waf_stage_id` - (Optional) The WAF stage ID the TLS stage will be linked to.
3840
- `managed_certificate` - (Optional) Set to true when Scaleway generates and manages a Let's Encrypt certificate for the TLS stage/custom endpoint.
3941
- `secrets` - (Optional) The TLS secrets.
4042
- `bucket_name` - The ID of the secret.

internal/services/edgeservices/cache_stage.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ func ResourceCacheStage() *schema.Resource {
3434
Computed: true,
3535
Description: "The backend stage ID the cache stage will be linked to",
3636
},
37+
"waf_stage_id": {
38+
Type: schema.TypeString,
39+
Optional: true,
40+
Computed: true,
41+
Description: "The WAF stage ID the cache stage will be linked to",
42+
},
43+
"route_stage_id": {
44+
Type: schema.TypeString,
45+
Optional: true,
46+
Computed: true,
47+
Description: "The route stage ID the cache stage will be linked to",
48+
},
3749
"fallback_ttl": {
3850
Type: schema.TypeInt,
3951
Optional: true,
@@ -92,6 +104,8 @@ func ResourceCacheStageCreate(ctx context.Context, d *schema.ResourceData, m int
92104
cacheStage, err := api.CreateCacheStage(&edgeservices.CreateCacheStageRequest{
93105
PipelineID: d.Get("pipeline_id").(string),
94106
BackendStageID: types.ExpandStringPtr(d.Get("backend_stage_id").(string)),
107+
RouteStageID: types.ExpandStringPtr(d.Get("route_stage_id").(string)),
108+
WafStageID: types.ExpandStringPtr(d.Get("waf_stage_id").(string)),
95109
FallbackTTL: &scw.Duration{Seconds: int64(d.Get("fallback_ttl").(int))},
96110
}, scw.WithContext(ctx))
97111
if err != nil {
@@ -123,6 +137,8 @@ func ResourceCacheStageRead(ctx context.Context, d *schema.ResourceData, m inter
123137
_ = d.Set("created_at", types.FlattenTime(cacheStage.CreatedAt))
124138
_ = d.Set("updated_at", types.FlattenTime(cacheStage.UpdatedAt))
125139
_ = d.Set("backend_stage_id", types.FlattenStringPtr(cacheStage.BackendStageID))
140+
_ = d.Set("route_stage_id", types.FlattenStringPtr(cacheStage.RouteStageID))
141+
_ = d.Set("waf_stage_id", types.FlattenStringPtr(cacheStage.WafStageID))
126142
_ = d.Set("fallback_ttl", cacheStage.FallbackTTL.Seconds)
127143

128144
return nil
@@ -142,6 +158,16 @@ func ResourceCacheStageUpdate(ctx context.Context, d *schema.ResourceData, m int
142158
hasChanged = true
143159
}
144160

161+
if d.HasChange("route_stage_id") {
162+
updateRequest.RouteStageID = types.ExpandUpdatedStringPtr(d.Get("route_stage_id"))
163+
hasChanged = true
164+
}
165+
166+
if d.HasChange("waf_stage_id") {
167+
updateRequest.WafStageID = types.ExpandUpdatedStringPtr(d.Get("waf_stage_id"))
168+
hasChanged = true
169+
}
170+
145171
if d.HasChange("fallback_ttl") {
146172
updateRequest.FallbackTTL = &scw.Duration{Seconds: int64(d.Get("fallback_ttl").(int))}
147173
hasChanged = true

internal/services/edgeservices/tls_stage.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ func ResourceTLSStage() *schema.Resource {
4141
Computed: true,
4242
Description: "The cache stage ID the TLS stage will be linked to",
4343
},
44+
"waf_stage_id": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
Computed: true,
48+
Description: "The WAF stage ID the TLS stage will be linked to",
49+
},
50+
"route_stage_id": {
51+
Type: schema.TypeString,
52+
Optional: true,
53+
Computed: true,
54+
Description: "The route stage ID the TLS stage will be linked to",
55+
},
4456
"managed_certificate": {
4557
Type: schema.TypeBool,
4658
Optional: true,
@@ -94,6 +106,8 @@ func ResourceTLSStageCreate(ctx context.Context, d *schema.ResourceData, m inter
94106
PipelineID: d.Get("pipeline_id").(string),
95107
BackendStageID: types.ExpandStringPtr(d.Get("backend_stage_id").(string)),
96108
CacheStageID: types.ExpandStringPtr(d.Get("cache_stage_id").(string)),
109+
RouteStageID: types.ExpandStringPtr(d.Get("route_stage_id").(string)),
110+
WafStageID: types.ExpandStringPtr(d.Get("waf_stage_id").(string)),
97111
ManagedCertificate: types.ExpandBoolPtr(d.Get("managed_certificate").(bool)),
98112
Secrets: expandTLSSecrets(d.Get("secrets"), region),
99113
}, scw.WithContext(ctx))
@@ -124,6 +138,8 @@ func ResourceTLSStageRead(ctx context.Context, d *schema.ResourceData, m interfa
124138

125139
_ = d.Set("backend_stage_id", types.FlattenStringPtr(tlsStage.BackendStageID))
126140
_ = d.Set("cache_stage_id", types.FlattenStringPtr(tlsStage.CacheStageID))
141+
_ = d.Set("route_stage_id", types.FlattenStringPtr(tlsStage.RouteStageID))
142+
_ = d.Set("waf_stage_id", types.FlattenStringPtr(tlsStage.WafStageID))
127143
_ = d.Set("pipeline_id", tlsStage.PipelineID)
128144
_ = d.Set("managed_certificate", tlsStage.ManagedCertificate)
129145
_ = d.Set("secrets", flattenTLSSecrets(tlsStage.Secrets))
@@ -156,6 +172,16 @@ func ResourceTLSStageUpdate(ctx context.Context, d *schema.ResourceData, m inter
156172
hasChanged = true
157173
}
158174

175+
if d.HasChange("route_stage_id") {
176+
updateRequest.RouteStageID = types.ExpandUpdatedStringPtr(d.Get("route_stage_id"))
177+
hasChanged = true
178+
}
179+
180+
if d.HasChange("waf_stage_id") {
181+
updateRequest.WafStageID = types.ExpandUpdatedStringPtr(d.Get("waf_stage_id"))
182+
hasChanged = true
183+
}
184+
159185
if d.HasChange("managed_certificate") {
160186
updateRequest.ManagedCertificate = types.ExpandBoolPtr(d.Get("managed_certificate"))
161187
hasChanged = true

0 commit comments

Comments
 (0)