Skip to content

Commit

Permalink
Fixup opensearch when using advanced security options (#1613) (#1614)
Browse files Browse the repository at this point in the history
[PR #1613/6919bac1 backport][stable-4] Fixup opensearch when using advanced security options

This is a backport of PR #1613 as merged into main (6919bac).
Fix #1560

Reviewed-by: Markus Bergholz <[email protected]>
  • Loading branch information
patchback[bot] committed Dec 7, 2022
1 parent 4a6c9af commit 1f42ae9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1613-opensearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- opensearch - Fix cluster creation when using advanced security options (https://github.com/ansible-collections/community.aws/pull/1613).
1 change: 1 addition & 0 deletions plugins/modules/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ def set_advanced_security_options(
] = advanced_security_opts.get("internal_user_database_enabled")
master_user_opts = advanced_security_opts.get("master_user_options")
if master_user_opts is not None:
advanced_security_config.setdefault("MasterUserOptions", {})
if master_user_opts.get("master_user_arn") is not None:
advanced_security_config["MasterUserOptions"][
"MasterUserARN"
Expand Down
33 changes: 31 additions & 2 deletions tests/integration/targets/opensearch/tasks/test_opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- name: test without specifying required module options
opensearch:
engine_version: "Elasticsearch_7.1"
ignore_errors: yes
ignore_errors: true
register: result

- name: assert domain_name is a required module option
Expand Down Expand Up @@ -959,7 +959,7 @@
wait_timeout: "{{ 60 * 60 }}"
register: opensearch_domain
until: opensearch_domain is not failed
ignore_errors: yes
ignore_errors: true
retries: 10
# After enabling at rest encryption, there is a period during which the API fails, so retry.
delay: 30
Expand Down Expand Up @@ -996,13 +996,22 @@
- "opensearch_domain.domain_endpoint_options.tls_security_policy == 'Policy-Min-TLS-1-2-2019-07'"
- opensearch_domain is changed

- name: Set common facts for advanced security tests
set_fact:
test_master_user_name: my_custom_admin_username
test_master_user_password: "{{ lookup('ansible.builtin.password', '/dev/null chars=ascii_lowercase,digits length=16') }}"

- name: Configure advanced security
block:
- name: Enable advanced security, check mode
opensearch:
domain_name: "es-{{ tiny_prefix }}-vpc"
advanced_security_options:
enabled: true
internal_user_database_enabled: false
master_user_options:
master_user_name: "{{ test_master_user_name }}"
master_user_password: "{{ test_master_user_password }}"
wait: true
check_mode: true
register: opensearch_domain
Expand All @@ -1019,19 +1028,31 @@
domain_name: "es-{{ tiny_prefix }}-vpc"
advanced_security_options:
enabled: true
internal_user_database_enabled: false
master_user_options:
master_user_name: "{{ test_master_user_name }}"
master_user_password: "{{ test_master_user_password }}"
wait: true
wait_timeout: "{{ 60 * 60 }}"
register: opensearch_domain
- assert:
that:
- "opensearch_domain.advanced_security_options.enabled == True"
- "opensearch_domain.advanced_security_options.internal_user_database_enabled == False"
- "opensearch_domain.advanced_security_options.master_user_options is defined"
- "opensearch_domain.advanced_security_options.master_user_options.master_user_name is test_master_user_name"
- "opensearch_domain.advanced_security_options.master_user_options.master_user_password is test_master_user_password"
- opensearch_domain is changed

- name: Enable advanced security, check mode again
opensearch:
domain_name: "es-{{ tiny_prefix }}-vpc"
advanced_security_options:
enabled: true
internal_user_database_enabled: false
master_user_options:
master_user_name: "{{ test_master_user_name }}"
master_user_password: "{{ test_master_user_password }}"
wait: true
check_mode: true
register: opensearch_domain
Expand All @@ -1044,11 +1065,19 @@
domain_name: "es-{{ tiny_prefix }}-vpc"
advanced_security_options:
enabled: true
internal_user_database_enabled: false
master_user_options:
master_user_name: "{{ test_master_user_name }}"
master_user_password: "{{ test_master_user_password }}"
wait: true
register: opensearch_domain
- assert:
that:
- "opensearch_domain.advanced_security_options.enabled == True"
- "opensearch_domain.advanced_security_options.internal_user_database_enabled == False"
- "opensearch_domain.advanced_security_options.master_user_options is defined"
- "opensearch_domain.advanced_security_options.master_user_options.master_user_name is test_master_user_name"
- "opensearch_domain.advanced_security_options.master_user_options.master_user_password is test_master_user_password"
- opensearch_domain is not changed

- name: Configure warm and cold storage
Expand Down

0 comments on commit 1f42ae9

Please sign in to comment.