Skip to content

Commit

Permalink
fixing issue #568 (#569)
Browse files Browse the repository at this point in the history
* fixing issue #568
  • Loading branch information
eamonnfaherty committed Sep 23, 2022
1 parent 52d6175 commit 5758178
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.193.0"
version = "0.194.0"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down
34 changes: 34 additions & 0 deletions servicecatalog_puppet/commands/task_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,40 @@ def handle_stacks(
task_reference,
task_to_add,
):
prepare_task_reference = f"{constants.PREPARE_ACCOUNT_FOR_STACKS}-{task_to_add.get('account_id')}"
if not all_tasks.get(prepare_task_reference):
all_tasks[prepare_task_reference] = dict(
task_reference=prepare_task_reference,

account_id=task_to_add.get('account_id'),
puppet_account_id=puppet_account_id,

dependencies_by_reference=list(),
reverse_dependencies_by_reference=list(),

manifest_section_name=list(),
manifest_item_name=list(),
manifest_account_id=list(),
manifest_account_ids=dict(),

section_name=constants.PREPARE_ACCOUNT_FOR_STACKS,
)
all_tasks[all_tasks_task_reference]["dependencies_by_reference"].append(
prepare_task_reference
)
all_tasks[prepare_task_reference]["manifest_section_name"].extend(
task_to_add.get("manifest_section_name")
)
all_tasks[prepare_task_reference]["manifest_item_name"].extend(
task_to_add.get("manifest_item_name")
)
all_tasks[prepare_task_reference]["manifest_account_id"].extend(
task_to_add.get("manifest_account_id")
)
all_tasks[prepare_task_reference]["manifest_account_ids"].update(
task_to_add.get("manifest_account_ids")
)

get_s3_template_ref = f"{constants.GET_TEMPLATE_FROM_S3}-{section_name}-{item_name}"
if not all_tasks.get(get_s3_template_ref):
all_tasks[get_s3_template_ref] = dict(
Expand Down
3 changes: 3 additions & 0 deletions servicecatalog_puppet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,6 @@
RUN_DEPLOY_IN_SPOKE = "run-deploy-in-spoke"
GENERATE_MANIFEST = "generate-manifest"
GET_TEMPLATE_FROM_S3 = "get-template-from-s3"


PREPARE_ACCOUNT_FOR_STACKS = "prepare-account-for-stacks"
Original file line number Diff line number Diff line change
Expand Up @@ -790,5 +790,18 @@ def create(
manifest_task_reference_file_path=manifest_task_reference_file_path,
)

elif section_name == constants.PREPARE_ACCOUNT_FOR_STACKS:
from servicecatalog_puppet.workflow.stack import prepare_account_for_stack_task

return prepare_account_for_stack_task.PrepareAccountForWorkspaceTask(
puppet_account_id=parameters_to_use.get("puppet_account_id"),
task_reference=parameters_to_use.get("task_reference"),
dependencies_by_reference=parameters_to_use.get(
"dependencies_by_reference"
),
account_id=parameters_to_use.get("account_id"),
manifest_task_reference_file_path=manifest_task_reference_file_path,
)

else:
raise Exception(f"Unknown section_name: {section_name}")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,59 @@

import luigi

from servicecatalog_puppet import constants
from servicecatalog_puppet.workflow import tasks
from servicecatalog_puppet.workflow.stack import create_template_for_stack_task
from servicecatalog_puppet import constants, config

import troposphere as t
from troposphere import iam

class PrepareAccountForWorkspaceTask(tasks.PuppetTask): # TODO make task with reference
from servicecatalog_puppet.workflow.dependencies import tasks


class PrepareAccountForWorkspaceTask(tasks.TaskWithReference):
account_id = luigi.Parameter()

def params_for_results_display(self):
return {
"account_id": self.account_id,
}

def requires(self):
return create_template_for_stack_task.CreateTemplateForStackTask()

def api_calls_used(self):
return {
f"cloudformation.create_or_update_{self.account_id}": 1,
}

def run(self):
template = self.input().open("r").read()
puppet_version = constants.VERSION
description = f"""Bootstrap template used to configure spoke account for stack use
{{"version": "{puppet_version}", "framework": "servicecatalog-puppet", "role": "bootstrap-spoke-stack"}}"""

template = t.Template(Description=description)

template.add_resource(
iam.Role(
"PuppetStackRole",
RoleName="PuppetStackRole",
ManagedPolicyArns=[
t.Sub("arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess")
],
Path=config.get_puppet_role_path(),
AssumeRolePolicyDocument={
"Version": "2012-10-17",
"Statement": [
{
"Action": ["sts:AssumeRole"],
"Effect": "Allow",
"Principal": {"Service": ["cloudformation.amazonaws.com"]},
}
],
},
)
)

with self.spoke_client("cloudformation") as cloudformation:
cloudformation.create_or_update(
StackName=constants.STACK_SPOKE_PREP_STACK_NAME,
TemplateBody=template,
TemplateBody=template.to_yaml(),
Capabilities=["CAPABILITY_NAMED_IAM"],
ShouldDeleteRollbackComplete=self.should_delete_rollback_complete_stacks,
Tags=self.initialiser_stack_tags,
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.193.0',
'version': '0.194.0',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
'author_email': 'aws-service-catalog-tools@amazon.com',
'maintainer': None,
'maintainer_email': None,
'maintainer': 'None',
'maintainer_email': 'None',
'url': 'https://service-catalog-tools-workshop.com/',
'package_dir': package_dir,
'packages': packages,
Expand Down

0 comments on commit 5758178

Please sign in to comment.