Skip to content

Commit

Permalink
Fix cluster network mapping (#375)
Browse files Browse the repository at this point in the history
* Make cluster network computed

* Replace computed with better mapping

* Fix comment

* Update unit test§
  • Loading branch information
vicentepinto98 authored May 27, 2024
1 parent 35b10c6 commit ecaf622
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 11 additions & 0 deletions stackit/internal/services/ske/cluster/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,17 @@ func mapNetwork(cl *ske.Cluster, m *Model) error {
return nil
}

// If the network field is not provided, the SKE API returns an empty object.
// If we parse that object into the terraform model, it will produce an inconsistent result after apply error

emptyNetwork := &ske.V1Network{}
if *cl.Network == *emptyNetwork && m.Network.IsNull() {
if m.Network.Attributes() == nil {
m.Network = types.ObjectNull(networkTypes)
}
return nil
}

id := types.StringNull()
if cl.Network.Id != nil {
id = types.StringValue(*cl.Network.Id)
Expand Down
12 changes: 5 additions & 7 deletions stackit/internal/services/ske/cluster/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestMapFields(t *testing.T) {
true,
},
{
"nil_network_id",
"empty_network",
types.ObjectNull(extensionsTypes),
&ske.Cluster{
Name: utils.Ptr("name"),
Expand All @@ -245,12 +245,10 @@ func TestMapFields(t *testing.T) {
AllowPrivilegedContainers: types.BoolNull(),
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
Maintenance: types.ObjectNull(maintenanceTypes),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringNull(),
}),
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
Extensions: types.ObjectNull(extensionsTypes),
KubeConfig: types.StringNull(),
Network: types.ObjectNull(networkTypes),
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
Extensions: types.ObjectNull(extensionsTypes),
KubeConfig: types.StringNull(),
},
true,
},
Expand Down

0 comments on commit ecaf622

Please sign in to comment.