Skip to content

Commit bc23af8

Browse files
authored
feat(edge-services): support route and waf references on cache & tls stages (#3035)
* feat(edge-services): support route and waf references on cache and tls stages * lint * add ConflictWith on stages * use const
1 parent e957634 commit bc23af8

File tree

9 files changed

+137
-46
lines changed

9 files changed

+137
-46
lines changed

docs/resources/edge_services_cache_stage.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ resource "scaleway_edge_services_cache_stage" "main" {
3535
## Argument Reference
3636

3737
- `pipeline_id` - (Required) The ID of the pipeline.
38-
- `backend_stage_id` - (Optional) The backend stage ID the cache stage will be linked to.
38+
- `backend_stage_id` - (Optional) The backend 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.
39+
- `route_stage_id` - (Optional) The route 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.
40+
- `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.
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_dns_stage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ resource "scaleway_edge_services_dns_stage" "main" {
2121
## Argument Reference
2222

2323
- `pipeline_id` - (Required) The ID of the pipeline.
24-
- `backend_stage_id` - (Optional) The backend stage ID the DNS stage will be linked to.
25-
- `tls_stage_id` - (Optional) The TLS stage ID the DNS stage will be linked to.
26-
- `cache_stage_id` - (Optional) The cache stage ID the DNS stage will be linked to.
24+
- `backend_stage_id` - (Optional) The backend stage ID the DNS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id` and `tls_stage_id` should be specified.
25+
- `tls_stage_id` - (Optional) The TLS stage ID the DNS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id` and `tls_stage_id` should be specified.
26+
- `cache_stage_id` - (Optional) The cache stage ID the DNS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id` and `tls_stage_id` should be specified.
2727
- `fqdns` - (Optional) Fully Qualified Domain Name (in the format subdomain.example.com) to attach to the stage.
2828
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the DNS stage is associated with.
2929

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ resource "scaleway_edge_services_tls_stage" "main" {
3333
## Argument Reference
3434

3535
- `pipeline_id` - (Required) The ID of the pipeline.
36-
- `backend_stage_id` - (Optional) The backend stage ID the TLS stage will be linked to.
37-
- `cache_stage_id` - (Optional) The cache stage ID the TLS stage will be linked to.
36+
- `backend_stage_id` - (Optional) The backend stage ID the TLS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id`, `route_stage_id` and `waf_stage_id` should be specified.
37+
- `cache_stage_id` - (Optional) The cache stage ID the TLS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id`, `route_stage_id` and `waf_stage_id` should be specified.
38+
- `route_stage_id` - (Optional) The route stage ID the TLS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id`, `route_stage_id` and `waf_stage_id` should be specified.
39+
- `waf_stage_id` - (Optional) The WAF stage ID the TLS stage will be linked to. Only one of `backend_stage_id`, `cache_stage_id`, `route_stage_id` and `waf_stage_id` should be specified.
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/container/container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func isContainerPresent(tt *acctest.TestTools, n string) resource.TestCheckFunc
575575
func isContainerDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
576576
return func(state *terraform.State) error {
577577
for _, rs := range state.RootModule().Resources {
578-
if rs.Type != "scaleway_container_namespace" { //nolint:goconst
578+
if rs.Type != containerNamespaceResource {
579579
continue
580580
}
581581

internal/services/container/namespace_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/registry"
1515
)
1616

17+
const containerNamespaceResource = "scaleway_container_namespace"
18+
1719
func TestAccNamespace_Basic(t *testing.T) {
1820
tt := acctest.NewTestTools(t)
1921
defer tt.Cleanup()
@@ -313,7 +315,7 @@ func isNamespacePresent(tt *acctest.TestTools, n string) resource.TestCheckFunc
313315
func isNamespaceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
314316
return func(state *terraform.State) error {
315317
for _, rs := range state.RootModule().Resources {
316-
if rs.Type != "scaleway_container_namespace" {
318+
if rs.Type != containerNamespaceResource {
317319
continue
318320
}
319321

@@ -343,7 +345,7 @@ func isNamespaceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
343345
func isRegistryDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
344346
return func(state *terraform.State) error {
345347
for _, rs := range state.RootModule().Resources {
346-
if rs.Type != "scaleway_container_namespace" {
348+
if rs.Type != containerNamespaceResource {
347349
continue
348350
}
349351

internal/services/edgeservices/cache_stage.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,25 @@ func ResourceCacheStage() *schema.Resource {
2929
Description: "The ID of the pipeline",
3030
},
3131
"backend_stage_id": {
32-
Type: schema.TypeString,
33-
Optional: true,
34-
Computed: true,
35-
Description: "The backend stage ID the cache stage will be linked to",
32+
Type: schema.TypeString,
33+
Optional: true,
34+
Computed: true,
35+
Description: "The backend stage ID the cache stage will be linked to",
36+
ConflictsWith: []string{"waf_stage_id", "route_stage_id"},
37+
},
38+
"waf_stage_id": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Computed: true,
42+
Description: "The WAF stage ID the cache stage will be linked to",
43+
ConflictsWith: []string{"backend_stage_id", "route_stage_id"},
44+
},
45+
"route_stage_id": {
46+
Type: schema.TypeString,
47+
Optional: true,
48+
Computed: true,
49+
Description: "The route stage ID the cache stage will be linked to",
50+
ConflictsWith: []string{"backend_stage_id", "waf_stage_id"},
3651
},
3752
"fallback_ttl": {
3853
Type: schema.TypeInt,
@@ -92,6 +107,8 @@ func ResourceCacheStageCreate(ctx context.Context, d *schema.ResourceData, m int
92107
cacheStage, err := api.CreateCacheStage(&edgeservices.CreateCacheStageRequest{
93108
PipelineID: d.Get("pipeline_id").(string),
94109
BackendStageID: types.ExpandStringPtr(d.Get("backend_stage_id").(string)),
110+
RouteStageID: types.ExpandStringPtr(d.Get("route_stage_id").(string)),
111+
WafStageID: types.ExpandStringPtr(d.Get("waf_stage_id").(string)),
95112
FallbackTTL: &scw.Duration{Seconds: int64(d.Get("fallback_ttl").(int))},
96113
}, scw.WithContext(ctx))
97114
if err != nil {
@@ -123,6 +140,8 @@ func ResourceCacheStageRead(ctx context.Context, d *schema.ResourceData, m inter
123140
_ = d.Set("created_at", types.FlattenTime(cacheStage.CreatedAt))
124141
_ = d.Set("updated_at", types.FlattenTime(cacheStage.UpdatedAt))
125142
_ = d.Set("backend_stage_id", types.FlattenStringPtr(cacheStage.BackendStageID))
143+
_ = d.Set("route_stage_id", types.FlattenStringPtr(cacheStage.RouteStageID))
144+
_ = d.Set("waf_stage_id", types.FlattenStringPtr(cacheStage.WafStageID))
126145
_ = d.Set("fallback_ttl", cacheStage.FallbackTTL.Seconds)
127146

128147
return nil
@@ -142,6 +161,16 @@ func ResourceCacheStageUpdate(ctx context.Context, d *schema.ResourceData, m int
142161
hasChanged = true
143162
}
144163

164+
if d.HasChange("route_stage_id") {
165+
updateRequest.RouteStageID = types.ExpandUpdatedStringPtr(d.Get("route_stage_id"))
166+
hasChanged = true
167+
}
168+
169+
if d.HasChange("waf_stage_id") {
170+
updateRequest.WafStageID = types.ExpandUpdatedStringPtr(d.Get("waf_stage_id"))
171+
hasChanged = true
172+
}
173+
145174
if d.HasChange("fallback_ttl") {
146175
updateRequest.FallbackTTL = &scw.Duration{Seconds: int64(d.Get("fallback_ttl").(int))}
147176
hasChanged = true

internal/services/edgeservices/dns_stage.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ func ResourceDNSStage() *schema.Resource {
2929
Description: "The ID of the pipeline",
3030
},
3131
"backend_stage_id": {
32-
Type: schema.TypeString,
33-
Optional: true,
34-
Computed: true,
35-
Description: "The backend stage ID the DNS stage will be linked to",
32+
Type: schema.TypeString,
33+
Optional: true,
34+
Computed: true,
35+
Description: "The backend stage ID the DNS stage will be linked to",
36+
ConflictsWith: []string{"cache_stage_id", "tls_stage_id"},
3637
},
3738
"tls_stage_id": {
38-
Type: schema.TypeString,
39-
Optional: true,
40-
Computed: true,
41-
Description: "The TLS stage ID the DNS stage will be linked to",
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Computed: true,
42+
Description: "The TLS stage ID the DNS stage will be linked to",
43+
ConflictsWith: []string{"cache_stage_id", "backend_stage_id"},
4244
},
4345
"cache_stage_id": {
44-
Type: schema.TypeString,
45-
Optional: true,
46-
Computed: true,
47-
Description: "The cache stage ID the DNS stage will be linked to",
46+
Type: schema.TypeString,
47+
Optional: true,
48+
Computed: true,
49+
Description: "The cache stage ID the DNS stage will be linked to",
50+
ConflictsWith: []string{"backend_stage_id", "tls_stage_id"},
4851
},
4952
"fqdns": {
5053
Type: schema.TypeList,

internal/services/edgeservices/tls_stage.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,32 @@ func ResourceTLSStage() *schema.Resource {
3030
Description: "The ID of the pipeline",
3131
},
3232
"backend_stage_id": {
33-
Type: schema.TypeString,
34-
Optional: true,
35-
Computed: true,
36-
Description: "The backend stage ID the TLS stage will be linked to",
33+
Type: schema.TypeString,
34+
Optional: true,
35+
Computed: true,
36+
Description: "The backend stage ID the TLS stage will be linked to",
37+
ConflictsWith: []string{"cache_stage_id", "route_stage_id", "waf_stage_id"},
3738
},
3839
"cache_stage_id": {
39-
Type: schema.TypeString,
40-
Optional: true,
41-
Computed: true,
42-
Description: "The cache stage ID the TLS stage will be linked to",
40+
Type: schema.TypeString,
41+
Optional: true,
42+
Computed: true,
43+
Description: "The cache stage ID the TLS stage will be linked to",
44+
ConflictsWith: []string{"backend_stage_id", "route_stage_id", "waf_stage_id"},
45+
},
46+
"waf_stage_id": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Computed: true,
50+
Description: "The WAF stage ID the TLS stage will be linked to",
51+
ConflictsWith: []string{"backend_stage_id", "cache_stage_id", "route_stage_id"},
52+
},
53+
"route_stage_id": {
54+
Type: schema.TypeString,
55+
Optional: true,
56+
Computed: true,
57+
Description: "The route stage ID the TLS stage will be linked to",
58+
ConflictsWith: []string{"backend_stage_id", "cache_stage_id", "waf_stage_id"},
4359
},
4460
"managed_certificate": {
4561
Type: schema.TypeBool,
@@ -94,6 +110,8 @@ func ResourceTLSStageCreate(ctx context.Context, d *schema.ResourceData, m inter
94110
PipelineID: d.Get("pipeline_id").(string),
95111
BackendStageID: types.ExpandStringPtr(d.Get("backend_stage_id").(string)),
96112
CacheStageID: types.ExpandStringPtr(d.Get("cache_stage_id").(string)),
113+
RouteStageID: types.ExpandStringPtr(d.Get("route_stage_id").(string)),
114+
WafStageID: types.ExpandStringPtr(d.Get("waf_stage_id").(string)),
97115
ManagedCertificate: types.ExpandBoolPtr(d.Get("managed_certificate").(bool)),
98116
Secrets: expandTLSSecrets(d.Get("secrets"), region),
99117
}, scw.WithContext(ctx))
@@ -124,6 +142,8 @@ func ResourceTLSStageRead(ctx context.Context, d *schema.ResourceData, m interfa
124142

125143
_ = d.Set("backend_stage_id", types.FlattenStringPtr(tlsStage.BackendStageID))
126144
_ = d.Set("cache_stage_id", types.FlattenStringPtr(tlsStage.CacheStageID))
145+
_ = d.Set("route_stage_id", types.FlattenStringPtr(tlsStage.RouteStageID))
146+
_ = d.Set("waf_stage_id", types.FlattenStringPtr(tlsStage.WafStageID))
127147
_ = d.Set("pipeline_id", tlsStage.PipelineID)
128148
_ = d.Set("managed_certificate", tlsStage.ManagedCertificate)
129149
_ = d.Set("secrets", flattenTLSSecrets(tlsStage.Secrets))
@@ -156,6 +176,16 @@ func ResourceTLSStageUpdate(ctx context.Context, d *schema.ResourceData, m inter
156176
hasChanged = true
157177
}
158178

179+
if d.HasChange("route_stage_id") {
180+
updateRequest.RouteStageID = types.ExpandUpdatedStringPtr(d.Get("route_stage_id"))
181+
hasChanged = true
182+
}
183+
184+
if d.HasChange("waf_stage_id") {
185+
updateRequest.WafStageID = types.ExpandUpdatedStringPtr(d.Get("waf_stage_id"))
186+
hasChanged = true
187+
}
188+
159189
if d.HasChange("managed_certificate") {
160190
updateRequest.ManagedCertificate = types.ExpandBoolPtr(d.Get("managed_certificate"))
161191
hasChanged = true

0 commit comments

Comments
 (0)