@@ -31,11 +31,17 @@ const (
31
31
32
32
func ResourceCluster () common.Resource {
33
33
return common.Resource {
34
- Create : resourceClusterCreate ,
35
- Read : resourceClusterRead ,
36
- Update : resourceClusterUpdate ,
37
- Delete : resourceClusterDelete ,
38
- Schema : clusterSchema ,
34
+ Create : resourceClusterCreate ,
35
+ Read : resourceClusterRead ,
36
+ Update : resourceClusterUpdate ,
37
+ Delete : resourceClusterDelete ,
38
+ Schema : clusterSchema ,
39
+ CustomizeDiff : func (ctx context.Context , d * schema.ResourceDiff ) error {
40
+ if isSingleNode , _ := d .GetOk ("is_single_node" ); isSingleNode .(bool ) {
41
+ return singleNodeClusterChangesCustomizeDiff (d )
42
+ }
43
+ return nil
44
+ },
39
45
SchemaVersion : clusterSchemaVersion ,
40
46
Timeouts : resourceClusterTimeouts (),
41
47
StateUpgraders : []schema.StateUpgrader {
@@ -48,6 +54,43 @@ func ResourceCluster() common.Resource {
48
54
}
49
55
}
50
56
57
+ func singleNodeClusterChangesCustomizeDiff (d * schema.ResourceDiff ) error {
58
+ autoConfigAttributes := map [string ][]string {
59
+ "custom_tags" : {"ResourceClass" },
60
+ "spark_conf" : {"spark.databricks.cluster.profile" , "spark.master" },
61
+ }
62
+
63
+ for key , attributes := range autoConfigAttributes {
64
+ if ! d .HasChange (key ) {
65
+ continue
66
+ }
67
+
68
+ o , n := d .GetChange (key )
69
+ old , okOld := o .(map [string ]interface {})
70
+ new , okNew := n .(map [string ]interface {})
71
+
72
+ if ! okNew || ! okOld {
73
+ return fmt .Errorf ("internal type casting error" )
74
+ }
75
+
76
+ log .Printf ("[DEBUG] values for key %s, old: %v, new: %v" , key , old , new )
77
+
78
+ for _ , attribute := range attributes {
79
+ if _ , exists := new [attribute ]; exists && new [attribute ] != nil {
80
+ continue
81
+ }
82
+
83
+ new [attribute ] = old [attribute ]
84
+ }
85
+
86
+ if err := d .SetNew (key , new ); err != nil {
87
+ return err
88
+ }
89
+ }
90
+
91
+ return nil
92
+ }
93
+
51
94
func clusterSchemaV0 () cty.Type {
52
95
return (& schema.Resource {
53
96
Schema : clusterSchema }).CoreConfigSchema ().ImpliedType ()
@@ -346,7 +389,8 @@ func (ClusterSpec) CustomizeSchema(s *common.CustomizableSchema) *common.Customi
346
389
s .SchemaPath ("docker_image" , "url" ).SetRequired ()
347
390
s .SchemaPath ("docker_image" , "basic_auth" , "password" ).SetRequired ().SetSensitive ()
348
391
s .SchemaPath ("docker_image" , "basic_auth" , "username" ).SetRequired ()
349
- s .SchemaPath ("spark_conf" ).SetCustomSuppressDiff (SparkConfDiffSuppressFunc )
392
+ s .SchemaPath ("spark_conf" ).SetCustomSuppressDiff (SparkConfDiffSuppressFunc ).SetComputed ().SetOptional ()
393
+ s .SchemaPath ("custom_tags" ).SetComputed ().SetOptional ()
350
394
s .SchemaPath ("aws_attributes" ).SetSuppressDiff ().SetConflictsWith ([]string {"azure_attributes" , "gcp_attributes" })
351
395
s .SchemaPath ("aws_attributes" , "zone_id" ).SetCustomSuppressDiff (ZoneDiffSuppress )
352
396
s .SchemaPath ("azure_attributes" ).SetSuppressDiff ().SetConflictsWith ([]string {"aws_attributes" , "gcp_attributes" })
0 commit comments