@@ -57,25 +57,19 @@ func resourceKubernetesJobV1CustomizeDiff(ctx context.Context, d *schema.Resourc
5757 return nil
5858 }
5959
60- // Retrieve old and new TTL values as strings
60+ // Retrieve old and new TTL schema values as
6161 oldTTLRaw , newTTLRaw := d .GetChange ("spec.0.ttl_seconds_after_finished" )
62-
63- var oldTTLStr , newTTLStr string
64-
65- if oldTTLRaw != nil {
66- oldTTLStr , _ = oldTTLRaw .(string )
67- }
68- if newTTLRaw != nil {
69- newTTLStr , _ = newTTLRaw .(string )
70- }
62+ oldTTLStr , _ := oldTTLRaw .(string )
63+ newTTLStr , _ := newTTLRaw .(string )
7164
7265 oldTTLInt , err := strconv .Atoi (oldTTLStr )
7366 if err != nil {
74- oldTTLInt = 0
67+ return fmt . Errorf ( "invalid old TTL value: %v" , err )
7568 }
69+
7670 newTTLInt , err := strconv .Atoi (newTTLStr )
7771 if err != nil {
78- newTTLInt = 0
72+ return fmt . Errorf ( "invalid new TTL value: %v" , err )
7973 }
8074
8175 conn , err := meta .(KubeClientsets ).MainClientset ()
@@ -92,32 +86,15 @@ func resourceKubernetesJobV1CustomizeDiff(ctx context.Context, d *schema.Resourc
9286 _ , err = conn .BatchV1 ().Jobs (namespace ).Get (ctx , name , metav1.GetOptions {})
9387 if err != nil {
9488 if apierrors .IsNotFound (err ) {
95- // Job is missing
96- if oldTTLInt >= 0 {
97- if oldTTLInt != newTTLInt {
98- // TTL value changed; force recreation
99- log .Printf ("[DEBUG] Job %s not found and ttl_seconds_after_finished changed from %d to %d; forcing recreation" , d .Id (), oldTTLInt , newTTLInt )
100- d .ForceNew ("spec.0.ttl_seconds_after_finished" )
101- return nil
102- } else {
103- // TTL remains the same; suppress diff
104- log .Printf ("[DEBUG] Job %s not found and ttl_seconds_after_finished remains %d; suppressing diff" , d .Id (), oldTTLInt )
105- d .Clear ("spec" )
106- d .Clear ("metadata" )
107- return nil
108- }
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" )
10994 }
11095 } else {
11196 return err
11297 }
113- } else {
114- // Job exists, check if TTL changed
115- if oldTTLInt != newTTLInt {
116- // TTL changed; force recreation
117- log .Printf ("[DEBUG] Job %s exists and ttl_seconds_after_finished changed from %d to %d; forcing recreation" , d .Id (), oldTTLInt , newTTLInt )
118- d .ForceNew ("spec.0.ttl_seconds_after_finished" )
119- return nil
120- }
12198 }
12299
123100 return nil
0 commit comments