Skip to content

Commit ecaf622

Browse files
Fix cluster network mapping (#375)
* Make cluster network computed * Replace computed with better mapping * Fix comment * Update unit test§
1 parent 35b10c6 commit ecaf622

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

stackit/internal/services/ske/cluster/resource.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,17 @@ func mapNetwork(cl *ske.Cluster, m *Model) error {
14861486
return nil
14871487
}
14881488

1489+
// If the network field is not provided, the SKE API returns an empty object.
1490+
// If we parse that object into the terraform model, it will produce an inconsistent result after apply error
1491+
1492+
emptyNetwork := &ske.V1Network{}
1493+
if *cl.Network == *emptyNetwork && m.Network.IsNull() {
1494+
if m.Network.Attributes() == nil {
1495+
m.Network = types.ObjectNull(networkTypes)
1496+
}
1497+
return nil
1498+
}
1499+
14891500
id := types.StringNull()
14901501
if cl.Network.Id != nil {
14911502
id = types.StringValue(*cl.Network.Id)

stackit/internal/services/ske/cluster/resource_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func TestMapFields(t *testing.T) {
231231
true,
232232
},
233233
{
234-
"nil_network_id",
234+
"empty_network",
235235
types.ObjectNull(extensionsTypes),
236236
&ske.Cluster{
237237
Name: utils.Ptr("name"),
@@ -245,12 +245,10 @@ func TestMapFields(t *testing.T) {
245245
AllowPrivilegedContainers: types.BoolNull(),
246246
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
247247
Maintenance: types.ObjectNull(maintenanceTypes),
248-
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
249-
"id": types.StringNull(),
250-
}),
251-
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
252-
Extensions: types.ObjectNull(extensionsTypes),
253-
KubeConfig: types.StringNull(),
248+
Network: types.ObjectNull(networkTypes),
249+
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
250+
Extensions: types.ObjectNull(extensionsTypes),
251+
KubeConfig: types.StringNull(),
254252
},
255253
true,
256254
},

0 commit comments

Comments
 (0)