Skip to content

Commit 3bf1e8c

Browse files
committed
fix(ha): handle nil Strict value in HARule and update API response validation
Signed-off-by: Pavel Boldyrev <pavel@bpg.sh>
1 parent 31ab05a commit 3bf1e8c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

fwprovider/cluster/ha/model_harule.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ func (m *RuleModel) ImportFromAPI(rule harules.HARuleGetResponseData) diag.Diagn
5959
m.Nodes = types.MapNull(types.Int64Type)
6060
}
6161

62-
m.Strict = rule.Strict.ToValue()
62+
if rule.Strict != nil {
63+
m.Strict = rule.Strict.ToValue()
64+
} else {
65+
m.Strict = types.BoolValue(false)
66+
}
67+
6368
m.Affinity = types.StringNull()
6469

6570
case RuleTypeResourceAffinity:

fwprovider/cluster/ha/resource_harule.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/bpg/terraform-provider-proxmox/fwprovider/config"
3333
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
3434
harules "github.com/bpg/terraform-provider-proxmox/proxmox/cluster/ha/rules"
35+
proxmoxtypes "github.com/bpg/terraform-provider-proxmox/proxmox/types"
3536
)
3637

3738
var (
@@ -272,7 +273,7 @@ func (r *haruleResource) Create(ctx context.Context, req resource.CreateRequest,
272273
case RuleTypeNodeAffinity:
273274
nodesStr := r.nodesToString(data.Nodes)
274275
createRequest.Nodes = &nodesStr
275-
createRequest.Strict.FromValue(data.Strict)
276+
createRequest.Strict = proxmoxtypes.CustomBoolPtr(data.Strict.ValueBoolPointer())
276277
case RuleTypeResourceAffinity:
277278
createRequest.Affinity = data.Affinity.ValueStringPointer()
278279
}
@@ -341,7 +342,7 @@ func (r *haruleResource) Update(ctx context.Context, req resource.UpdateRequest,
341342
case RuleTypeNodeAffinity:
342343
nodesStr := r.nodesToString(data.Nodes)
343344
updateRequest.Nodes = &nodesStr
344-
updateRequest.Strict.FromValue(data.Strict)
345+
updateRequest.Strict = proxmoxtypes.CustomBoolPtr(data.Strict.ValueBoolPointer())
345346
case RuleTypeResourceAffinity:
346347
updateRequest.Affinity = data.Affinity.ValueStringPointer()
347348
}

proxmox/api/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ func validateResponseCode(res *http.Response) error {
367367
(res.StatusCode == http.StatusInternalServerError &&
368368
(strings.Contains(res.Status, "does not exist") ||
369369
strings.Contains(msg, "does not exist") ||
370-
strings.Contains(msg, "no such "))) {
370+
strings.Contains(msg, "no such resource") ||
371+
strings.Contains(msg, "no such ha"))) {
371372
return errors.Join(ErrResourceDoesNotExist, httpError)
372373
}
373374

proxmox/cluster/ha/rules/harules_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type HARuleNodeAffinityData struct {
4545
// A comma-separated list of node names with optional priorities (e.g. node1:2,node2:1).
4646
Nodes *string `json:"nodes,omitempty" url:"nodes,omitempty"`
4747
// Whether the node affinity rule is strict (resources cannot run on other nodes).
48-
Strict types.CustomBool `json:"strict,omitempty" url:"strict,int"`
48+
Strict *types.CustomBool `json:"strict,omitempty" url:"strict,omitempty,int"`
4949
}
5050

5151
// HARuleResourceAffinityData contains fields specific to resource-affinity rules.

0 commit comments

Comments
 (0)