Skip to content

Instantly share code, notes, and snippets.

@jerm
Last active March 29, 2019 05:29
Show Gist options
  • Save jerm/d82b855235c6512ea8eec0626a23243d to your computer and use it in GitHub Desktop.
Save jerm/d82b855235c6512ea8eec0626a23243d to your computer and use it in GitHub Desktop.
Takes a 4 tier yaml file (project/app/level/key) and imports it into AWS encrypted parameter store
#!/usr/bin/env python
import os
import boto3
import yaml
import click
from ansible_vault import Vault
def update_aws_settings(filename=None, ansible_vault=False, password=None):
# type: (str, bool, str) -> None
client = boto3.client('ssm')
if ansible_vault:
vault = Vault()
data = vault.load(open('secrets.yml').read())
else:
with open(filename) as fh:
data = yaml.load(fh)
for projectname, projectdata in data.items():
for appname, appdata in projectdata.items():
for level, params in appdata.items():
for param, value in params.items():
print("Adding {}".format(param))
response = client.put_parameter(
Name="/{}/{}/{}/{}".format(projectname, appname, level, param),
Description="{} {} {} {}".format(projectname, appname, level, param),
Value=value,
Type='SecureString',
Overwrite=True,
)
@click.command()
@click.option('--filename', type=str, default="secrets.yml", help="YAML parameter file")
def main(filename):
# type: (str) -> None
update_aws_settings(filename, ansible_vault=True
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment