@@ -86,6 +86,7 @@ const (
8686 FieldNodeTemplateSharingConfiguration = "sharing_configuration"
8787 FieldNodeTemplateSharedClientsPerGpu = "shared_clients_per_gpu"
8888 FieldNodeTemplateSharedGpuName = "gpu_name"
89+ FieldNodeTemplateSharingStrategy = "sharing_strategy"
8990 FieldNodeTemplateClmEnabled = "clm_enabled"
9091 FieldNodeTemplateEdgeLocationIDs = "edge_location_ids"
9192 FieldNodeTemplatePriceAdjustmentConfiguration = "price_adjustment_configuration"
@@ -679,11 +680,44 @@ func resourceNodeTemplate() *schema.Resource {
679680 DiffSuppressFunc : compareLists ,
680681 Elem : & schema.Resource {
681682 Schema : map [string ]* schema.Schema {
683+ FieldNodeTemplateSharingStrategy : {
684+ Type : schema .TypeString ,
685+ Optional : true ,
686+ ValidateDiagFunc : validation .ToDiagFunc (validation .StringInSlice ([]string {"time-slicing" , "mps" }, false )),
687+ Description : "GPU sharing strategy. Supported values: `time-slicing`, `mps`." ,
688+ DiffSuppressFunc : func (k , oldVal , newVal string , d * schema.ResourceData ) bool {
689+ // Suppress diff when sharing_strategy is not configured but enable_time_sharing=true
690+ // implies time-slicing, so the API returning "time-slicing" is not a real change.
691+ //
692+ // The DiffSuppressFunc receives k — the full key path of the field that's diffing, which looks like:
693+ // gpu.0.sharing_strategy
694+ // We need to check the sibling field enable_time_sharing at the same path:
695+ // gpu.0.enable_time_sharing
696+ // So the code:
697+ // prefix := k[:len(k)-len(FieldNodeTemplateSharingStrategy)]
698+ // // k = "gpu.0.sharing_strategy"
699+ // // len("sharing_strategy") chars stripped from end
700+ // // prefix = "gpu.0."
701+ //
702+ //Then:
703+ // d.GetOk(prefix + FieldNodeTemplateEnableTimeSharing)
704+ // // = d.GetOk("gpu.0." + "enable_time_sharing")
705+ // // = d.GetOk("gpu.0.enable_time_sharing")
706+ if newVal == "" && oldVal == "time-slicing" {
707+ prefix := k [:len (k )- len (FieldNodeTemplateSharingStrategy )]
708+ if v , ok := d .GetOk (prefix + FieldNodeTemplateEnableTimeSharing ); ok && v .(bool ) {
709+ return true
710+ }
711+ }
712+ return false
713+ },
714+ },
682715 FieldNodeTemplateEnableTimeSharing : {
683716 Type : schema .TypeBool ,
684717 Optional : true ,
685718 Default : nil ,
686- Description : "Enable/disable GPU time-sharing." ,
719+ Deprecated : "Use sharing_strategy instead." ,
720+ Description : "Enable/disable GPU time-sharing. Deprecated: use sharing_strategy = \" time-slicing\" instead." ,
687721 },
688722 FieldNodeTemplateDefaultSharedClientsPerGpu : {
689723 Type : schema .TypeInt ,
@@ -882,6 +916,10 @@ func flattenGpuSettings(g *sdk.NodetemplatesV1GPU) ([]map[string]any, error) {
882916 out [FieldNodeTemplateUserManagedGPUDrivers ] = g .UserManagedGpuDrivers
883917 }
884918
919+ if g .SharingStrategy != nil {
920+ out [FieldNodeTemplateSharingStrategy ] = gpuSharingStrategyToTerraform (* g .SharingStrategy )
921+ }
922+
885923 if g .EnableTimeSharing != nil {
886924 out [FieldNodeTemplateEnableTimeSharing ] = g .EnableTimeSharing
887925 }
@@ -1175,6 +1213,7 @@ func updateNodeTemplate(ctx context.Context, d *schema.ResourceData, meta any, s
11751213 FieldNodeTemplateGpu ,
11761214 FieldNodeTemplateDefaultSharedClientsPerGpu ,
11771215 FieldNodeTemplateEnableTimeSharing ,
1216+ FieldNodeTemplateSharingStrategy ,
11781217 FieldNodeTemplateSharingConfiguration ,
11791218 FieldNodeTemplateSharedGpuName ,
11801219 FieldNodeTemplateSharedClientsPerGpu ,
@@ -1702,6 +1741,12 @@ func toTemplateGpu(obj map[string]any) *sdk.NodetemplatesV1GPU {
17021741 defaultSharedClientsPerGpu = int32 (v )
17031742 }
17041743
1744+ var sharingStrategy * sdk.NodetemplatesV1GPUSharingStrategy
1745+ if v , ok := obj [FieldNodeTemplateSharingStrategy ].(string ); ok && v != "" {
1746+ s := gpuSharingStrategyToAPI (v )
1747+ sharingStrategy = & s
1748+ }
1749+
17051750 var enableTimeSharing bool
17061751 if v , ok := obj [FieldNodeTemplateEnableTimeSharing ].(bool ); ok {
17071752 enableTimeSharing = v
@@ -1728,13 +1773,14 @@ func toTemplateGpu(obj map[string]any) *sdk.NodetemplatesV1GPU {
17281773 // terraform treats nil values as zero values
17291774 // this condition checks whether the whole gpu configuration is deleted
17301775 // and gpu configuration should be set to nil
1731- if defaultSharedClientsPerGpu == 0 && ! enableTimeSharing && len (sharingConfig ) == 0 && ! userManagedGPUDrivers {
1776+ if defaultSharedClientsPerGpu == 0 && ! enableTimeSharing && sharingStrategy == nil && len (sharingConfig ) == 0 && ! userManagedGPUDrivers {
17321777 return nil
17331778 }
17341779
17351780 result := & sdk.NodetemplatesV1GPU {
17361781 EnableTimeSharing : & enableTimeSharing ,
17371782 SharingConfiguration : & sharingConfig ,
1783+ SharingStrategy : sharingStrategy ,
17381784 }
17391785
17401786 // Only set DefaultSharedClientsPerGpu if it's non-zero to avoid API validation errors
@@ -1925,3 +1971,27 @@ func compareLists(key, oldValue, newValue string, d *schema.ResourceData) bool {
19251971 }
19261972 return false
19271973}
1974+
1975+ // gpuSharingStrategyToAPI converts a terraform-friendly strategy string to the API enum value.
1976+ func gpuSharingStrategyToAPI (s string ) sdk.NodetemplatesV1GPUSharingStrategy {
1977+ switch s {
1978+ case "mps" :
1979+ return sdk .GPUSHARINGSTRATEGYMPS
1980+ case "time-slicing" :
1981+ return sdk .GPUSHARINGSTRATEGYTIMESLICING
1982+ default :
1983+ return sdk .GPUSHARINGSTRATEGYUNSPECIFIED
1984+ }
1985+ }
1986+
1987+ // gpuSharingStrategyToTerraform converts the API enum value to a terraform-friendly string.
1988+ func gpuSharingStrategyToTerraform (s sdk.NodetemplatesV1GPUSharingStrategy ) string {
1989+ switch s {
1990+ case sdk .GPUSHARINGSTRATEGYMPS :
1991+ return "mps"
1992+ case sdk .GPUSHARINGSTRATEGYTIMESLICING :
1993+ return "time-slicing"
1994+ default :
1995+ return ""
1996+ }
1997+ }
0 commit comments