Skip to content

Commit

Permalink
Release/0.0.41 (#47)
Browse files Browse the repository at this point in the history
changing home param to read from ssm parameter
  • Loading branch information
eamonnfaherty committed May 13, 2019
1 parent 5da55d7 commit 61e560c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 17 deletions.
5 changes: 2 additions & 3 deletions servicecatalog_puppet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
from servicecatalog_puppet.commands.list_launches import do_list_launches
from servicecatalog_puppet.utils import manifest as manifest_utils
from servicecatalog_puppet.asset_helpers import resolve_from_site_packages
from servicecatalog_puppet.constants import HOME_REGION, \
CONFIG_PARAM_NAME, CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN
from servicecatalog_puppet.constants import CONFIG_PARAM_NAME, CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN
from servicecatalog_puppet.core import get_org_iam_role_arn, write_templates, create_share_template, \
deploy_launches
from servicecatalog_puppet.commands.bootstrap import do_bootstrap
Expand Down Expand Up @@ -175,7 +174,7 @@ def validate(f):
@cli.command()
def version():
click.echo("cli version: {}".format(pkg_resources.require("aws-service-catalog-puppet")[0].version))
with betterboto_client.ClientContextManager('ssm', region_name=HOME_REGION) as ssm:
with betterboto_client.ClientContextManager('ssm') as ssm:
response = ssm.get_parameter(
Name="service-catalog-puppet-regional-version"
)
Expand Down
12 changes: 9 additions & 3 deletions servicecatalog_puppet/commands/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from threading import Thread

import os
import click
from betterboto import client as betterboto_client
from jinja2 import Template
Expand All @@ -11,7 +11,7 @@

def do_bootstrap(puppet_version):
click.echo('Starting bootstrap')
ALL_REGIONS = get_regions()
ALL_REGIONS = get_regions(os.environ.get("AWS_DEFAULT_REGION"))
with betterboto_client.MultiRegionClientContextManager('cloudformation', ALL_REGIONS) as clients:
click.echo('Creating {}-regional'.format(BOOTSTRAP_STACK_NAME))
threads = []
Expand All @@ -27,6 +27,11 @@ def do_bootstrap(puppet_version):
'ParameterValue': puppet_version,
'UsePreviousValue': False,
},
{
'ParameterKey': 'DefaultRegionValue',
'ParameterValue': os.environ.get('AWS_DEFAULT_REGION'),
'UsePreviousValue': False,
},
],
}
for client_region, client in clients.items():
Expand Down Expand Up @@ -59,7 +64,8 @@ def do_bootstrap(puppet_version):
],
}
cloudformation.create_or_update(**args)
click.echo('Finished creating {}.'.format(BOOTSTRAP_STACK_NAME))

click.echo('Finished creating {}.'.format(BOOTSTRAP_STACK_NAME))
with betterboto_client.ClientContextManager('codecommit') as codecommit:
response = codecommit.get_repository(repositoryName=SERVICE_CATALOG_PUPPET_REPO_NAME)
clone_url = response.get('repositoryMetadata').get('cloneUrlHttp')
Expand Down
2 changes: 1 addition & 1 deletion servicecatalog_puppet/commands/list_launches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def do_list_launches(manifest):
click.echo("Getting details from your account...")
ALL_REGIONS = get_regions()
ALL_REGIONS = get_regions(os.environ.get("AWS_DEFAULT_REGION"))
deployment_map = build_deployment_map(manifest)
account_ids = [a.get('account_id') for a in manifest.get('accounts')]
deployments = {}
Expand Down
4 changes: 2 additions & 2 deletions servicecatalog_puppet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OUTPUT = "output"
TEMPLATES = os.path.sep.join([OUTPUT, "templates"])
LAUNCHES = os.path.sep.join([OUTPUT, "launches"])
HOME_REGION = os.environ.get('AWS_DEFAULT_REGION', 'eu-west-1')
CONFIG_PARAM_NAME = "/servicecatalog-puppet/config"
CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN = "/servicecatalog-puppet/org-iam-role-arn"
PUPPET_ORG_ROLE_FOR_EXPANDS_ARN = "PuppetOrgRoleForExpandsArn"
PUPPET_ORG_ROLE_FOR_EXPANDS_ARN = "PuppetOrgRoleForExpandsArn"
HOME_REGION_PARAM_NAME = "/servicecatalog-puppet/home-region"
24 changes: 17 additions & 7 deletions servicecatalog_puppet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@
from jinja2 import Environment, FileSystemLoader

