-
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.
Add secret manager replication support (#827)
Add secret manager replication support Signed-off-by: Eric Millbrandt [email protected] SUMMARY Add support for regional secret replication. The component now supports: Creating a secret with a regional replica Adding a region replica to a secret Removing a region replica from a secret ISSUE TYPE Feature Pull Request COMPONENT NAME aws_secret ADDITIONAL INFORMATION https://aws.amazon.com/about-aws/whats-new/2021/03/aws-secrets-manager-provides-support-to-replicate-secrets-in-aws-secrets-manager-to-multiple-aws-regions/ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html Reviewed-by: Eric Millbrandt <[email protected]> Reviewed-by: Markus Bergholz <[email protected]> Reviewed-by: Mark Chappell <None> Reviewed-by: Alina Buzachis <None> Reviewed-by: Mark Woolley <[email protected]> (cherry picked from commit c7c6800)
- Loading branch information
1 parent
bf7de35
commit 8c9f8ae
Showing
4 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/827-secretsmanager_secret-replication.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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- secretsmanager_secret - added support for region replication using the ``replica`` parameter (https://github.com/ansible-collections/community.aws/pull/827). |
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
116 changes: 116 additions & 0 deletions
116
tests/integration/targets/secretsmanager_secret/tasks/replication.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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
--- | ||
- block: | ||
# ============================================================ | ||
# Creation/Deletion testing | ||
# ============================================================ | ||
- name: add secret to AWS Secrets Manager | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
state: present | ||
secret_type: 'string' | ||
secret: "{{ super_secret_string }}" | ||
replica: | ||
- region: 'us-east-2' | ||
- region: 'us-west-2' | ||
kms_key_id: 'alias/aws/secretsmanager' | ||
register: result | ||
|
||
- name: assert correct keys are returned | ||
assert: | ||
that: | ||
- result.changed | ||
- result.arn is not none | ||
- result.name is not none | ||
- result.secret.replication_status[0]["region"] == 'us-east-2' | ||
- result.secret.replication_status[1]["region"] == 'us-west-2' | ||
- result.secret.replication_status[1]["kms_key_id"] == 'alias/aws/secretsmanager' | ||
- result.tags is not none | ||
- result.version_ids_to_stages is not none | ||
|
||
- name: no changes to secret | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
state: present | ||
secret: "{{ super_secret_string }}" | ||
replica: | ||
- region: 'us-east-2' | ||
- region: 'us-west-2' | ||
kms_key_id: 'alias/aws/secretsmanager' | ||
register: result | ||
|
||
- name: assert correct keys are returned | ||
assert: | ||
that: | ||
- not result.changed | ||
- result.arn is not none | ||
|
||
- name: remove region replica | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
description: 'this is a change to remove replication' | ||
secret: "{{ super_secret_string }}" | ||
state: present | ||
replica: [] | ||
register: result | ||
|
||
- name: assert that replica was removed | ||
assert: | ||
that: | ||
- not result.failed | ||
- '"replication_status" not in result.secret' | ||
|
||
- name: add region replica to an existing secret | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
description: 'this is a change add replication' | ||
secret: "{{ super_secret_string }}" | ||
state: present | ||
replica: | ||
- region: 'us-east-2' | ||
- region: 'us-west-2' | ||
kms_key_id: 'alias/aws/secretsmanager' | ||
register: result | ||
|
||
- name: assert that replica was created | ||
assert: | ||
that: | ||
- not result.failed | ||
- result.secret.replication_status[0]["region"] == 'us-east-2' | ||
- result.secret.replication_status[1]["region"] == 'us-west-2' | ||
- result.secret.replication_status[1]["kms_key_id"] == 'alias/aws/secretsmanager' | ||
|
||
- name: change replica regions | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
state: present | ||
secret: "{{ super_secret_string }}" | ||
replica: | ||
- region: 'us-east-2' | ||
- region: 'eu-central-1' | ||
kms_key_id: 'alias/aws/secretsmanager' | ||
register: result | ||
|
||
- name: assert that replica regions changed | ||
assert: | ||
that: | ||
- not result.failed | ||
- result.secret.replication_status[0]["region"] == 'us-east-2' | ||
- result.secret.replication_status[1]["region"] == 'eu-central-1' | ||
- result.secret.replication_status[1]["kms_key_id"] == 'alias/aws/secretsmanager' | ||
|
||
always: | ||
- name: remove region replica | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
description: 'this is a change to remove replication' | ||
state: present | ||
secret: "{{ super_secret_string }}" | ||
register: result | ||
ignore_errors: yes | ||
|
||
- name: remove secret | ||
aws_secret: | ||
name: "{{ secret_name }}" | ||
state: absent | ||
recovery_window: 0 | ||
ignore_errors: yes |