@@ -361,13 +361,9 @@ def is_resource_identical(self):
361
361
if not self .module_result ["diff_list" ]:
362
362
del self .module_result ["diff_list" ]
363
363
if immutable_resource_module_params != []:
364
- msg = (
365
- "Cannot change value for the following non-updateable attributes %s"
366
- % immutable_resource_module_params
367
- )
368
- self .return_failure (msg )
364
+ return (False , immutable_resource_module_params )
369
365
370
- return False if diff_list else True
366
+ return ( False , None ) if diff_list else ( True , None )
371
367
372
368
@trace
373
369
def create_or_update (self ):
@@ -430,8 +426,13 @@ def create_or_update(self):
430
426
self .resource_module_params ["sitename" ] = sitename
431
427
432
428
else :
433
- # Update only if resource is not identical (idempotent)
434
- if self .is_resource_identical ():
429
+ # Update process will go through 2 iterations of is_resource_identical
430
+ # 1. First iteration will check if the resource is identical. If not, it will give the list of non-updatable attributes that exists
431
+ # in the user playbook. If non-updatable attributes are present, it will remove them from the module_params and update the resource
432
+ # 2. Second iteration will check if the resource is identical. If not, it will update the resource after ignoring the
433
+ # non-updatable resources
434
+ is_identical , immutable_keys_list = self .is_resource_identical ()
435
+ if is_identical :
435
436
log (
436
437
"INFO: Resource `%s:%s` exists and is identical. No change required."
437
438
% (
@@ -451,19 +452,46 @@ def create_or_update(self):
451
452
ok , err = create_resource (
452
453
self .client , self .resource_name , self .resource_module_params
453
454
)
454
- else :
455
+
456
+ elif immutable_keys_list is None :
457
+ self .module_result ["changed" ] = True
455
458
log (
456
- "INFO: Resource %s:%s exists. Will be UPDATED."
457
- % (
458
- self .resource_name ,
459
- self .resource_id ,
460
- )
459
+ "INFO: Resource %s:%s exists and is different. Will be UPDATED."
460
+ % (self .resource_name , self .resource_id )
461
461
)
462
462
ok , err = update_resource (
463
463
self .client , self .resource_name , self .resource_module_params
464
464
)
465
- if not ok :
466
- self .return_failure (err )
465
+ if not ok :
466
+ self .return_failure (err )
467
+ else :
468
+ for key in immutable_keys_list :
469
+ self .resource_module_params .pop (key )
470
+
471
+ is_identical , temp_immutable_list = self .is_resource_identical ()
472
+ # temp_immutable_list is a dummy as '_' is not allowed in lint.
473
+ if is_identical :
474
+ msg = (
475
+ f"Resource { self .resource_name } /{ self .resource_id } not updated because user is trying to "
476
+ f"update following non-updatable keys: { immutable_keys_list } "
477
+ )
478
+ self .module .warn (msg )
479
+ log (msg )
480
+ self .module_result ["changed" ] = False
481
+ self .module .exit_json (** self .module_result )
482
+ else :
483
+ self .module_result ["changed" ] = True
484
+ msg = (
485
+ f"Resource { self .resource_name } /{ self .resource_id } is updated after ignoring following "
486
+ f"non-updatable keys: { immutable_keys_list } "
487
+ )
488
+ self .module .warn (msg )
489
+ log (msg )
490
+ ok , err = update_resource (
491
+ self .client , self .resource_name , self .resource_module_params
492
+ )
493
+ if not ok :
494
+ self .return_failure (err )
467
495
468
496
@trace
469
497
def enable_or_disable (self , desired_state ):
0 commit comments