Skip to content
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

[PR #1756/c535e630 backport][stable-8] Create droppath option in ssm_parameter.py #2274

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Aug 30, 2024

This is a backport of PR #1756 as merged into main (c535e63).

SUMMARY

In the event that there exists two parameters in Parameter Store path/to/params/foo/bar/param and path/to/params/x/y/param, a user attempting to recursively pull all parameters under the path/to/params path with the command {{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', shortnames=true, bypath=true, recursive=true ) }}" will be unable to use the shortnames argument without creating a conflict between the two param results. Only one param key will exist in the resulting dictionary.

This is problematic for users that wish to lookup a parameter hierarchy with repetitive names in the final value of the parameter path. In this scenario, users are currently forced to use the fully qualified parameter name when interacting with their dictionary results.

This pull request introduces the droppath option, which will drop the common lookup path from the names of all parameters. In the scenario above, the resulting dictionary would contain both a foo/bar/param and a /x/y/param allowing users to refer to them by their minimally differentiated name.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • lookup
ADDITIONAL INFORMATION
Step by step

Setup

  • Create parameter path/to/params/foo/bar/param with value abc
  • Create parameter path/to/params/x/y/param with value 123

Run shortnames

    • name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
      debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', shortnames=true, bypath=true, recursive=true ) }}"
  • Observe result {'param': '123'}

Run droppath

    • name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
      debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', droppath=true, bypath=true, recursive=true ) }}"
  • Observe result {'/foo/bar/param': 'abc', '/x/y/param': '123'}

Run both

    • name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
      debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', droppath=true, shortnames = true, bypath=true, recursive=true ) }}"
  • Observe error shortnames and droppath are mutually exclusive. They cannot both be set to true.

SUMMARY
In the event that there exists two parameters in Parameter Store path/to/params/foo/bar/param and path/to/params/x/y/param, a user attempting to recursively pull all parameters under the path/to/params path with the command {{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', shortnames=true, bypath=true, recursive=true ) }}" will be unable to use the shortnames argument without creating a conflict between the two param results.  Only one param key will exist in the resulting dictionary.
This is problematic for users that wish to lookup a parameter hierarchy with repetitive names in the final value of the parameter path. In this scenario, users are currently forced to use the fully qualified parameter name when interacting with their dictionary results.
This pull request introduces the droppath option,  which will drop the common lookup path from the names of all parameters. In the scenario above, the resulting dictionary would contain both a foo/bar/param and a /x/y/param  allowing users to refer to them by their minimally differentiated name.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME

lookup

ADDITIONAL INFORMATION
Step by step
Setup

Create parameter path/to/params/foo/bar/param with value abc
Create parameter path/to/params/x/y/param with value 123

Run shortnames

name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', shortnames=true, bypath=true, recursive=true ) }}"

Observe result  {'param': '123'}

Run droppath

name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', droppath=true, bypath=true, recursive=true ) }}"

Observe result  {'/foo/bar/param': 'abc', '/x/y/param': '123'}

Run both

name: return a dictionary of ssm parameters from a hierarchy path with shortened names (param instead of /PATH/to/param)
debug: msg="{{ lookup('amazon.aws.aws_ssm', '/PATH/to/params', region='ap-southeast-2', droppath=true, shortnames = true, bypath=true, recursive=true ) }}"

Observe error shortnames and droppath are mutually exclusive. They cannot both be set to true.

Reviewed-by: Mark Chappell
(cherry picked from commit c535e63)
@tremble tremble added the mergeit Merge the PR (SoftwareFactory) label Aug 30, 2024
Copy link

github-actions bot commented Aug 30, 2024

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

Copy link
Contributor

Build succeeded (gate pipeline).
https://ansible.softwarefactory-project.io/zuul/buildset/648eb61524ed439b87821ae22db2edb7

✔️ ansible-galaxy-importer SUCCESS in 5m 02s
✔️ build-ansible-collection SUCCESS in 10m 49s
✔️ ansible-test-splitter SUCCESS in 4m 23s
✔️ integration-amazon.aws-1 SUCCESS in 11m 02s
Skipped 43 jobs

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 91694ef into stable-8 Aug 30, 2024
34 of 37 checks passed
@softwarefactory-project-zuul softwarefactory-project-zuul bot deleted the patchback/backports/stable-8/c535e630811d9e8aaa6aad639cf0c804b9c02eb8/pr-1756 branch August 30, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit Merge the PR (SoftwareFactory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants