@@ -11,6 +11,7 @@ import (
11
11
"fmt"
12
12
"strings"
13
13
14
+ "github.com/hashicorp/terraform-plugin-framework/attr"
14
15
"github.com/hashicorp/terraform-plugin-framework/datasource"
15
16
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
16
17
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -51,6 +52,7 @@ type hypercoreVMModel struct {
51
52
Tags []types.String `tfsdk:"tags"`
52
53
Disks []HypercoreDiskModel `tfsdk:"disks"`
53
54
// TODO nics
55
+ AffinityStrategy AffinityStrategyModel `tfsdk:"affinity_strategy"`
54
56
}
55
57
56
58
type HypercoreDiskModel struct {
@@ -100,6 +102,15 @@ func (d *hypercoreVMDataSource) Schema(_ context.Context, _ datasource.SchemaReq
100
102
ElementType : types .StringType ,
101
103
Optional : true ,
102
104
},
105
+ "affinity_strategy" : schema.ObjectAttribute {
106
+ MarkdownDescription : "VM node affinity." ,
107
+ Computed : true ,
108
+ AttributeTypes : map [string ]attr.Type {
109
+ "strict_affinity" : types .BoolType ,
110
+ "preferred_node_uuid" : types .StringType ,
111
+ "backup_node_uuid" : types .StringType ,
112
+ },
113
+ },
103
114
104
115
"disks" : schema.ListNestedAttribute {
105
116
MarkdownDescription : "List of disks" ,
@@ -204,18 +215,26 @@ func (d *hypercoreVMDataSource) Read(ctx context.Context, req datasource.ReadReq
204
215
}
205
216
disks = append (disks , disk )
206
217
}
218
+
219
+ hc3affinityStrategy := utils .AnyToMap (vm ["affinityStrategy" ])
220
+ var affinityStrategy AffinityStrategyModel
221
+ affinityStrategy .StrictAffinity = types .BoolValue (utils .AnyToBool (hc3affinityStrategy ["strictAffinity" ]))
222
+ affinityStrategy .PreferredNodeUUID = types .StringValue (utils .AnyToString (hc3affinityStrategy ["preferredNodeUUID" ]))
223
+ affinityStrategy .BackupNodeUUID = types .StringValue (utils .AnyToString (hc3affinityStrategy ["backupNodeUUID" ]))
224
+
207
225
// VM
208
226
memory_B := utils .AnyToInteger64 (vm ["mem" ])
209
227
memory_MiB := memory_B / 1024 / 1024
210
228
hypercoreVMState := hypercoreVMModel {
211
- UUID : types .StringValue (utils .AnyToString (vm ["uuid" ])),
212
- Name : types .StringValue (utils .AnyToString (vm ["name" ])),
213
- VCPU : types .Int32Value (int32 (utils .AnyToInteger64 (vm ["numVCPU" ]))),
214
- Memory : types .Int64Value (memory_MiB ),
215
- Description : types .StringValue (utils .AnyToString (vm ["description" ])),
216
- PowerState : types .StringValue (utils .AnyToString (vm ["state" ])), // TODO convert (stopped vs SHUTOFF)
217
- Tags : tags_String ,
218
- Disks : disks ,
229
+ UUID : types .StringValue (utils .AnyToString (vm ["uuid" ])),
230
+ Name : types .StringValue (utils .AnyToString (vm ["name" ])),
231
+ VCPU : types .Int32Value (int32 (utils .AnyToInteger64 (vm ["numVCPU" ]))),
232
+ Memory : types .Int64Value (memory_MiB ),
233
+ Description : types .StringValue (utils .AnyToString (vm ["description" ])),
234
+ PowerState : types .StringValue (utils .AnyToString (vm ["state" ])), // TODO convert (stopped vs SHUTOFF)
235
+ Tags : tags_String ,
236
+ AffinityStrategy : affinityStrategy ,
237
+ Disks : disks ,
219
238
}
220
239
state .Vms = append (state .Vms , hypercoreVMState )
221
240
}
0 commit comments