Skip to content

Commit

Permalink
opensearch: avoid a KeyError during the DomainConfig reading
Browse files Browse the repository at this point in the history
This commit avoids a KeyError exception in `get_domain_config()`.
Some entries from DomainConfig don't have any `Options` key. For instance, `ChangeProgressDetails`.

See:
- https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_DomainConfig.html
- https://docs.aws.amazon.com/opensearch-service/latest/APIReference/API_ChangeProgressDetails.html
  • Loading branch information
goneri committed Aug 31, 2023
1 parent 4a5b50e commit 1aab201
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/opensearch_domainconfig_no_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "opensearch - Don't try to read a non existing key from the domain config (https://github.com/ansible-collections/community.aws/pull/1910)."
3 changes: 2 additions & 1 deletion plugins/module_utils/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def get_domain_config(client, module, domain_name):
arn = None
if response is not None:
for k in response["DomainConfig"]:
domain_config[k] = response["DomainConfig"][k]["Options"]
if "Options" in response["DomainConfig"][k]:
domain_config[k] = response["DomainConfig"][k]["Options"]
domain_config["DomainName"] = domain_name
# If ES cluster is attached to the Internet, the "VPCOptions" property is not present.
if "VPCOptions" in domain_config:
Expand Down

0 comments on commit 1aab201

Please sign in to comment.