@@ -75,6 +75,7 @@ type Model struct {
7575
7676// Struct corresponding to Model.BootVolume
7777type bootVolumeModel struct {
78+ Id types.String `tfsdk:"id"`
7879 PerformanceClass types.String `tfsdk:"performance_class"`
7980 Size types.Int64 `tfsdk:"size"`
8081 SourceType types.String `tfsdk:"source_type"`
@@ -89,6 +90,7 @@ var bootVolumeTypes = map[string]attr.Type{
8990 "source_type" : basetypes.StringType {},
9091 "source_id" : basetypes.StringType {},
9192 "delete_on_termination" : basetypes.BoolType {},
93+ "id" : basetypes.StringType {},
9294}
9395
9496// NewServerResource is a helper function to simplify the provider implementation.
@@ -253,6 +255,13 @@ func (r *serverResource) Schema(_ context.Context, _ resource.SchemaRequest, res
253255 objectplanmodifier .RequiresReplace (),
254256 },
255257 Attributes : map [string ]schema.Attribute {
258+ "id" : schema.StringAttribute {
259+ Description : "The ID of the boot volume" ,
260+ Computed : true ,
261+ PlanModifiers : []planmodifier.String {
262+ stringplanmodifier .UseStateForUnknown (),
263+ },
264+ },
256265 "performance_class" : schema.StringAttribute {
257266 Description : "The performance class of the server." ,
258267 Optional : true ,
@@ -911,6 +920,34 @@ func mapFields(ctx context.Context, serverResp *iaas.Server, model *Model) error
911920 model .NetworkInterfaces = types .ListNull (types .StringType )
912921 }
913922
923+ if serverResp .BootVolume != nil {
924+ // convert boot volume model
925+ var bootVolumeModel = & bootVolumeModel {}
926+ if ! (model .BootVolume .IsNull () || model .BootVolume .IsUnknown ()) {
927+ diags := model .BootVolume .As (ctx , bootVolumeModel , basetypes.ObjectAsOptions {})
928+ if diags .HasError () {
929+ return fmt .Errorf ("failed to map bootVolume: %w" , core .DiagsToError (diags ))
930+ }
931+ }
932+
933+ // Only the id and delete_on_termination is returned via response.
934+ // Take the other values from the model.
935+ bootVolume , diags := types .ObjectValue (bootVolumeTypes , map [string ]attr.Value {
936+ "id" : types .StringPointerValue (serverResp .BootVolume .Id ),
937+ "delete_on_termination" : types .BoolPointerValue (serverResp .BootVolume .DeleteOnTermination ),
938+ "source_id" : bootVolumeModel .SourceId ,
939+ "size" : bootVolumeModel .Size ,
940+ "source_type" : bootVolumeModel .SourceType ,
941+ "performance_class" : bootVolumeModel .PerformanceClass ,
942+ })
943+ if diags .HasError () {
944+ return fmt .Errorf ("failed to map bootVolume: %w" , core .DiagsToError (diags ))
945+ }
946+ model .BootVolume = bootVolume
947+ } else {
948+ model .BootVolume = types .ObjectNull (bootVolumeTypes )
949+ }
950+
914951 model .ServerId = types .StringValue (serverId )
915952 model .MachineType = types .StringPointerValue (serverResp .MachineType )
916953
0 commit comments