Fix cluster network mapping (#375)

* Make cluster network computed

* Replace computed with better mapping

* Fix comment

* Update unit test§
This commit is contained in:
Vicente Pinto 2024-05-27 09:18:10 +01:00 committed by GitHub
parent 35b10c602b
commit ecaf622f55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -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)

View file

@ -231,7 +231,7 @@ func TestMapFields(t *testing.T) {
true,
},
{
"nil_network_id",
"empty_network",
types.ObjectNull(extensionsTypes),
&ske.Cluster{
Name: utils.Ptr("name"),
@ -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,
},