Skip to content

Commit 791291d

Browse files
committed
remove position fields
1 parent d43bbd7 commit 791291d

File tree

4 files changed

+292
-328
lines changed

4 files changed

+292
-328
lines changed

docs/resources/edge_services_route_stage.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ Creates and manages Scaleway Edge Services Route Stages.
1515
resource "scaleway_edge_services_route_stage" "main" {
1616
pipeline_id = scaleway_edge_services_pipeline.main.id
1717
waf_stage_id = scaleway_edge_services_waf_stage.waf.id
18-
after_position = 0
1918
20-
rules {
19+
rule {
2120
backend_stage_id = scaleway_edge_services_backend_stage.backend.id
22-
2321
rule_http_match {
2422
method_filters = ["get", "post"]
25-
2623
path_filter {
2724
path_filter_type = "regex"
2825
value = ".*"
@@ -35,10 +32,8 @@ resource "scaleway_edge_services_route_stage" "main" {
3532
## Argument Reference
3633

3734
- `pipeline_id` - (Required) The ID of the pipeline.
38-
- `after_position` - (Optional) Add rules after the given position. Only one of `after_position` and `before_position` should be specified.
39-
- `before_position` - (Optional) Add rules before the given position. Only one of `after_position` and `before_position` should be specified.
4035
- `waf_stage_id` - (Optional) The ID of the WAF stage HTTP requests should be forwarded to when no rules are matched.
41-
- `rules` - (Optional) The list of rules to be checked against every HTTP request. The first matching rule will forward the request to its specified backend stage. If no rules are matched, the request is forwarded to the WAF stage defined by `waf_stage_id`.
36+
- `rule` - (Optional) The list of rules to be checked against every HTTP request. The first matching rule will forward the request to its specified backend stage. If no rules are matched, the request is forwarded to the WAF stage defined by `waf_stage_id`.
4237
- `backend_stage_id` (Required) The ID of the backend stage that requests matching the rule should be forwarded to.
4338
- `rule_http_match` (Optional) The rule condition to be matched. Requests matching the condition defined here will be directly forwarded to the backend specified by the `backend_stage_id` field. Requests that do not match will be checked by the next rule's condition.
4439
- `method_filters` (Optional) HTTP methods to filter for. A request using any of these methods will be considered to match the rule. Possible values are `get`, `post`, `put`, `patch`, `delete`, `head`, `options`. All methods will match if none is provided.

internal/services/edgeservices/route_stage.go

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,7 @@ func ResourceRouteStage() *schema.Resource {
3434
Optional: true,
3535
Description: "The ID of the WAF stage HTTP requests should be forwarded to when no rules are matched",
3636
},
37-
"after_position": {
38-
Type: schema.TypeInt,
39-
Optional: true,
40-
Description: "Add rules after the given position",
41-
ConflictsWith: []string{"before_position"},
42-
},
43-
"before_position": {
44-
Type: schema.TypeInt,
45-
Optional: true,
46-
Description: "Add rules before the given position",
47-
ConflictsWith: []string{"after_position"},
48-
},
49-
"rules": {
37+
"rule": {
5038
Type: schema.TypeList,
5139
Optional: true,
5240
Description: "List of rules to be checked against every HTTP request. The first matching rule will forward the request to its specified backend stage. If no rules are matched, the request is forwarded to the WAF stage defined by `waf_stage_id`",
@@ -127,25 +115,9 @@ func ResourceRouteStageCreate(ctx context.Context, d *schema.ResourceData, m int
127115
return diag.FromErr(err)
128116
}
129117

130-
var afterPosition *uint64
131-
if v, ok := d.GetOk("after_position"); ok {
132-
afterPosition = types.ExpandUint64Ptr(v)
133-
} else {
134-
afterPosition = nil
135-
}
136-
137-
var beforePosition *uint64
138-
if v, ok := d.GetOk("before_position"); ok {
139-
beforePosition = types.ExpandUint64Ptr(v)
140-
} else {
141-
beforePosition = nil
142-
}
143-
144-
_, err = api.AddRouteRules(&edgeservices.AddRouteRulesRequest{
145-
RouteStageID: routeStage.ID,
146-
AfterPosition: afterPosition,
147-
BeforePosition: beforePosition,
148-
RouteRules: expandRouteRules(d.Get("rules")),
118+
_, err = api.SetRouteRules(&edgeservices.SetRouteRulesRequest{
119+
RouteStageID: routeStage.ID,
120+
RouteRules: expandRouteRules(d.Get("rule")),
149121
}, scw.WithContext(ctx))
150122
if err != nil {
151123
return diag.FromErr(err)
@@ -184,7 +156,7 @@ func ResourceRouteStageRead(ctx context.Context, d *schema.ResourceData, m inter
184156
return diag.FromErr(err)
185157
}
186158

187-
_ = d.Set("rules", flattenRouteRules(routeRules.RouteRules))
159+
_ = d.Set("rule", flattenRouteRules(routeRules.RouteRules))
188160

189161
return nil
190162
}
@@ -210,10 +182,10 @@ func ResourceRouteStageUpdate(ctx context.Context, d *schema.ResourceData, m int
210182
}
211183
}
212184

213-
if d.HasChange("rules") {
185+
if d.HasChange("rule") {
214186
_, err := api.SetRouteRules(&edgeservices.SetRouteRulesRequest{
215187
RouteStageID: d.Id(),
216-
RouteRules: expandRouteRules(d.Get("rules")),
188+
RouteRules: expandRouteRules(d.Get("rule")),
217189
}, scw.WithContext(ctx))
218190
if err != nil {
219191
return diag.FromErr(err)

internal/services/edgeservices/route_stage_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ func TestAccEdgeServicesRoute_Basic(t *testing.T) {
4747
resource "scaleway_edge_services_route_stage" "main" {
4848
pipeline_id = scaleway_edge_services_pipeline.main.id
4949
waf_stage_id = scaleway_edge_services_waf_stage.waf.id
50-
after_position = 0
5150
52-
rules {
51+
rule {
5352
backend_stage_id = scaleway_edge_services_backend_stage.backend.id
54-
5553
rule_http_match {
5654
method_filters = ["get", "post"]
57-
5855
path_filter {
5956
path_filter_type = "regex"
6057
value = ".*"
@@ -67,17 +64,17 @@ func TestAccEdgeServicesRoute_Basic(t *testing.T) {
6764
edgeservicestestfuncs.CheckEdgeServicesRouteExists(tt, "scaleway_edge_services_route_stage.main"),
6865
resource.TestCheckResourceAttrPair(
6966
"scaleway_edge_services_backend_stage.backend", "id",
70-
"scaleway_edge_services_route_stage.main", "rules.0.backend_stage_id"),
67+
"scaleway_edge_services_route_stage.main", "rule.0.backend_stage_id"),
7168
resource.TestCheckResourceAttrPair(
7269
"scaleway_edge_services_waf_stage.waf", "id",
7370
"scaleway_edge_services_route_stage.main", "waf_stage_id"),
7471
resource.TestCheckResourceAttrPair(
7572
"scaleway_edge_services_waf_stage.waf", "id",
7673
"scaleway_edge_services_route_stage.main", "waf_stage_id"),
77-
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rules.0.rule_http_match.0.method_filters.0", "get"),
78-
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rules.0.rule_http_match.0.method_filters.1", "post"),
79-
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rules.0.rule_http_match.0.path_filter.0.path_filter_type", "regex"),
80-
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rules.0.rule_http_match.0.path_filter.0.value", ".*"),
74+
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rule.0.rule_http_match.0.method_filters.0", "get"),
75+
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rule.0.rule_http_match.0.method_filters.1", "post"),
76+
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rule.0.rule_http_match.0.path_filter.0.path_filter_type", "regex"),
77+
resource.TestCheckResourceAttr("scaleway_edge_services_route_stage.main", "rule.0.rule_http_match.0.path_filter.0.value", ".*"),
8178
resource.TestCheckResourceAttrSet("scaleway_edge_services_route_stage.main", "created_at"),
8279
resource.TestCheckResourceAttrSet("scaleway_edge_services_route_stage.main", "updated_at"),
8380
),

0 commit comments

Comments
 (0)