44 "context"
55 "fmt"
66 "log"
7+ "slices"
78 "strings"
89 "time"
910
@@ -23,8 +24,8 @@ var clusterSchema = resourceClusterSchema()
2324var clusterSchemaVersion = 4
2425
2526const (
26- numWorkerErr = "NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details"
27- unsupportedExceptCreateOrEditErr = "unsupported type %T, must be one of %scompute.CreateCluster, %scompute.ClusterSpec or %scompute.EditCluster. Please report this issue to the GitHub repo"
27+ numWorkerErr = "NumWorkers could be 0 only for SingleNode clusters. See https://docs.databricks.com/clusters/single-node.html for more details"
28+ unsupportedExceptCreateEditClusterSpecErr = "unsupported type %T, must be one of %scompute.CreateCluster, %scompute.ClusterSpec or %scompute.EditCluster. Please report this issue to the GitHub repo"
2829)
2930
3031func ResourceCluster () common.Resource {
@@ -135,7 +136,7 @@ func Validate(cluster any) error {
135136 master = c .SparkConf ["spark.master" ]
136137 resourceClass = c .CustomTags ["ResourceClass" ]
137138 default :
138- return fmt .Errorf (unsupportedExceptCreateOrEditErr , cluster , "" , "" , "" )
139+ return fmt .Errorf (unsupportedExceptCreateEditClusterSpecErr , cluster , "" , "" , "" )
139140 }
140141 if profile == "singleNode" && strings .HasPrefix (master , "local" ) && resourceClass == "SingleNode" {
141142 return nil
@@ -232,7 +233,7 @@ func ModifyRequestOnInstancePool(cluster any) error {
232233 c .DriverNodeTypeId = ""
233234 return nil
234235 default :
235- return fmt .Errorf (unsupportedExceptCreateOrEditErr , cluster , "*" , "*" , "*" )
236+ return fmt .Errorf (unsupportedExceptCreateEditClusterSpecErr , cluster , "*" , "*" , "*" )
236237 }
237238}
238239
@@ -260,7 +261,7 @@ func FixInstancePoolChangeIfAny(d *schema.ResourceData, cluster any) error {
260261 }
261262 return nil
262263 default :
263- return fmt .Errorf (unsupportedExceptCreateOrEditErr , cluster , "*" , "*" , "*" )
264+ return fmt .Errorf (unsupportedExceptCreateEditClusterSpecErr , cluster , "*" , "*" , "*" )
264265 }
265266}
266267
@@ -439,6 +440,105 @@ func setPinnedStatus(ctx context.Context, d *schema.ResourceData, clusterAPI com
439440 return d .Set ("is_pinned" , pinnedEvent == compute .EventTypePinned )
440441}
441442
443+ func RemoveUnnecessaryFieldsFromForceSendFields (cluster any ) error {
444+ switch clusterSpec := cluster .(type ) {
445+ case * compute.ClusterSpec :
446+ if clusterSpec .AwsAttributes != nil {
447+ newAwsAttributesForceSendFields := []string {}
448+ // These fields should never be 0.
449+ unnecessaryFieldNamesForAwsAttributes := []string {
450+ "SpotBidPricePercent" ,
451+ "EbsVolumeCount" ,
452+ "EbsVolumeIops" ,
453+ "EbsVolumeSize" ,
454+ "EbsVolumeThroughput" ,
455+ }
456+ for _ , field := range clusterSpec .AwsAttributes .ForceSendFields {
457+ if ! slices .Contains (unnecessaryFieldNamesForAwsAttributes , field ) {
458+ newAwsAttributesForceSendFields = append (newAwsAttributesForceSendFields , field )
459+ }
460+ }
461+ clusterSpec .AwsAttributes .ForceSendFields = newAwsAttributesForceSendFields
462+ }
463+ if clusterSpec .GcpAttributes != nil {
464+ newGcpAttributesForceSendFields := []string {}
465+ // Should never be 0.
466+ unnecessaryFieldNamesForGcpAttributes := []string {
467+ "BootDiskSize" ,
468+ }
469+ for _ , field := range clusterSpec .GcpAttributes .ForceSendFields {
470+ if ! slices .Contains (unnecessaryFieldNamesForGcpAttributes , field ) {
471+ newGcpAttributesForceSendFields = append (newGcpAttributesForceSendFields , field )
472+ }
473+ }
474+ clusterSpec .GcpAttributes .ForceSendFields = newGcpAttributesForceSendFields
475+ }
476+ if clusterSpec .AzureAttributes != nil {
477+ newAzureAttributesForceSendFields := []string {}
478+ // Should never be 0.
479+ unnecessaryFieldNamesForAzureAttributes := []string {
480+ "FirstOnDemand" ,
481+ "SpotBidMaxPrice" ,
482+ }
483+ for _ , field := range clusterSpec .AzureAttributes .ForceSendFields {
484+ if ! slices .Contains (unnecessaryFieldNamesForAzureAttributes , field ) {
485+ newAzureAttributesForceSendFields = append (newAzureAttributesForceSendFields , field )
486+ }
487+ }
488+ clusterSpec .AzureAttributes .ForceSendFields = newAzureAttributesForceSendFields
489+ }
490+ return nil
491+ case * compute.EditCluster :
492+ if clusterSpec .AwsAttributes != nil {
493+ newAwsAttributesForceSendFields := []string {}
494+ // These fields should never be 0.
495+ unnecessaryFieldNamesForAwsAttributes := []string {
496+ "SpotBidPricePercent" ,
497+ "EbsVolumeCount" ,
498+ "EbsVolumeIops" ,
499+ "EbsVolumeSize" ,
500+ "EbsVolumeThroughput" ,
501+ }
502+ for _ , field := range clusterSpec .AwsAttributes .ForceSendFields {
503+ if ! slices .Contains (unnecessaryFieldNamesForAwsAttributes , field ) {
504+ newAwsAttributesForceSendFields = append (newAwsAttributesForceSendFields , field )
505+ }
506+ }
507+ clusterSpec .AwsAttributes .ForceSendFields = newAwsAttributesForceSendFields
508+ }
509+ if clusterSpec .GcpAttributes != nil {
510+ newGcpAttributesForceSendFields := []string {}
511+ // Should never be 0.
512+ unnecessaryFieldNamesForGcpAttributes := []string {
513+ "BootDiskSize" ,
514+ }
515+ for _ , field := range clusterSpec .GcpAttributes .ForceSendFields {
516+ if ! slices .Contains (unnecessaryFieldNamesForGcpAttributes , field ) {
517+ newGcpAttributesForceSendFields = append (newGcpAttributesForceSendFields , field )
518+ }
519+ }
520+ clusterSpec .GcpAttributes .ForceSendFields = newGcpAttributesForceSendFields
521+ }
522+ if clusterSpec .AzureAttributes != nil {
523+ newAzureAttributesForceSendFields := []string {}
524+ // Should never be 0.
525+ unnecessaryFieldNamesForAzureAttributes := []string {
526+ "FirstOnDemand" ,
527+ "SpotBidMaxPrice" ,
528+ }
529+ for _ , field := range clusterSpec .AzureAttributes .ForceSendFields {
530+ if ! slices .Contains (unnecessaryFieldNamesForAzureAttributes , field ) {
531+ newAzureAttributesForceSendFields = append (newAzureAttributesForceSendFields , field )
532+ }
533+ }
534+ clusterSpec .AzureAttributes .ForceSendFields = newAzureAttributesForceSendFields
535+ }
536+ return nil
537+ default :
538+ return fmt .Errorf (unsupportedExceptCreateEditClusterSpecErr , cluster , "*" , "*" , "*" )
539+ }
540+ }
541+
442542func resourceClusterRead (ctx context.Context , d * schema.ResourceData , c * common.DatabricksClient ) error {
443543 w , err := c .WorkspaceClient ()
444544 if err != nil {
@@ -572,6 +672,10 @@ func resourceClusterUpdate(ctx context.Context, d *schema.ResourceData, c *commo
572672 Autoscale : cluster .Autoscale ,
573673 })
574674 } else {
675+ err = RemoveUnnecessaryFieldsFromForceSendFields (& cluster )
676+ if err != nil {
677+ return err
678+ }
575679 _ , err = clusters .Edit (ctx , cluster )
576680 }
577681 if err != nil {
0 commit comments