Skip to content

Commit

Permalink
fix: some scenarios where a depends on b depends on c where failing t…
Browse files Browse the repository at this point in the history
…o execute

fix: a->b->c dep failure
  • Loading branch information
eamonnfaherty committed Jun 6, 2023
2 parents ca9c38f + 95674e1 commit 3fc45e5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Makefile.Puppet
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ deploy-from-task-reference:
time poetry run servicecatalog-puppet --info deploy-from-task-reference --num-workers 5 \
ignored/src/ServiceCatalogPuppet/

## @Puppet_commands Runs servicecatalog-puppet --info deploy-from-task-reference for the checked out manifest file
## @uppet_commands Runs servicecatalog-puppet --info deploy-from-task-reference for the checked out manifest file
deploy-from-task-reference-single-account:
time poetry run servicecatalog-puppet --info deploy-in-spoke-from-task-reference \
--execution-mode spoke \
Expand Down Expand Up @@ -76,4 +76,4 @@ show-pipelines:
poetry run servicecatalog-puppet --info show-pipelines

vizviewer:
poetry run vizviewer result.json
poetry run vizviewer result.json
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.229.0"
version = "0.230.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
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def ssm_parameter_handler(
f"Cannot use cross account SSM parameters in execution mode: {task_execution}"
)

task_def = dict(
ssm_task_params = dict(
account_id=owning_account,
region=owning_region,
manifest_section_names=dict(**task.get("manifest_section_names")),
manifest_item_names=dict(**task.get("manifest_item_names")),
manifest_account_ids=dict(**task.get("manifest_account_ids")),
manifest_section_names=dict(),
manifest_item_names=dict(),
manifest_account_ids=dict(),
dependencies=[],
execution=task_execution,
)
Expand All @@ -71,34 +71,43 @@ def ssm_parameter_handler(
ssm_parameter_task_reference = (
f"{constants.SSM_PARAMETERS}-{task_reference}-{param_name}"
)
task_def["param_name"] = param_name
task_def["section_name"] = constants.SSM_PARAMETERS
ssm_task_params["param_name"] = param_name
ssm_task_params["section_name"] = constants.SSM_PARAMETERS
else:
ssm_parameter_task_reference = (
f"{constants.SSM_PARAMETERS_WITH_A_PATH}-{task_reference}-{path}"
)
task_def["path"] = path
task_def["section_name"] = constants.SSM_PARAMETERS_WITH_A_PATH
task_def["task_reference"] = ssm_parameter_task_reference
ssm_task_params["path"] = path
ssm_task_params["section_name"] = constants.SSM_PARAMETERS_WITH_A_PATH
ssm_task_params["task_reference"] = ssm_parameter_task_reference

ssm_task_dependencies = []

potential_output_task_ref = f"{constants.SSM_PARAMETERS}-{task_reference}-{param_name}".replace(
f"{constants.SSM_PARAMETERS}-", f"{constants.SSM_OUTPUTS}-"
)
if all_tasks.get(potential_output_task_ref):
dependency = [potential_output_task_ref]
else:
dependency = []
task_def["dependencies_by_reference"] = dependency
ssm_task_dependencies.append(potential_output_task_ref)

ssm_task_params["dependencies_by_reference"] = ssm_task_dependencies

# IF THERE ARE TWO TASKS USING THE SAME PARAMETER AND THE OTHER TASK ADDED IT FIRST
if new_tasks.get(ssm_parameter_task_reference):
existing_task_def = new_tasks[ssm_parameter_task_reference]
# AVOID DUPLICATE DEPENDENCIES IN THE SAME LIST
for dep in dependency:
for dep in ssm_task_dependencies:
if dep not in existing_task_def["dependencies_by_reference"]:
existing_task_def["dependencies_by_reference"].append(dep)
else:
new_tasks[ssm_parameter_task_reference] = task_def
new_tasks[ssm_parameter_task_reference] = ssm_task_params

ssm_task_params["manifest_section_names"].update(
**task.get("manifest_section_names")
)
ssm_task_params["manifest_item_names"].update(**task.get("manifest_item_names"))
ssm_task_params["manifest_account_ids"].update(
**task.get("manifest_account_ids")
)

ssm_parameter_task = new_tasks[ssm_parameter_task_reference]
ssm_parameter_task["manifest_section_names"].update(
Expand All @@ -110,6 +119,8 @@ def ssm_parameter_handler(
ssm_parameter_task["manifest_account_ids"].update(
task.get("manifest_account_ids")
)
ssm_parameter_task["dependencies"].extend(task.get("dependencies"))
ssm_parameter_task["dependencies_by_reference"].extend(
task.get("dependencies_by_reference")
)

task["dependencies_by_reference"].append(ssm_parameter_task_reference)
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ def test_for_ssm_parameters_for_spoke_execution_mode(self):
"param_name": f"/sleeper/SleeperFunctionArn/{region}/stacks",
"section_name": constants.SSM_PARAMETERS,
"task_reference": expected_ssm_parameter_task_ref,
"dependencies_by_reference": [],
"dependencies": task.get("dependencies"),
"dependencies_by_reference": [
"create-policies",
"prepare-account-for-stacks-spoke_account_id",
"get-template-from-s3-stacks-depsrefactor",
],
"dependencies": [],
},
all_tasks[expected_ssm_parameter_task_ref],
"assert the boto3 task is generated correctly",
Expand Down Expand Up @@ -196,8 +200,12 @@ def test_for_ssm_parameters_for_hub_execution_mode(self):
"param_name": f"/sleeper/SleeperFunctionArn/{region}/stacks",
"section_name": constants.SSM_PARAMETERS,
"task_reference": expected_ssm_parameter_task_ref,
"dependencies_by_reference": [],
"dependencies": task.get("dependencies"),
"dependencies_by_reference": [
"create-policies",
"prepare-account-for-stacks-spoke_account_id",
"get-template-from-s3-stacks-depsrefactor",
],
"dependencies": [],
},
all_tasks[expected_ssm_parameter_task_ref],
"assert the boto3 task is generated correctly",
Expand Down Expand Up @@ -322,8 +330,12 @@ def test_for_ssm_parameters_for_spoke_execution_mode_where_param_is_set_in_hub(
"param_name": f"/sleeper/SleeperFunctionArn/{region}/stacks",
"section_name": constants.SSM_PARAMETERS,
"task_reference": expected_ssm_parameter_task_ref,
"dependencies_by_reference": [],
"dependencies": task.get("dependencies"),
"dependencies_by_reference": [
"create-policies",
"prepare-account-for-stacks-spoke_account_id",
"get-template-from-s3-stacks-depsrefactor",
],
"dependencies": [],
},
all_tasks[expected_ssm_parameter_task_ref],
"assert the boto3 task is generated correctly",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.229.0',
'version': '0.230.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',
Expand Down

0 comments on commit 3fc45e5

Please sign in to comment.