Skip to content

Support fetching full attributes (ARN, Description, LastChangedDate, Tags... etc) #2538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

8a8al00ey
Copy link

@8a8al00ey 8a8al00ey commented Feb 27, 2025

Supports fetching full attributes (ARN, Description, LastChangedDate, Tags)

SUMMARY

Supports fetching full attributes (ARN, Description, LastChangedDate, Tags)
The community.aws version has the ability but it is very hacky and dangerous. You'd need to match rotation, resource policy, tags and replication options.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Supports fetching full attributes (ARN, Description, LastChangedDate, Tags)

ADDITIONAL INFORMATION

Supports fetching full attributes (ARN, Description, LastChangedDate, Tags)

Currently there isn't a safe way to describe a secret to obtain ie: LastChangedDate

# This will retrieve the secrets attributes
- name: Lookup secretsmanager secret attributes in the current region
  ansible.builtin.debug: msg="{{ lookup('amazon.aws.aws_secret', '/path/to/secrets', get_attributes=true) }}"

Copy link

github-actions bot commented Feb 27, 2025

Docs Build 📝

Thank you for contribution!✨

The docsite for this PR is available for download as an artifact from this run:
https://github.com/ansible-collections/amazon.aws/actions/runs/15139938212

You can compare to the docs for the main branch here:
https://ansible-collections.github.io/amazon.aws/branch/main

File changes:

  • M collections/amazon/aws/secretsmanager_secret_lookup.html
Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/amazon.aws/amazon.aws/docsbuild/base/collections/amazon/aws/secretsmanager_secret_lookup.html b/home/runner/work/amazon.aws/amazon.aws/docsbuild/head/collections/amazon/aws/secretsmanager_secret_lookup.html
index 201fcc2..fc389b4 100644
--- a/home/runner/work/amazon.aws/amazon.aws/docsbuild/base/collections/amazon/aws/secretsmanager_secret_lookup.html
+++ b/home/runner/work/amazon.aws/amazon.aws/docsbuild/head/collections/amazon/aws/secretsmanager_secret_lookup.html
@@ -164,7 +164,8 @@ see <a class="reference internal" href="#ansible-collections-amazon-aws-secretsm
 <ul class="simple">
 <li><p>Look up secrets stored in AWS Secrets Manager provided the caller has the appropriate permissions to read the secret.</p></li>
 <li><p>Lookup is based on the secret’s <em>Name</em> value.</p></li>
-<li><p>Optional parameters can be passed into this lookup; <code class="ansible-option docutils literal notranslate"><strong><a class="reference internal" href="#ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-id"><span class="std std-ref"><span class="pre">version_id</span></span></a></strong></code> and <code class="ansible-option docutils literal notranslate"><strong><a class="reference internal" href="#ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-stage"><span class="std std-ref"><span class="pre">version_stage</span></span></a></strong></code>.</p></li>
+<li><p>Supports fetching full attributes (ARN, Description, LastChangedDate, Tags) aka boto’s describe_secret.</p></li>
+<li><p>Optional parameters for get value include <code class="ansible-option docutils literal notranslate"><strong><a class="reference internal" href="#ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-id"><span class="std std-ref"><span class="pre">version_id</span></span></a></strong></code>, <code class="ansible-option docutils literal notranslate"><strong><a class="reference internal" href="#ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-stage"><span class="std std-ref"><span class="pre">version_stage</span></span></a></strong></code>.</p></li>
 <li><p>Prior to release 6.0.0 this module was known as <code class="docutils literal notranslate"><span class="pre">aws_ssm</span></code>, the usage remains the same.</p></li>
 </ul>
 <p>Aliases: aws_secret</p>
@@ -253,6 +254,19 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </div></td>
 </tr>
 <tr class="row-odd"><td><div class="ansible-option-cell">
