Skip to content

Commit

Permalink
Adding initialiser template
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnfaherty committed Oct 7, 2019
1 parent 8ec1847 commit 2cd0e23
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
13 changes: 13 additions & 0 deletions servicecatalog_puppet/cli.py
Expand Up @@ -170,5 +170,18 @@ def reset_provisioned_product_owner(f):
cli_commands.reset_provisioned_product_owner(f)


@cli.command()
@click.argument('regions', nargs=-1)
def set_regions(regions):
cli_commands.set_config_value('regions', regions)


@cli.command()
@click.argument('name')
@click.argument('value')
def set_config_value(name, value, type=bool):
cli_commands.set_config_value(name, value)


if __name__ == "__main__":
cli()
16 changes: 16 additions & 0 deletions servicecatalog_puppet/cli_commands.py
Expand Up @@ -597,3 +597,19 @@ def remove_from_launches(launch_name):
manifest = get_manifest()
del manifest.get('launches')[launch_name]
save_manifest(manifest)


def set_config_value(name, value):
with betterboto_client.ClientContextManager('ssm', region_name=constants.HOME_REGION) as ssm:
try:
response = ssm.get_parameter(Name=constants.CONFIG_PARAM_NAME)
config = yaml.safe_load(response.get('Parameter').get('Value'))
except ssm.exceptions.ParameterNotFound:
config = {}

if name == "regions":
config['regions'] = value if len(value) > 1 else value[0].split(",")
else:
config[name] = value.upper() == 'TRUE'

upload_config(config)
4 changes: 3 additions & 1 deletion servicecatalog_puppet/constants.py
Expand Up @@ -33,4 +33,6 @@

EVENT_BUS_NAME = "servicecatalog-puppet-event-bus"
SERVICE_CATALOG_PUPPET_EVENT_SOURCE = "servicecatalog-puppet"
SERVICE_CATALOG_PUPPET_OPS_CENTER_SOURCE = "servicecatalog-puppet"
SERVICE_CATALOG_PUPPET_OPS_CENTER_SOURCE = "servicecatalog-puppet"

HOME_REGION = os.environ.get('AWS_REGION', os.environ.get('AWS_DEFAULT_REGION', 'eu-west-1'))
113 changes: 113 additions & 0 deletions servicecatalog_puppet/servicecatalog-puppet-initialiser.template.yaml
@@ -0,0 +1,113 @@
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

AWSTemplateFormatVersion: "2010-09-09"
Description: |
Initialiser template used to bring up the install ServiceCatalog-Puppet
{"version": "0.37.0", "framework": "servicecatalog-puppet", "role": "initialiser"}
Parameters:
Version:
Type: String
Default: "0.37.0"
Description: |
Which version of aws-service-catalog-puppet to install
EnabledRegions:
Type: String
Description: |
Space or comma seperated list of AWS Regions for which your puppet should operate in
ShouldCollectCloudformationEvents:
Type: String
AllowedValues:
- True
- False
ShouldForwardEventsToEventbridge:
Type: String
AllowedValues:
- True
- False
ShouldForwardFailuresToOpscenter:
Type: String
AllowedValues:
- True
- False

Resources:
Param:
Type: AWS::SSM::Parameter
Properties:
Name: service-catalog-puppet-initialiser-version
Type: String
Value: !Ref Version

InitialiserRole:
Type: AWS::IAM::Role
Properties:
RoleName: Initialiser
Path: /servicecatalog-product-puppet/
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess

InitialiserProject:
Type: AWS::CodeBuild::Project
Properties:
Name: servicecatalog-product-puppet-initialiser
Description: "Initialiser for the framework"
ServiceRole: !GetAtt InitialiserRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: linuxContainer
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/python:3.7.1
EnvironmentVariables:
- Name: VERSION
Type: PLAINTEXT
Value: !Ref Version

- Name: ENABLED_REGIONS
Type: PLAINTEXT
Value: !Join [ ',', !Split [ ', ', !Ref EnabledRegions]]

- Name: SHOULD_COLLECT_CLOUDFORMATION_EVENTS
Type: PLAINTEXT
Value: !Ref ShouldCollectCloudformationEvents

- Name: SHOULD_FORWARD_EVENTS_TO_EVENTBRIDGE
Type: PLAINTEXT
Value: !Ref ShouldForwardEventsToEventbridge

- Name: SHOULD_FORWARD_FAILURES_TO_OPSCENTER
Type: PLAINTEXT
Value: !Ref ShouldForwardFailuresToOpscenter
Source:
Type: NO_SOURCE
BuildSpec: !Sub |
version: 0.2
phases:
install:
commands:
- pip install aws-service-catalog-puppet==$${VERSION}
- servicecatalog-puppet --info set-regions $${ENABLED_REGIONS}
- servicecatalog-puppet set-config-value should_collect_cloudformation_events $${SHOULD_COLLECT_CLOUDFORMATION_EVENTS}
- servicecatalog-puppet set-config-value should_forward_events_to_eventbridge $${SHOULD_FORWARD_EVENTS_TO_EVENTBRIDGE}
- servicecatalog-puppet set-config-value should_forward_failures_to_opscenter $${SHOULD_FORWARD_FAILURES_TO_OPSCENTER}
- servicecatalog-puppet bootstrap-spoke ${AWS::AccountId}
build:
commands:
- servicecatalog-puppet --info bootstrap
TimeoutInMinutes: 60

Outputs:
Version:
Value: !GetAtt Param.Value
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="aws-service-catalog-puppet",
version="0.36.2",
version="0.37.0",
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 2cd0e23

Please sign in to comment.