Skip to content

Commit

Permalink
iam_saml_federation - return details of provider when no changes are …
Browse files Browse the repository at this point in the history
…made (ansible-collections#419)

* iam_saml_federation - return details of provider when no changes are made.
* iam_saml_federation - enable integration tests
  • Loading branch information
tremble authored Mar 8, 2021
1 parent a742dc1 commit 8053c30
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 16 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/419-iam_saml_federation-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- iam_saml_federation - module now returns the state of the provider when no changes are made (https://github.com/ansible-collections/community.aws/pull/419).
2 changes: 2 additions & 0 deletions plugins/modules/iam_saml_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def create_or_update_saml_provider(self, name, metadata):
res['saml_provider'] = self._build_res(resp['SAMLProviderArn'])
except botocore.exceptions.ClientError as e:
self.module.fail_json_aws(e, msg="Could not update the identity provider '{0}'".format(name))
else:
res['saml_provider'] = self._build_res(arn)

else: # create
res['changed'] = True
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/targets/iam_saml_federation/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# reason: missing-policy
unsupported

cloud/aws
shippable/aws/group4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
provider_name: 'ansible-test-{{ resource_prefix }}'
125 changes: 112 additions & 13 deletions tests/integration/targets/iam_saml_federation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,170 @@
block:
# ============================================================
# TESTS
- name: Create the identity provider

# Create

- name: Create the identity provider (check-mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example1.xml") }}'
register: create_result
check_mode: yes
- name: assert changed
assert:
that:
- create_result is changed

- name: Create the identity provider
iam_saml_federation:
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example1.xml") }}'
register: create_result
- name: assert idp created
assert:
that:
- create_result is changed
- "'saml_provider' in create_result"
- "'arn' in create_result.saml_provider"
- create_result.saml_provider.arn.startswith("arn:aws")
- create_result.saml_provider.arn.endswith(provider_name)
- "'create_date' in create_result.saml_provider"
- "'expire_date' in create_result.saml_provider"
- "'metadata_document' in create_result.saml_provider"

- name: Test that nothing changes when we retry
- name: Test that nothing changes when we retry (check_mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example1.xml") }}'
register: create_result
check_mode: yes
- name: assert the idp doesn't change when we retry
assert:
that:
- create_result is not changed

- name: Test that nothing changes when we retry
iam_saml_federation:
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example1.xml") }}'
register: create_result
- name: assert the idp doesn't change when we retry
assert:
that:
- create_result is not changed
- "'saml_provider' in create_result"
- "'arn' in create_result.saml_provider"
- create_result.saml_provider.arn.startswith("arn:aws")
- create_result.saml_provider.arn.endswith(provider_name)
- "'create_date' in create_result.saml_provider"
- "'expire_date' in create_result.saml_provider"
- "'metadata_document' in create_result.saml_provider"

- name: Change the identity provider
# Update

- name: Change the identity provider (check_mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example2.xml") }}'
register: change_result
check_mode: yes
- name: assert idp created
assert:
that:
- change_result is changed

- name: Change the identity provider
iam_saml_federation:
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example2.xml") }}'
register: change_result
- name: assert idp created
assert:
that:
- change_result is changed
- "'saml_provider' in create_result"
- "'arn' in create_result.saml_provider"
- change_result.saml_provider.arn.startswith("arn:aws")
- change_result.saml_provider.arn.endswith(provider_name)
- "'create_date' in create_result.saml_provider"
- "'expire_date' in create_result.saml_provider"
- "'metadata_document' in create_result.saml_provider"

- name: Test that nothing changes when we retry
- name: Test that nothing changes when we retry (check_mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example2.xml") }}'
register: change_result
check_mode: yes
- name: assert the idp doesn't change when we retry
assert:
that:
- change_result is not changed

- name: Test that nothing changes when we retry
iam_saml_federation:
name: '{{ provider_name }}'
state: present
saml_metadata_document: '{{ lookup("file", "example2.xml") }}'
register: change_result
- name: assert the idp doesn't change when we retry
assert:
that:
- change_result is not changed
- "'saml_provider' in create_result"
- "'arn' in create_result.saml_provider"
- change_result.saml_provider.arn.startswith("arn:aws")
- change_result.saml_provider.arn.endswith(provider_name)
- "'create_date' in create_result.saml_provider"
- "'expire_date' in create_result.saml_provider"
- "'metadata_document' in create_result.saml_provider"

- name: Delete the identity provider
# delete

- name: Delete the identity provider (check_mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: absent
register: destroy_result
check_mode: yes
- name: assert changed
assert:
that:
- destroy_result is changed

- name: Delete the identity provider
iam_saml_federation:
name: '{{ provider_name }}'
state: absent
register: destroy_result
- name: assert deleted
assert:
that:
- destroy_result is changed

- name: Attempt to re-delete the identity provider
- name: Attempt to re-delete the identity provider (check_mode)
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: absent
register: destroy_result
check_mode: yes
- name: assert deleted
assert:
that:
- destroy_result is not changed

- name: Attempt to re-delete the identity provider
iam_saml_federation:
name: '{{ provider_name }}'
state: absent
register: destroy_result
- name: assert deleted
assert:
that:
Expand All @@ -84,6 +183,6 @@
# CLEAN-UP
- name: finish off by deleting the identity provider
iam_saml_federation:
name: '{{ resource_prefix }}-saml'
name: '{{ provider_name }}'
state: absent
register: destroy_result

0 comments on commit 8053c30

Please sign in to comment.