-
Notifications
You must be signed in to change notification settings - Fork 37
Read k3s_token from secrets.yml file #540
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
93ab6a3
read k3s_secret from secrets.yml
sjpb d3d9cd8
override secrets path for stackhpc terraform
sjpb 6fab7f5
remove templating of k3s_secret to terraform dir
sjpb 575f8d9
remove k3s_secret var from stackhpc env
sjpb aa93572
clarify stackhpc override for tf secrets in stackhpc
sjpb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
environments/skeleton/{{cookiecutter.environment}}/terraform/read-inventory-secrets.py
This file contains hidden or 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,45 @@ | ||
| #!/usr/bin/env python | ||
| """ opentofu external data program to load inventory string variables from | ||
| a (possibly vault-encrypted) secrets file. | ||
|
|
||
| Example usage: | ||
|
|
||
| data "external" "example" { | ||
| program = [this_file] | ||
|
|
||
| query = { | ||
| path = "${path.module}/../inventory/group_vars/all/secrets.yml" | ||
| } | ||
| } | ||
|
|
||
| The external data resource's result attribute then contains a mapping of | ||
| variable names to values. | ||
|
|
||
| NB: Only keys/values where values are strings are returned, in line with | ||
| the external program protocol. | ||
|
|
||
| NB: This approach is better than e.g. templating inventory vars as the | ||
| inventory doesn't need to be valid, which is helpful when opentofu will | ||
| template out hosts/groups. | ||
| """ | ||
|
|
||
| import sys, json, subprocess, yaml | ||
| input = sys.stdin.read() | ||
| secrets_path = json.loads(input)['path'] | ||
|
|
||
| with open(secrets_path) as f: | ||
| header = f.readline() | ||
| if header.startswith('$ANSIBLE_VAULT'): | ||
| cmd = ['ansible-vault', 'view', secrets_path] | ||
| ansible = subprocess.run(cmd, capture_output=True, text=True) | ||
| contents = ansible.stdout | ||
| else: | ||
| contents = f.read() | ||
|
|
||
| data = yaml.safe_load(contents) | ||
|
|
||
| output = {} | ||
| for k, v in data.items(): | ||
| if isinstance(v, str): | ||
| output[k] = v | ||
| print(json.dumps(output)) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.