+<div class="ansibleOptionAnchor" id="parameter-get_attributes"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-get-attributes"><strong>get_attributes</strong></p>
+<a class="ansibleOptionLink" href="#parameter-get_attributes" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
+<p><em class="ansible-option-versionadded">added in amazon.aws 9.4.0</em></p>
+</div></td>
+<td><div class="ansible-option-cell"><p>Whether to return full attributes instead of just the secret value.</p>
+<p class="ansible-option-line"><strong class="ansible-option-choices">Choices:</strong></p>
+<ul class="simple">
+<li><p><code class="ansible-option-default-bold docutils literal notranslate"><strong><span class="pre">false</span></strong></code> <span class="ansible-option-choices-default-mark">← (default)</span></p></li>
+<li><p><code class="ansible-option-choices-entry docutils literal notranslate"><span class="pre">true</span></code></p></li>
+</ul>
+</div></td>
+</tr>
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-join"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-join"><strong>join</strong></p>
 <a class="ansibleOptionLink" href="#parameter-join" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 </div></td>
@@ -266,7 +280,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-nested"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-nested"><strong>nested</strong></p>
 <a class="ansibleOptionLink" href="#parameter-nested" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">boolean</span></p>
 <p><em class="ansible-option-versionadded">added in amazon.aws 1.4.0</em></p>
@@ -279,7 +293,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-on_deleted"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-on-deleted"><strong>on_deleted</strong></p>
 <a class="ansibleOptionLink" href="#parameter-on_deleted" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 <p><em class="ansible-option-versionadded">added in amazon.aws 2.0.0</em></p>
@@ -296,7 +310,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-on_denied"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-on-denied"><strong>on_denied</strong></p>
 <a class="ansibleOptionLink" href="#parameter-on_denied" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -312,7 +326,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-on_missing"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-on-missing"><strong>on_missing</strong></p>
 <a class="ansibleOptionLink" href="#parameter-on_missing" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -328,7 +342,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-profile"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_profile"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-profile"><span id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-aws-profile"></span><strong>profile</strong></p>
 <a class="ansibleOptionLink" href="#parameter-profile" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_profile</span></p>
@@ -344,7 +358,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-region"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_region"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-region"><span id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-aws-region"></span><strong>region</strong></p>
 <a class="ansibleOptionLink" href="#parameter-region" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_region</span></p>
@@ -358,7 +372,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-secret_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_access_key"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_secret_key"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-secret-key"><span id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-aws-secret-key"></span><span id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-aws-secret-access-key"></span><strong>secret_key</strong></p>
@@ -376,7 +390,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-session_token"></div>
 <div class="ansibleOptionAnchor" id="parameter-aws_session_token"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-session-token"><span id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-aws-session-token"></span><strong>session_token</strong></p>
 <a class="ansibleOptionLink" href="#parameter-session_token" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-aliases">aliases: aws_session_token</span></p>
@@ -391,14 +405,14 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 </ul>
 </div></td>
 </tr>
-<tr class="row-even"><td><div class="ansible-option-cell">
+<tr class="row-odd"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-version_id"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-id"><strong>version_id</strong></p>
 <a class="ansibleOptionLink" href="#parameter-version_id" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
 <td><div class="ansible-option-cell"><p>Version of the secret(s).</p>
 </div></td>
 </tr>
-<tr class="row-odd"><td><div class="ansible-option-cell">
+<tr class="row-even"><td><div class="ansible-option-cell">
 <div class="ansibleOptionAnchor" id="parameter-version_stage"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-parameter-version-stage"><strong>version_stage</strong></p>
 <a class="ansibleOptionLink" href="#parameter-version_stage" title="Permalink to this option"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
@@ -425,6 +439,9 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 <div class="highlight-yaml+jinja notranslate"><div class="highlight"><pre><span></span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Lookup secretsmanager secret in the current region</span>
 <span class="w">  </span><span class="nt">ansible.builtin.debug</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">msg=&quot;</span><span class="cp">{{</span> <span class="nv">lookup</span><span class="o">(</span><span class="s1">&#39;amazon.aws.aws_secret&#39;</span><span class="o">,</span> <span class="s1">&#39;/path/to/secrets&#39;</span><span class="o">,</span> <span class="nv">bypath</span><span class="o">=</span><span class="kp">true</span><span class="o">)</span> <span class="cp">}}</span><span class="l l-Scalar l-Scalar-Plain">&quot;</span>
 
