@@ -57,44 +57,40 @@ func resourceKubernetesJobV1CustomizeDiff(ctx context.Context, d *schema.Resourc
5757 return nil
5858 }
5959
60- // Retrieve old and new TTL schema values as
60+ // Retrieve old and new TTL values
6161 oldTTLRaw , newTTLRaw := d .GetChange ("spec.0.ttl_seconds_after_finished" )
62- oldTTLStr , _ := oldTTLRaw .(string )
63- newTTLStr , _ := newTTLRaw .(string )
6462
65- oldTTLInt , err := strconv .Atoi (oldTTLStr )
66- if err != nil {
67- return fmt .Errorf ("invalid old TTL value: %v" , err )
63+ // If both TTL values are not set or are empty, skip TTL diff
64+ if (oldTTLRaw == nil && newTTLRaw == nil ) || (oldTTLRaw == "" && newTTLRaw == "" ) {
65+ log .Printf ("[DEBUG] No ttl_seconds_after_finished provided or both values are empty; skipping TTL diff" )
66+ return nil
6867 }
6968
70- newTTLInt , err := strconv .Atoi (newTTLStr )
71- if err != nil {
72- return fmt .Errorf ("invalid new TTL value: %v" , err )
69+ // Only check TTL if present
70+ var oldTTLStr , newTTLStr string
71+ if oldTTLRaw != nil {
72+ oldTTLStr , _ = oldTTLRaw .(string )
73+ }
74+ if newTTLRaw != nil {
75+ newTTLStr , _ = newTTLRaw .(string )
7376 }
7477
75- conn , err := meta .( KubeClientsets ). MainClientset ( )
78+ oldTTLInt , err := strconv . Atoi ( oldTTLStr )
7679 if err != nil {
77- return err
80+ log .Printf ("[DEBUG] Invalid old TTL value: %s, skipping diff" , oldTTLStr )
81+ return nil
7882 }
79-
80- namespace , name , err := idParts (d .Id ())
83+ newTTLInt , err := strconv .Atoi (newTTLStr )
8184 if err != nil {
82- return err
85+ log .Printf ("[DEBUG] Invalid new TTL value: %s, skipping diff" , newTTLStr )
86+ return nil
8387 }
8488
85- // Check if the Job exists
86- _ , err = conn .BatchV1 ().Jobs (namespace ).Get (ctx , name , metav1.GetOptions {})
87- if err != nil {
88- if apierrors .IsNotFound (err ) {
89- // Job is missing, suppress diff if the TTL is the same
90- if oldTTLInt == newTTLInt {
91- log .Printf ("[DEBUG] Job %s not found and ttl_seconds_after_finished remains unchanged; suppressing diff" , d .Id ())
92- d .Clear ("spec" )
93- d .Clear ("metadata" )
94- }
95- } else {
96- return err
97- }
89+ // Suppress the diff if the old and new TTL values are the same
90+ if oldTTLInt == newTTLInt {
91+ log .Printf ("[DEBUG] ttl_seconds_after_finished has not changed; suppressing diff" )
92+ d .Clear ("spec" )
93+ d .Clear ("metadata" )
9894 }
9995
10096 return nil
0 commit comments