@@ -77,8 +77,15 @@ def __init__(self, resource_name, supports_check_mode=True):
7777 default = "present" ,
7878 ),
7979 )
80+ module_remove_non_updatable_params = dict (
81+ remove_non_updatable_params = dict (
82+ type = "str" ,
83+ choices = ["yes" , "no" ],
84+ default = "no" ,
85+ ),
86+ )
8087 argument_spec .update (module_state_argument )
81-
88+ argument_spec . update ( module_remove_non_updatable_params )
8289 self .module = AnsibleModule (
8390 argument_spec = argument_spec ,
8491 supports_check_mode = supports_check_mode ,
@@ -421,6 +428,7 @@ def install(self):
421428 @trace
422429 def create_or_update (self ):
423430 desired_state = self .module .params ["state" ]
431+ remove_non_updatable_params = self .module .params .get ("remove_non_updatable_params" , "no" )
424432 if (
425433 desired_state == "present" and
426434 self .resource_name .endswith ("_binding" ) and
@@ -494,7 +502,8 @@ def create_or_update(self):
494502 else :
495503 # Update process will go through 2 iterations of is_resource_identical
496504 # 1. First iteration will check if the resource is identical. If not, it will give the list of non-updatable attributes that exists
497- # in the user playbook. If non-updatable attributes are present, it will remove them from the module_params and update the resource
505+ # in the user playbook. If non-updatable attributes are present and user marks `remove_non_updatable_params` as yes,
506+ # it will remove them from the module_params and update the resource
498507 # 2. Second iteration will check if the resource is identical. If not, it will update the resource after ignoring the
499508 # non-updatable resources
500509 is_identical , immutable_keys_list = self .is_resource_identical ()
@@ -541,8 +550,9 @@ def create_or_update(self):
541550 ok , err = create_resource (
542551 self .client , self .resource_name , self .resource_module_params
543552 )
544-
545- elif immutable_keys_list is None :
553+ # Here we are checking if resource has immutable keys
554+ # if yes, we will check if the user wants to keep the non-updatable params (which in turn will return error)
555+ elif immutable_keys_list is None or (immutable_keys_list and remove_non_updatable_params == "no" ):
546556 self .module_result ["changed" ] = True
547557 log (
548558 "INFO: Resource %s:%s exists and is different. Will be UPDATED."
@@ -554,6 +564,7 @@ def create_or_update(self):
554564 if not ok :
555565 self .return_failure (err )
556566 else :
567+ # in case user wants to remove non-updatable params, we will remove them from the module_params
557568 for key in immutable_keys_list :
558569 self .resource_module_params .pop (key )
559570
0 commit comments