-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-enable and update integration tests for aws_ssm_parameter_store
- Loading branch information
Showing
5 changed files
with
217 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- aws_ssm_parameter_store - fix exception when description was set without value (https://github.com/ansible-collections/community.aws/pull/1241). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
cloud/aws | ||
disabled |
3 changes: 1 addition & 2 deletions
3
tests/integration/targets/aws_ssm_parameter_store/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
--- | ||
# defaults file for aws_lambda test | ||
ssm_key_prefix: '{{resource_prefix}}' | ||
ssm_key_prefix: '{{ resource_prefix }}' |
309 changes: 197 additions & 112 deletions
309
tests/integration/targets/aws_ssm_parameter_store/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,208 @@ | ||
--- | ||
# | ||
# Author: Michael De La Rue | ||
# based on aws_lambda test cases | ||
|
||
- name: 'aws_ssm_parameter_store integration tests' | ||
- set_fact: | ||
# As a lookup plugin we don't have access to module_defaults | ||
connection_args: | ||
region: "{{ aws_region }}" | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
aws_security_token: "{{ security_token | default(omit) }}" | ||
no_log: True | ||
|
||
- name: 'aws_ssm lookup plugin integration tests' | ||
collections: | ||
- amazon.aws | ||
- amazon.aws | ||
module_defaults: | ||
group/aws: | ||
aws_access_key: '{{ aws_access_key }}' | ||
aws_secret_key: '{{ aws_secret_key }}' | ||
security_token: '{{ security_token | default(omit) }}' | ||
region: '{{ aws_region }}' | ||
vars: | ||
simple_name: '/{{ ssm_key_prefix }}/Simple' | ||
simple_description: 'This is a simple example' | ||
simple_value: 'A simple VALue' | ||
updated_description: 'This is an updated example' | ||
updated_value: 'A simple VALue **UPDATED**' | ||
block: | ||
|
||
# ============================================================ | ||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/Hello" | ||
description: "This is your first key" | ||
value: "World" | ||
|
||
- name: Check that parameter was stored correctly | ||
assert: | ||
that: | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/Hello', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token )}}' == 'World'" | ||
|
||
# ============================================================ | ||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/path/wonvar" | ||
description: "This is your first key" | ||
value: "won value" | ||
|
||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/path/toovar" | ||
description: "This is your first key" | ||
value: "too value" | ||
|
||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/path/tree/treevar" | ||
description: "This is your first key" | ||
value: "tree value" | ||
|
||
# ============================================================ | ||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/deeppath/wondir/samevar" | ||
description: "This is your first key" | ||
value: "won value" | ||
|
||
- name: Create or update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/deeppath/toodir/samevar" | ||
description: "This is your first key" | ||
value: "too value" | ||
|
||
# ============================================================ | ||
- name: debug the lookup | ||
debug: | ||
msg: "{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/path', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token, bypath=True )}}'" | ||
|
||
- name: Check that parameter path is stored and retrieved | ||
assert: | ||
that: | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/path', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token, bypath=True, shortnames=true ) | to_json }}' == '{\"toovar\": \"too value\", \"wonvar\": \"won value\"}'" | ||
|
||
# ============================================================ | ||
- name: Returns empty value in case we don't find a named parameter and default filter works | ||
assert: | ||
that: | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/Goodbye', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token )}}' == ''" | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/Goodbye', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token ) | default('I_can_has_default', true)}}' == 'I_can_has_default'" | ||
|
||
# ============================================================ | ||
- name: Handle multiple paths with one that doesn't exist - default to full names. | ||
assert: | ||
that: | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/path', '/' ~ ssm_key_prefix ~ '/dont_create_this_path_you_will_break_the_ansible_tests', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token, bypath=True ) | to_json }}' in ( '[{\"/' ~ ssm_key_prefix ~ '/path/toovar\": \"too value\", \"/' ~ ssm_key_prefix ~ '/path/wonvar\": \"won value\"}, {}]', '[{\"/' ~ ssm_key_prefix ~ '/path/wonvar\": \"won value\", \"/' ~ ssm_key_prefix ~ '/path/toovar\": \"too value\"}, {}]' )" | ||
|
||
|
||
# ============================================================ | ||
# this may be a bit of a nasty test case; we should perhaps accept _either_ value that was stored | ||
# in the two variables named 'samevar' | ||
|
||
- name: Handle multiple paths with one that doesn't exist - shortnames - including overlap. | ||
assert: | ||
that: | ||
- "'{{lookup('amazon.aws.aws_ssm', '/' ~ ssm_key_prefix ~ '/path', '/' ~ ssm_key_prefix ~ '/dont_create_this_path_you_will_break_the_ansible_tests', '/' ~ ssm_key_prefix ~ '/deeppath', region=ec2_region, aws_access_key=ec2_access_key, aws_secret_key=ec2_secret_key, aws_security_token=security_token, bypath=True, shortnames=true, recursive=true ) | to_json }}' == '[{\"toovar\": \"too value\", \"treevar\": \"tree value\", \"wonvar\": \"won value\"}, {}, {\"samevar\": \"won value\"}]'" | ||
|
||
|
||
# ============================================================ | ||
- name: Delete key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/Hello" | ||
state: absent | ||
|
||
# ============================================================ | ||
- name: Attempt delete key/value pair in aws parameter store again | ||
aws_ssm_parameter_store: | ||
name: "/{{ssm_key_prefix}}/Hello" | ||
state: absent | ||
register: result | ||
|
||
- name: assert that changed is False since parameter should be deleted | ||
assert: | ||
that: | ||
- result.changed == False | ||
# ============================================================ | ||
# Create | ||
|
||
- name: Create key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
description: '{{ simple_description }}' | ||
value: '{{ simple_value }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is changed | ||
- lookup_value == simple_value | ||
|
||
- name: Create key/value pair in aws parameter store - idempotency | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
description: '{{ simple_description }}' | ||
value: '{{ simple_value }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is not changed | ||
- lookup_value == simple_value | ||
|
||
# ============================================================ | ||
# Update description | ||
|
||
- name: Update description | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
description: '{{ updated_description }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is changed | ||
- lookup_value == simple_value | ||
|
||
- name: Update description - idempotency | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
description: '{{ updated_description }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is not changed | ||
- lookup_value == simple_value | ||
|
||
# ============================================================ | ||
# Update value | ||
|
||
- name: Update key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
value: '{{ updated_value }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is changed | ||
- lookup_value == updated_value | ||
|
||
- name: Update key/value pair in aws parameter store - idempotency | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
value: '{{ updated_value }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is not changed | ||
- lookup_value == updated_value | ||
|
||
# ============================================================ | ||
# Because we have no mechanism for viewing the description, test that passing | ||
# new value and description doesn't result in a change | ||
|
||
- name: Test no change to description | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
value: '{{ updated_value }}' | ||
description: '{{ updated_description }}' | ||
register: result | ||
|
||
- assert: | ||
that: | ||
- result is not changed | ||
|
||
# ============================================================ | ||
# Complex update | ||
|
||
- name: Complex update to key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
value: '{{ simple_value }}' | ||
description: '{{ simple_description }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is changed | ||
- lookup_value == simple_value | ||
|
||
- name: Complex update to key/value pair in aws parameter store - idempotency | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
value: '{{ simple_value }}' | ||
description: '{{ simple_description }}' | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
- assert: | ||
that: | ||
- result is not changed | ||
- lookup_value == simple_value | ||
|
||
# ============================================================ | ||
# Delete | ||
|
||
- name: Create key/value pair in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
state: absent | ||
register: result | ||
|
||
- name: Lookup a single key | ||
set_fact: | ||
lookup_value: "{{ lookup('amazon.aws.aws_ssm', simple_name, **connection_args) }}" | ||
register: info_result | ||
ignore_errors: true | ||
- assert: | ||
that: | ||
- result is changed | ||
- info_result is failed | ||
|
||
- name: Create key/value pair in aws parameter store - idempotency | ||
aws_ssm_parameter_store: | ||
name: '{{ simple_name }}' | ||
state: absent | ||
register: result | ||
|
||
- assert: | ||
that: | ||
- result is not changed | ||
|
||
always: | ||
# ============================================================ | ||
- name: Delete remaining key/value pairs in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "{{item}}" | ||
state: absent | ||
with_items: | ||
- "/{{ssm_key_prefix}}/Hello" | ||
- "/{{ssm_key_prefix}}/path/wonvar" | ||
- "/{{ssm_key_prefix}}/path/toovar" | ||
- "/{{ssm_key_prefix}}/path/tree/treevar" | ||
- "/{{ssm_key_prefix}}/deeppath/wondir/samevar" | ||
# ============================================================ | ||
- name: Delete remaining key/value pairs in aws parameter store | ||
aws_ssm_parameter_store: | ||
name: "{{item}}" | ||
state: absent | ||
ignore_errors: True | ||
with_items: | ||
- '{{ simple_name }}' |