Skip to content

Commit 6beaef8

Browse files
author
Shiva Shankar Vaddepally
committed
corrected logic to handle regular resources
Signed-off-by: Shiva Shankar Vaddepally <shivashankar.vaddepally@cloud.com>
1 parent d1ba410 commit 6beaef8

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

plugins/module_utils/module_executor.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -321,30 +321,32 @@ def get_existing_resource(self):
321321
)
322322
if is_exist is False:
323323
return {}
324-
if self.resource_name not in GETALL_ONLY_RESOURCES and len(existing_resource) > 1:
325-
msg = (
326-
"ERROR: For resource `%s` Found more than one resource with the same primary key `%s` and resource_module_params %s"
327-
% (
328-
self.resource_name,
329-
self.resource_id,
330-
self.resource_module_params,
324+
if len(existing_resource) > 1:
325+
if self.resource_name in GETALL_ONLY_RESOURCES:
326+
for resources in existing_resource:
327+
# Check if all module params match this resource
328+
match_found = True
329+
for key, value in self.resource_module_params.items():
330+
if key in resources and resources[key] != value:
331+
match_found = False
332+
break
333+
334+
# If all parameters match, use this resource
335+
if match_found:
336+
self.existing_resource = resources
337+
break
338+
else:
339+
msg = (
340+
"ERROR: For resource `%s` Found more than one resource with the same primary key `%s` and resource_module_params %s"
341+
% (
342+
self.resource_name,
343+
self.resource_id,
344+
self.resource_module_params,
345+
)
331346
)
332-
)
333-
self.return_failure(msg)
334-
self.existing_resource = existing_resource[0]
347+
self.return_failure(msg)
335348
else:
336-
for resources in existing_resource:
337-
# Check if all module params match this resource
338-
match_found = True
339-
for key, value in self.resource_module_params.items():
340-
if key in resources and resources[key] != value:
341-
match_found = False
342-
break
343-
344-
# If all parameters match, use this resource
345-
if match_found:
346-
self.existing_resource = resources
347-
break
349+
self.existing_resource = existing_resource[0]
348350

349351
if self.resource_name in NITRO_ATTRIBUTES_ALIASES:
350352
self.existing_resource = self._add_nitro_attributes_aliases(

0 commit comments

Comments
 (0)