Skip to content

Commit

Permalink
Release/0.0.33 (#33)
Browse files Browse the repository at this point in the history
You can retrieve parameter values from SSM
  • Loading branch information
eamonnfaherty committed May 3, 2019
2 parents e437a03 + 12e73b3 commit 055fe4a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
22 changes: 22 additions & 0 deletions docs/source/puppet/designing_your_manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ like in the example - using the parameter names like ```BucketName``` will lead
The order of precedence for parameters is account level parameters override all others and launch level parameters
override global.

#### AWS SSM Parameters
You can retrieve parameter values from SSM. Here is an an example:
```yaml
schema: puppet-2019-04-01

parameters:
CentralLoggingBucketName:
ssm:
name: central-logging-bucket-name
```

You can get a different value for each region:
```yaml
schema: puppet-2019-04-01

parameters:
CentralLoggingBucketName:
ssm:
name: central-logging-bucket-name
region: eu-west-1
```

#### Macros
You can also use a macro to set the value of a parameter. It works in the same way as a normal parameter except it
executes a function to get the value first. Here is an an example:
Expand Down
28 changes: 26 additions & 2 deletions servicecatalog_puppet/commands/expand.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy

from servicecatalog_puppet.macros import macros

from betterboto import client as betterboto_client

import logging

Expand Down Expand Up @@ -59,6 +59,8 @@ def do_expand(manifest, client):
parameter_details['default'] = result
del parameter_details['macro']

expand_parameter_ssm(parameter_details)

for first_account in new_accounts:
for parameter_name, parameter_details in first_account.get('parameters', {}).items():
if parameter_details.get('macro'):
Expand All @@ -67,6 +69,8 @@ def do_expand(manifest, client):
parameter_details['default'] = result
del parameter_details['macro']

expand_parameter_ssm(parameter_details)

times_seen = 0
for second_account in new_accounts:
if first_account.get('account_id') == second_account.get('account_id'):
Expand All @@ -91,4 +95,24 @@ def do_expand(manifest, client):
parameter_details['default'] = result
del parameter_details['macro']

return new_manifest
expand_parameter_ssm(parameter_details)

return new_manifest


def expand_parameter_ssm(parameter_details):
if parameter_details.get('ssm'):
param_name = parameter_details.get('ssm').get('name')
if parameter_details.get('ssm').get('region'):
client_kwargs = {
'region_name': parameter_details.get('ssm').get('region')
}
else:
client_kwargs = {}
with betterboto_client.ClientContextManager('ssm', **client_kwargs) as ssm:
try:
param_value = ssm.get_parameter(Name=param_name).get('Parameter').get('Value')
except ssm.exceptions.ParameterNotFound:
raise Exception("There is no SSM parameter in this region with the name: {}".format(param_name))
parameter_details['default'] = param_value
del parameter_details['ssm']
8 changes: 8 additions & 0 deletions servicecatalog_puppet/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ schema;map_params:
enum: ['get_accounts_for_path']
args:
type: str
ssm:
type: map
mapping:
name:
type: str
region:
type: str


schema;map_account_id:
type: map
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="aws-service-catalog-puppet",
version="0.0.32",
version="0.0.33",
author="Eamonn Faherty",
author_email="aws-service-catalog-tools@amazon.com",
description="Making it easier to deploy ServiceCatalog products",
Expand Down

0 comments on commit 055fe4a

Please sign in to comment.