Skip to content

Commit 4eab8fb

Browse files
Jonas Gottliebrubenhoenle
authored andcommitted
feat: add dynamic_routes bool to routing_table
Add the optional bool flag "dynamic_routes" to the routing_table resource.
1 parent 6c9752a commit 4eab8fb

File tree

11 files changed

+73
-28
lines changed

11 files changed

+73
-28
lines changed

docs/data-sources/routing_table.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ data "stackit_routing_table" "example" {
4545
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
4646
- `name` (String) The name of the routing table.
4747
- `system_routes` (Boolean) This controls whether the routes for project-to-project communication are created automatically or not.
48+
- `dynamic_routes` (Boolean) This controls whether dynamic routes are propagated to this routing table
4849
- `updated_at` (String) Date-time when the routing table was updated

docs/data-sources/routing_tables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ Read-Only:
5151
- `name` (String) The name of the routing table.
5252
- `routing_table_id` (String) The routing tables ID.
5353
- `system_routes` (Boolean) This controls whether the routes for project-to-project communication are created automatically or not.
54+
- `dynamic_routes` (Boolean) This controls whether dynamic routes are propagated to this routing table
5455
- `updated_at` (String) Date-time when the routing table was updated

docs/resources/routing_table.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
4848
- `region` (String) The resource region. If not defined, the provider region is used.
4949
- `system_routes` (Boolean) This controls whether the routes for project-to-project communication are created automatically or not.
50+
- `dynamic_routes` (Boolean) This controls whether dynamic routes are propagated to this routing table
5051

5152
### Read-Only
5253

stackit/internal/services/iaas/iaas_acc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ func TestAccNetworkMax(t *testing.T) {
719719
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region),
720720
resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"),
721721
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"),
722+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"),
722723
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
723724
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
724725
),
@@ -803,6 +804,7 @@ func TestAccNetworkMax(t *testing.T) {
803804
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.Region),
804805
resource.TestCheckNoResourceAttr("data.stackit_routing_table.routing_table", "description"),
805806
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", "true"),
807+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"),
806808
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"),
807809
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"),
808810
),
@@ -952,6 +954,7 @@ func TestAccNetworkMax(t *testing.T) {
952954
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region),
953955
resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"),
954956
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"),
957+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"),
955958
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
956959
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
957960
),

stackit/internal/services/iaasalpha/iaasalpha_acc_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var testConfigRoutingTableMax = config.Variables{
6262
"description": config.StringVariable("This is the description of the routing table."),
6363
"label": config.StringVariable("routing-table-label-01"),
6464
"system_routes": config.BoolVariable(false),
65+
"dynamic_routes": config.BoolVariable(false),
6566
"region": config.StringVariable(testutil.Region),
6667
}
6768

@@ -133,6 +134,7 @@ func TestAccRoutingTable(t *testing.T) {
133134
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region),
134135
resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"),
135136
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"),
137+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"),
136138
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
137139
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
138140
),
@@ -172,6 +174,7 @@ func TestAccRoutingTable(t *testing.T) {
172174
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.Region),
173175
resource.TestCheckNoResourceAttr("data.stackit_routing_table.routing_table", "description"),
174176
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", "true"),
177+
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", "true"),
175178
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"),
176179
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"),
177180
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"),
@@ -197,6 +200,7 @@ func TestAccRoutingTable(t *testing.T) {
197200
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.%", "0"),
198201
resource.TestCheckNoResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description"),
199202
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", "true"),
203+
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", "true"),
200204
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"),
201205
resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"),
202206
resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"),
@@ -242,6 +246,7 @@ func TestAccRoutingTable(t *testing.T) {
242246
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region),
243247
resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"),
244248
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"),
249+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"),
245250
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
246251
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
247252
),
@@ -272,6 +277,7 @@ func TestAccRoutingTable(t *testing.T) {
272277
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])),
273278
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])),
274279
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])),
280+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])),
275281
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
276282
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
277283
),
@@ -312,6 +318,7 @@ func TestAccRoutingTable(t *testing.T) {
312318
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])),
313319
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])),
314320
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])),
321+
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])),
315322
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"),
316323
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"),
317324
resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"),
@@ -338,6 +345,7 @@ func TestAccRoutingTable(t *testing.T) {
338345
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])),
339346
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])),
340347
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])),
348+
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])),
341349
resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"),
342350
resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"),
343351
resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"),
@@ -384,6 +392,7 @@ func TestAccRoutingTable(t *testing.T) {
384392
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["region"])),
385393
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["description"])),
386394
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["system_routes"])),
395+
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["dynamic_routes"])),
387396
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"),
388397
resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"),
389398
),

stackit/internal/services/iaasalpha/routingtable/shared/shared.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type RoutingTableReadModel struct {
2626
UpdatedAt types.String `tfsdk:"updated_at"`
2727
Default types.Bool `tfsdk:"default"`
2828
SystemRoutes types.Bool `tfsdk:"system_routes"`
29+
DynamicRoutes types.Bool `tfsdk:"dynamic_routes"`
2930
}
3031

3132
func RoutingTableReadModelTypes() map[string]attr.Type {
@@ -38,6 +39,7 @@ func RoutingTableReadModelTypes() map[string]attr.Type {
3839
"updated_at": types.StringType,
3940
"default": types.BoolType,
4041
"system_routes": types.BoolType,
42+
"dynamic_routes": types.BoolType,
4143
}
4244
}
4345

@@ -208,6 +210,10 @@ func RoutingTableResponseAttributes() map[string]schema.Attribute {
208210
Description: "This controls whether the routes for project-to-project communication are created automatically or not.",
209211
Computed: true,
210212
},
213+
"dynamic_ro": schema.BoolAttribute{
214+
Description: "This controls whether the routes for project-to-project communication are created automatically or not.",
215+
Computed: true,
216+
},
211217
"created_at": schema.StringAttribute{
212218
Description: "Date-time when the routing table was created",
213219
Computed: true,
@@ -257,6 +263,7 @@ func MapRoutingTableReadModel(ctx context.Context, routingTable *iaasalpha.Routi
257263
model.Description = types.StringPointerValue(routingTable.Description)
258264
model.Default = types.BoolPointerValue(routingTable.Default)
259265
model.SystemRoutes = types.BoolPointerValue(routingTable.SystemRoutes)
266+
model.DynamicRoutes = types.BoolPointerValue(routingTable.DynamicRoutes)
260267
model.Labels = labels
261268
model.CreatedAt = createdAtTF
262269
model.UpdatedAt = updatedAtTF

stackit/internal/services/iaasalpha/routingtable/table/resource.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Model struct {
4848
Labels types.Map `tfsdk:"labels"`
4949
Region types.String `tfsdk:"region"`
5050
SystemRoutes types.Bool `tfsdk:"system_routes"`
51+
DynamicRoutes types.Bool `tfsdk:"dynamic_routes"`
5152
CreatedAt types.String `tfsdk:"created_at"`
5253
UpdatedAt types.String `tfsdk:"updated_at"`
5354
}
@@ -206,6 +207,15 @@ func (r *routingTableResource) Schema(_ context.Context, _ resource.SchemaReques
206207
boolplanmodifier.RequiresReplace(),
207208
},
208209
},
210+
"dynamic_routes": schema.BoolAttribute{
211+
Description: "This controls whether the routes for project-to-project communication are created automatically or not.",
212+
Optional: true,
213+
Computed: true,
214+
Default: booldefault.StaticBool(true),
215+
PlanModifiers: []planmodifier.Bool{
216+
boolplanmodifier.RequiresReplace(),
217+
},
218+
},
209219
"created_at": schema.StringAttribute{
210220
Description: "Date-time when the routing table was created",
211221
Computed: true,
@@ -485,6 +495,7 @@ func mapFields(ctx context.Context, routingTable *iaasalpha.RoutingTable, model
485495
model.Labels = labels
486496
model.Region = types.StringValue(region)
487497
model.SystemRoutes = types.BoolPointerValue(routingTable.SystemRoutes)
498+
model.DynamicRoutes = types.BoolPointerValue(routingTable.DynamicRoutes)
488499
model.CreatedAt = createdAtTF
489500
model.UpdatedAt = updatedAtTF
490501
return nil
@@ -501,10 +512,11 @@ func toCreatePayload(ctx context.Context, model *Model) (*iaasalpha.AddRoutingTa
501512
}
502513

503514
return &iaasalpha.AddRoutingTableToAreaPayload{
504-
Description: conversion.StringValueToPointer(model.Description),
505-
Name: conversion.StringValueToPointer(model.Name),
506-
Labels: &labels,
507-
SystemRoutes: conversion.BoolValueToPointer(model.SystemRoutes),
515+
Description: conversion.StringValueToPointer(model.Description),
516+
Name: conversion.StringValueToPointer(model.Name),
517+
Labels: &labels,
518+
SystemRoutes: conversion.BoolValueToPointer(model.SystemRoutes),
519+
DynamicRoutes: conversion.BoolValueToPointer(model.DynamicRoutes),
508520
}, nil
509521
}
510522

stackit/internal/services/iaasalpha/routingtable/table/resource_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ func TestToCreatePayload(t *testing.T) {
132132
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
133133
"key": types.StringValue("value"),
134134
}),
135-
SystemRoutes: types.BoolValue(true),
135+
SystemRoutes: types.BoolValue(true),
136+
DynamicRoutes: types.BoolValue(true),
136137
},
137138
expected: &iaasalpha.AddRoutingTableToAreaPayload{
138139
Description: utils.Ptr("Description"),
139140
Name: utils.Ptr("default_ok"),
140141
Labels: &map[string]interface{}{
141142
"key": "value",
142143
},
143-
SystemRoutes: utils.Ptr(true),
144+
SystemRoutes: utils.Ptr(true),
145+
DynamicRoutes: utils.Ptr(true),
144146
},
145147
isValid: true,
146148
},

stackit/internal/services/iaasalpha/routingtable/tables/datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func mapDataSourceRoutingTables(ctx context.Context, routingTables *iaasalpha.Ro
196196
"updated_at": routingTableModel.UpdatedAt,
197197
"default": routingTableModel.Default,
198198
"system_routes": routingTableModel.SystemRoutes,
199+
"dynamic_routes": routingTableModel.DynamicRoutes,
199200
}
200201

201202
routingTableTF, diags := types.ObjectValue(shared.RoutingTableReadModelTypes(), routingTableMap)

stackit/internal/services/iaasalpha/routingtable/tables/datasource_test.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ func TestMapDataFields(t *testing.T) {
4949
&iaasalpha.RoutingTableListResponse{
5050
Items: &[]iaasalpha.RoutingTable{
5151
{
52-
Id: utils.Ptr(routingTableId.String()),
53-
Name: utils.Ptr("test"),
54-
Description: utils.Ptr("description"),
55-
Default: utils.Ptr(true),
56-
CreatedAt: &createdAt,
57-
UpdatedAt: &updatedAt,
58-
SystemRoutes: utils.Ptr(false),
52+
Id: utils.Ptr(routingTableId.String()),
53+
Name: utils.Ptr("test"),
54+
Description: utils.Ptr("description"),
55+
Default: utils.Ptr(true),
56+
CreatedAt: &createdAt,
57+
UpdatedAt: &updatedAt,
58+
SystemRoutes: utils.Ptr(false),
59+
DynamicRoutes: utils.Ptr(false),
5960
},
6061
},
6162
},
@@ -71,6 +72,7 @@ func TestMapDataFields(t *testing.T) {
7172
"description": types.StringValue("description"),
7273
"default": types.BoolValue(true),
7374
"system_routes": types.BoolValue(false),
75+
"dynamic_routes": types.BoolValue(false),
7476
"created_at": types.StringValue(createdAt.Format(time.RFC3339)),
7577
"updated_at": types.StringValue(updatedAt.Format(time.RFC3339)),
7678
"labels": types.MapNull(types.StringType),
@@ -89,22 +91,24 @@ func TestMapDataFields(t *testing.T) {
8991
&iaasalpha.RoutingTableListResponse{
9092
Items: &[]iaasalpha.RoutingTable{
9193
{
92-
Id: utils.Ptr(routingTableId.String()),
93-
Name: utils.Ptr("test"),
94-
Description: utils.Ptr("description"),
95-
Default: utils.Ptr(true),
96-
CreatedAt: &createdAt,
97-
UpdatedAt: &updatedAt,
98-
SystemRoutes: utils.Ptr(false),
94+
Id: utils.Ptr(routingTableId.String()),
95+
Name: utils.Ptr("test"),
96+
Description: utils.Ptr("description"),
97+
Default: utils.Ptr(true),
98+
CreatedAt: &createdAt,
99+
UpdatedAt: &updatedAt,
100+
SystemRoutes: utils.Ptr(false),
101+
DynamicRoutes: utils.Ptr(false),
99102
},
100103
{
101-
Id: utils.Ptr(secondRoutingTableId.String()),
102-
Name: utils.Ptr("test2"),
103-
Description: utils.Ptr("description2"),
104-
Default: utils.Ptr(false),
105-
CreatedAt: &createdAt,
106-
UpdatedAt: &updatedAt,
107-
SystemRoutes: utils.Ptr(false),
104+
Id: utils.Ptr(secondRoutingTableId.String()),
105+
Name: utils.Ptr("test2"),
106+
Description: utils.Ptr("description2"),
107+
Default: utils.Ptr(false),
108+
CreatedAt: &createdAt,
109+
UpdatedAt: &updatedAt,
110+
SystemRoutes: utils.Ptr(false),
111+
DynamicRoutes: utils.Ptr(false),
108112
},
109113
},
110114
},
@@ -120,6 +124,7 @@ func TestMapDataFields(t *testing.T) {
120124
"description": types.StringValue("description"),
121125
"default": types.BoolValue(true),
122126
"system_routes": types.BoolValue(false),
127+
"dynamic_routes": types.BoolValue(false),
123128
"created_at": types.StringValue(createdAt.Format(time.RFC3339)),
124129
"updated_at": types.StringValue(updatedAt.Format(time.RFC3339)),
125130
"labels": types.MapNull(types.StringType),
@@ -130,6 +135,7 @@ func TestMapDataFields(t *testing.T) {
130135
"description": types.StringValue("description2"),
131136
"default": types.BoolValue(false),
132137
"system_routes": types.BoolValue(false),
138+
"dynamic_routes": types.BoolValue(false),
133139
"created_at": types.StringValue(createdAt.Format(time.RFC3339)),
134140
"updated_at": types.StringValue(updatedAt.Format(time.RFC3339)),
135141
"labels": types.MapNull(types.StringType),

0 commit comments

Comments
 (0)