from servicecatalog_puppet.asset_helpers import resolve_from_site_packages
from servicecatalog_puppet.constants import HOME_REGION, CONFIG_PARAM_NAME, CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN, TEMPLATES, PREFIX
from servicecatalog_puppet.constants import HOME_REGION_PARAM_NAME, CONFIG_PARAM_NAME, CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN, TEMPLATES, PREFIX

logger = logging.getLogger()


def get_regions():
with betterboto_client.ClientContextManager('ssm', region_name=HOME_REGION) as ssm:
def get_regions(default_region=None):
logger.info("getting regions, default_region: {}".format(default_region))
with betterboto_client.ClientContextManager(
'ssm',
region_name=default_region if default_region else get_home_region()
) as ssm:
response = ssm.get_parameter(Name=CONFIG_PARAM_NAME)
config = yaml.safe_load(response.get('Parameter').get('Value'))
return config.get('regions')


def get_home_region():
with betterboto_client.ClientContextManager('ssm') as ssm:
response = ssm.get_parameter(Name=HOME_REGION_PARAM_NAME)
return response.get('Parameter').get('Value')


def get_org_iam_role_arn():
with betterboto_client.ClientContextManager('ssm', region_name=HOME_REGION) as ssm:
with betterboto_client.ClientContextManager('ssm', region_name=get_home_region()) as ssm:
try:
response = ssm.get_parameter(Name=CONFIG_PARAM_NAME_ORG_IAM_ROLE_ARN)
return yaml.safe_load(response.get('Parameter').get('Value'))
Expand Down Expand Up @@ -188,7 +198,7 @@ def write_share_template(portfolio_use_by_account, region, host_account_id, shar
env.get_template('shares.template.yaml.j2').render(
portfolio_use_by_account=portfolio_use_by_account,
host_account_id=host_account_id,
HOME_REGION=HOME_REGION,
HOME_REGION=get_home_region(),
sharing_policies=sharing_policies,
)
)
Expand Down Expand Up @@ -368,7 +378,7 @@ def deploy_launch_to_account_and_region(
],
NotificationArns=[
"arn:aws:sns:{}:{}:servicecatalog-puppet-cloudformation-events".format(
HOME_REGION,
get_home_region(),
puppet_account_id
),
],
Expand Down Expand Up @@ -429,7 +439,7 @@ def deploy_launch_to_account_and_region(
for outputs in launch.get('outputs', {}).get('ssm', []):
ssm_param_name = outputs.get('param_name')
ssm_param_value = outputs.get('stack_output')
ssm_param_region = outputs.get('region', HOME_REGION)
ssm_param_region = outputs.get('region', get_home_region())
logger.info('Trying to set SSM parameter: {}'.format(ssm_param_name))
logger.info(('Looking for stack: {}'.format(stack_name)))
stack_response = cloudformation.describe_stacks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ Parameters:
Version:
Type: String
Default: "{{ VERSION }}"
DefaultRegionValue:
Type: String

Resources:

DefaultRegionParam:
Type: AWS::SSM::Parameter
Properties:
Name: /servicecatalog-puppet/home-region
Type: String
Value: !Ref DefaultRegionValue

Param:
Type: AWS::SSM::Parameter
Properties:
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.40",
version="0.0.41",
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 61e560c

Please sign in to comment.