+<span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Lookup secretsmanager secret attributes in the current region</span>
+<span class="w">  </span><span class="nt">ansible.builtin.debug</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">msg=&quot;</span><span class="cp">{{</span> <span class="nv">lookup</span><span class="o">(</span><span class="s1">&#39;amazon.aws.aws_secret&#39;</span><span class="o">,</span> <span class="s1">&#39;/path/to/secrets&#39;</span><span class="o">,</span> <span class="nv">get_attributes</span><span class="o">=</span><span class="kp">true</span><span class="o">)</span> <span class="cp">}}</span><span class="l l-Scalar l-Scalar-Plain">&quot;</span>
+
 <span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Create RDS instance with aws_secret lookup for password param</span>
 <span class="w">  </span><span class="nt">amazon.aws.rds_instance</span><span class="p">:</span>
 <span class="w">    </span><span class="nt">state</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">present</span>
@@ -470,7 +487,7 @@ examples: <code class="docutils literal notranslate"><span class="pre">lookup('a
 <div class="ansibleOptionAnchor" id="return-_raw"></div><p class="ansible-option-title" id="ansible-collections-amazon-aws-secretsmanager-secret-lookup-return-raw"><strong>Return value</strong></p>
 <a class="ansibleOptionLink" href="#return-_raw" title="Permalink to this return value"></a><p class="ansible-option-type-line"><span class="ansible-option-type">string</span></p>
 </div></td>
-<td><div class="ansible-option-cell"><p>Returns the value of the secret stored in AWS Secrets Manager.</p>
+<td><div class="ansible-option-cell"><p>Returns either the secret value or a dictionary containing attributes stored in AWS Secrets Manager.</p>
 <p class="ansible-option-line"><strong class="ansible-option-returned-bold">Returned:</strong> success</p>
 </div></td>
 </tr>

Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/2fc3880bc69d486eb32de94135880190

✔️ ansible-galaxy-importer SUCCESS in 3m 23s
✔️ build-ansible-collection SUCCESS in 10m 18s
✔️ ansible-test-splitter SUCCESS in 3m 51s
✔️ integration-amazon.aws-1 SUCCESS in 4m 25s
Skipped 43 jobs

@8a8al00ey 8a8al00ey changed the title Update secretsmanager_secret.py Support fetching full attributes (ARN, Description, LastChangedDate, Tags) Feb 27, 2025
@8a8al00ey 8a8al00ey changed the title Support fetching full attributes (ARN, Description, LastChangedDate, Tags) Support fetching full attributes (ARN, Description, LastChangedDate, Tags... etc) Feb 27, 2025
Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/3ba50ebdbbfd4afb80a409c5c1a71c80

✔️ ansible-galaxy-importer SUCCESS in 5m 14s
✔️ build-ansible-collection SUCCESS in 10m 52s
✔️ ansible-test-splitter SUCCESS in 4m 29s
✔️ integration-amazon.aws-1 SUCCESS in 5m 56s
Skipped 43 jobs

Copy link
Contributor

@abikouo abikouo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@8a8al00ey, thanks for submitting this new feature. Please add a changelog fragment describing the change and update the integration tests lookup_secretsmanager_secret to test the new feature.

Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/9e1e0cf6245b41a29e304812a34f4389

✔️ ansible-galaxy-importer SUCCESS in 5m 09s
✔️ build-ansible-collection SUCCESS in 10m 59s
✔️ ansible-test-splitter SUCCESS in 4m 09s
✔️ integration-amazon.aws-1 SUCCESS in 5m 22s
Skipped 43 jobs

Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/e396c0f6f6ab4453a26cd4bd19a3fb68

✔️ ansible-galaxy-importer SUCCESS in 8m 22s
✔️ build-ansible-collection SUCCESS in 10m 57s
✔️ ansible-test-splitter SUCCESS in 4m 05s
✔️ integration-amazon.aws-1 SUCCESS in 5m 15s
Skipped 43 jobs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants