Skip to content

Commit 8555662

Browse files
authored
feat(iaas): use SNA ipv4 nameserver when nameserver is unset in network resource (#1281)
relates to STACKITTPR-345
1 parent b452eb5 commit 8555662

6 files changed

Lines changed: 251 additions & 200 deletions

File tree

docs/data-sources/network.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ data "stackit_network" "example" {
4747
- `ipv6_prefixes` (List of String) The IPv6 prefixes of the network.
4848
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
4949
- `name` (String) The name of the network.
50-
- `nameservers` (List of String, Deprecated) The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.
51-
- `prefixes` (List of String, Deprecated) The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.
5250
- `public_ip` (String) The public IP of the network.
5351
- `routed` (Boolean) Shows if the network is routed and therefore accessible from other networks.
5452
- `routing_table_id` (String) The ID of the routing table associated with the network.

docs/resources/network.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ page_title: "stackit_network Resource - stackit"
44
subcategory: ""
55
description: |-
66
Network resource schema. Must have a region specified in the provider configuration.
7-
~> Behavior of not configured ipv4_nameservers will change from January 2026. When ipv4_nameservers is not set, it will be set to the network area's default_nameservers.
7+
~> Behavior of not configured ipv4_nameservers has changed. When ipv4_nameservers is not set, it will be set to the network area's default_nameservers.
88
To prevent any nameserver configuration, the ipv4_nameservers attribute should be explicitly set to an empty list [].
99
In cases where ipv4_nameservers are defined within the resource, the existing behavior will remain unchanged.
1010
---
1111

1212
# stackit_network (Resource)
1313

1414
Network resource schema. Must have a `region` specified in the provider configuration.
15-
~> Behavior of not configured `ipv4_nameservers` will change from January 2026. When `ipv4_nameservers` is not set, it will be set to the network area's `default_nameservers`.
15+
~> Behavior of not configured `ipv4_nameservers` has changed. When `ipv4_nameservers` is not set, it will be set to the network area's `default_nameservers`.
1616
To prevent any nameserver configuration, the `ipv4_nameservers` attribute should be explicitly set to an empty list `[]`.
1717
In cases where `ipv4_nameservers` are defined within the resource, the existing behavior will remain unchanged.
1818

@@ -66,15 +66,14 @@ import {
6666

6767
- `dhcp` (Boolean) If the network has DHCP enabled. Default value is `true`.
6868
- `ipv4_gateway` (String) The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
69-
- `ipv4_nameservers` (List of String) The IPv4 nameservers of the network.
69+
- `ipv4_nameservers` (List of String) The IPv4 nameservers of the network. If not specified on creation, it will be set with the default nameservers from the network area. If not specified on update, it will remain unchanged.
7070
- `ipv4_prefix` (String) The IPv4 prefix of the network (CIDR).
7171
- `ipv4_prefix_length` (Number) The IPv4 prefix length of the network.
7272
- `ipv6_gateway` (String) The IPv6 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
7373
- `ipv6_nameservers` (List of String) The IPv6 nameservers of the network.
7474
- `ipv6_prefix` (String) The IPv6 prefix of the network (CIDR).
7575
- `ipv6_prefix_length` (Number) The IPv6 prefix length of the network.
7676
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
77-
- `nameservers` (List of String, Deprecated) The nameservers of the network. This field is deprecated and will be removed in January 2026, use `ipv4_nameservers` to configure the nameservers for IPv4.
7877
- `no_ipv4_gateway` (Boolean) If set to `true`, the network doesn't have a gateway.
7978
- `no_ipv6_gateway` (Boolean) If set to `true`, the network doesn't have a gateway.
8079
- `region` (String) The resource region. If not defined, the provider region is used.
@@ -87,5 +86,4 @@ import {
8786
- `ipv4_prefixes` (List of String) The IPv4 prefixes of the network.
8887
- `ipv6_prefixes` (List of String) The IPv6 prefixes of the network.
8988
- `network_id` (String) The network ID.
90-
- `prefixes` (List of String, Deprecated) The prefixes of the network. This field is deprecated and will be removed in January 2026, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.
9189
- `public_ip` (String) The public IP of the network.

stackit/internal/services/iaas/network/datasource.go

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ type DataSourceModel struct {
3131
ProjectId types.String `tfsdk:"project_id"`
3232
NetworkId types.String `tfsdk:"network_id"`
3333
Name types.String `tfsdk:"name"`
34-
Nameservers types.List `tfsdk:"nameservers"`
3534
IPv4Gateway types.String `tfsdk:"ipv4_gateway"`
3635
IPv4Nameservers types.List `tfsdk:"ipv4_nameservers"`
3736
IPv4Prefix types.String `tfsdk:"ipv4_prefix"`
3837
IPv4PrefixLength types.Int64 `tfsdk:"ipv4_prefix_length"`
39-
Prefixes types.List `tfsdk:"prefixes"`
4038
IPv4Prefixes types.List `tfsdk:"ipv4_prefixes"`
4139
IPv6Gateway types.String `tfsdk:"ipv6_gateway"`
4240
IPv6Nameservers types.List `tfsdk:"ipv6_nameservers"`
@@ -115,12 +113,6 @@ func (d *networkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
115113
stringvalidator.LengthAtMost(63),
116114
},
117115
},
118-
"nameservers": schema.ListAttribute{
119-
Description: "The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.",
120-
DeprecationMessage: "Use `ipv4_nameservers` to configure the nameservers for IPv4.",
121-
Computed: true,
122-
ElementType: types.StringType,
123-
},
124116
"ipv4_gateway": schema.StringAttribute{
125117
Description: "The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.",
126118
Computed: true,
@@ -139,12 +131,6 @@ func (d *networkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
139131
Description: "The IPv4 prefix length of the network.",
140132
Computed: true,
141133
},
142-
"prefixes": schema.ListAttribute{
143-
Description: "The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
144-
DeprecationMessage: "Use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
145-
Computed: true,
146-
ElementType: types.StringType,
147-
},
148134
"ipv4_prefixes": schema.ListAttribute{
149135
Description: "The IPv4 prefixes of the network.",
150136
Computed: true,
@@ -215,6 +201,9 @@ func (d *networkDataSource) Read(ctx context.Context, req datasource.ReadRequest
215201
if resp.Diagnostics.HasError() {
216202
return
217203
}
204+
205+
ctx = core.InitProviderContext(ctx)
206+
218207
projectId := model.ProjectId.ValueString()
219208
networkId := model.NetworkId.ValueString()
220209
region := d.providerData.GetRegionWithOverride(model.Region)
@@ -237,6 +226,8 @@ func (d *networkDataSource) Read(ctx context.Context, req datasource.ReadRequest
237226
return
238227
}
239228

229+
ctx = core.LogResponse(ctx)
230+
240231
err = mapDataSourceFields(ctx, networkResp, &model, region)
241232
if err != nil {
242233
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading network", fmt.Sprintf("Processing API payload: %v", err))
@@ -277,37 +268,25 @@ func mapDataSourceFields(ctx context.Context, networkResp *iaas.Network, model *
277268
// IPv4
278269

279270
if networkResp.Ipv4 == nil || networkResp.Ipv4.Nameservers == nil {
280-
model.Nameservers = types.ListNull(types.StringType)
281271
model.IPv4Nameservers = types.ListNull(types.StringType)
282272
} else {
283273
respNameservers := *networkResp.Ipv4.Nameservers
284-
modelNameservers, err := utils.ListValuetoStringSlice(model.Nameservers)
285-
modelIPv4Nameservers, errIpv4 := utils.ListValuetoStringSlice(model.IPv4Nameservers)
274+
modelIPv4Nameservers, err := utils.ListValuetoStringSlice(model.IPv4Nameservers)
286275
if err != nil {
287-
return fmt.Errorf("get current network nameservers from model: %w", err)
288-
}
289-
if errIpv4 != nil {
290-
return fmt.Errorf("get current IPv4 network nameservers from model: %w", errIpv4)
276+
return fmt.Errorf("get current IPv4 network nameservers from model: %w", err)
291277
}
292278

293-
reconciledNameservers := utils.ReconcileStringSlices(modelNameservers, respNameservers)
294279
reconciledIPv4Nameservers := utils.ReconcileStringSlices(modelIPv4Nameservers, respNameservers)
295280

296-
nameserversTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledNameservers)
297-
ipv4NameserversTF, ipv4Diags := types.ListValueFrom(ctx, types.StringType, reconciledIPv4Nameservers)
281+
ipv4NameserversTF, diags := types.ListValueFrom(ctx, types.StringType, reconciledIPv4Nameservers)
298282
if diags.HasError() {
299-
return fmt.Errorf("map network nameservers: %w", core.DiagsToError(diags))
300-
}
301-
if ipv4Diags.HasError() {
302-
return fmt.Errorf("map IPv4 network nameservers: %w", core.DiagsToError(ipv4Diags))
283+
return fmt.Errorf("map IPv4 network nameservers: %w", core.DiagsToError(diags))
303284
}
304285

305-
model.Nameservers = nameserversTF
306286
model.IPv4Nameservers = ipv4NameserversTF
307287
}
308288

309289
if networkResp.Ipv4 == nil || networkResp.Ipv4.Prefixes == nil {
310-
model.Prefixes = types.ListNull(types.StringType)
311290
model.IPv4Prefixes = types.ListNull(types.StringType)
312291
} else {
313292
respPrefixes := *networkResp.Ipv4.Prefixes
@@ -327,7 +306,6 @@ func mapDataSourceFields(ctx context.Context, networkResp *iaas.Network, model *
327306
}
328307
}
329308

330-
model.Prefixes = prefixesTF
331309
model.IPv4Prefixes = prefixesTF
332310
}
333311

stackit/internal/services/iaas/network/datasource_test.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ func TestMapDataSourceFields(t *testing.T) {
4343
ProjectId: types.StringValue("pid"),
4444
NetworkId: types.StringValue("nid"),
4545
Name: types.StringNull(),
46-
Nameservers: types.ListNull(types.StringType),
4746
IPv4Nameservers: types.ListNull(types.StringType),
4847
IPv4PrefixLength: types.Int64Null(),
4948
IPv4Gateway: types.StringNull(),
5049
IPv4Prefix: types.StringNull(),
51-
Prefixes: types.ListNull(types.StringType),
5250
IPv4Prefixes: types.ListNull(types.StringType),
5351
IPv6Nameservers: types.ListNull(types.StringType),
5452
IPv6PrefixLength: types.Int64Null(),
@@ -106,20 +104,12 @@ func TestMapDataSourceFields(t *testing.T) {
106104
ProjectId: types.StringValue("pid"),
107105
NetworkId: types.StringValue("nid"),
108106
Name: types.StringValue("name"),
109-
Nameservers: types.ListValueMust(types.StringType, []attr.Value{
110-
types.StringValue("ns1"),
111-
types.StringValue("ns2"),
112-
}),
113107
IPv4Nameservers: types.ListValueMust(types.StringType, []attr.Value{
114108
types.StringValue("ns1"),
115109
types.StringValue("ns2"),
116110
}),
117111
IPv4PrefixLength: types.Int64Value(24),
118-
Prefixes: types.ListValueMust(types.StringType, []attr.Value{
119-
types.StringValue("192.168.42.0/24"),
120-
types.StringValue("10.100.10.0/16"),
121-
}),
122-
IPv4Prefix: types.StringValue("192.168.42.0/24"),
112+
IPv4Prefix: types.StringValue("192.168.42.0/24"),
123113
IPv4Prefixes: types.ListValueMust(types.StringType, []attr.Value{
124114
types.StringValue("192.168.42.0/24"),
125115
types.StringValue("10.100.10.0/16"),
@@ -151,10 +141,6 @@ func TestMapDataSourceFields(t *testing.T) {
151141
DataSourceModel{
152142
ProjectId: types.StringValue("pid"),
153143
NetworkId: types.StringValue("nid"),
154-
Nameservers: types.ListValueMust(types.StringType, []attr.Value{
155-
types.StringValue("ns1"),
156-
types.StringValue("ns2"),
157-
}),
158144
IPv4Nameservers: types.ListValueMust(types.StringType, []attr.Value{
159145
types.StringValue("ns1"),
160146
types.StringValue("ns2"),
@@ -177,12 +163,7 @@ func TestMapDataSourceFields(t *testing.T) {
177163
Name: types.StringNull(),
178164
IPv6Prefixes: types.ListNull(types.StringType),
179165
IPv6Nameservers: types.ListNull(types.StringType),
180-
Prefixes: types.ListNull(types.StringType),
181166
IPv4Prefixes: types.ListNull(types.StringType),
182-
Nameservers: types.ListValueMust(types.StringType, []attr.Value{
183-
types.StringValue("ns2"),
184-
types.StringValue("ns3"),
185-
}),
186167
IPv4Nameservers: types.ListValueMust(types.StringType, []attr.Value{
187168
types.StringValue("ns2"),
188169
types.StringValue("ns3"),
@@ -219,9 +200,7 @@ func TestMapDataSourceFields(t *testing.T) {
219200
Name: types.StringNull(),
220201
IPv6Prefixes: types.ListNull(types.StringType),
221202
IPv4Nameservers: types.ListNull(types.StringType),
222-
Prefixes: types.ListNull(types.StringType),
223203
IPv4Prefixes: types.ListNull(types.StringType),
224-
Nameservers: types.ListNull(types.StringType),
225204
IPv6Nameservers: types.ListValueMust(types.StringType, []attr.Value{
226205
types.StringValue("ns2"),
227206
types.StringValue("ns3"),
@@ -236,10 +215,6 @@ func TestMapDataSourceFields(t *testing.T) {
236215
DataSourceModel{
237216
ProjectId: types.StringValue("pid"),
238217
NetworkId: types.StringValue("nid"),
239-
Prefixes: types.ListValueMust(types.StringType, []attr.Value{
240-
types.StringValue("192.168.42.0/24"),
241-
types.StringValue("10.100.10.0/16"),
242-
}),
243218
},
244219
&iaas.Network{
245220
Id: utils.Ptr("nid"),
@@ -260,14 +235,9 @@ func TestMapDataSourceFields(t *testing.T) {
260235
IPv6PrefixLength: types.Int64Null(),
261236
IPv6Prefixes: types.ListNull(types.StringType),
262237
Labels: types.MapNull(types.StringType),
263-
Nameservers: types.ListNull(types.StringType),
264238
IPv4Nameservers: types.ListNull(types.StringType),
265239
IPv4PrefixLength: types.Int64Value(16),
266240
IPv4Prefix: types.StringValue("10.100.20.0/16"),
267-
Prefixes: types.ListValueMust(types.StringType, []attr.Value{
268-
types.StringValue("10.100.20.0/16"),
269-
types.StringValue("10.100.10.0/16"),
270-
}),
271241
IPv4Prefixes: types.ListValueMust(types.StringType, []attr.Value{
272242
types.StringValue("10.100.20.0/16"),
273243
types.StringValue("10.100.10.0/16"),
@@ -303,10 +273,8 @@ func TestMapDataSourceFields(t *testing.T) {
303273
Name: types.StringNull(),
304274
IPv4Nameservers: types.ListNull(types.StringType),
305275
IPv4PrefixLength: types.Int64Null(),
306-
Prefixes: types.ListNull(types.StringType),
307276
IPv4Prefixes: types.ListNull(types.StringType),
308277
Labels: types.MapNull(types.StringType),
309-
Nameservers: types.ListNull(types.StringType),
310278
IPv6Nameservers: types.ListNull(types.StringType),
311279
IPv6PrefixLength: types.Int64Value(64),
312280
IPv6Prefix: types.StringValue("fd12:3456:789a:3::/64"),
@@ -333,11 +301,9 @@ func TestMapDataSourceFields(t *testing.T) {
333301
ProjectId: types.StringValue("pid"),
334302
NetworkId: types.StringValue("nid"),
335303
Name: types.StringNull(),
336-
Nameservers: types.ListNull(types.StringType),
337304
IPv4Nameservers: types.ListNull(types.StringType),
338305
IPv4PrefixLength: types.Int64Null(),
339306
IPv4Gateway: types.StringNull(),
340-
Prefixes: types.ListNull(types.StringType),
341307
IPv4Prefixes: types.ListNull(types.StringType),
342308
IPv6Nameservers: types.ListNull(types.StringType),
343309
IPv6PrefixLength: types.Int64Null(),

0 commit comments

Comments
 (0)