Skip to content

Commit

Permalink
Provisioning changes to stacks and products did not cause updates to …
Browse files Browse the repository at this point in the history
…SSM outputs issue #719
  • Loading branch information
eamonnfaherty committed Aug 12, 2024
1 parent 9f577af commit 01f773d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 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.248.0"
version = "0.249.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
12 changes: 7 additions & 5 deletions servicecatalog_puppet/workflow/launch/provision_product_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ProvisionProductTask(tasks.TaskWithParameters):

section_name = constants.LAUNCHES
cachable_level = constants.CACHE_LEVEL_RUN
need_to_provision = False

@property
def item_name(self):
Expand All @@ -55,6 +56,7 @@ def params_for_results_display(self):
"launch_name": self.launch_name,
"account_id": self.account_id,
"region": self.region,
"need_to_provision": self.need_to_provision,
}

@property
Expand Down Expand Up @@ -116,7 +118,7 @@ def run(self):
provisioned_product_detail, service_catalog
)

need_to_provision = True
self.need_to_provision = True

if provisioning_artifact_id == version_id:
self.info(f"found previous good provision")
Expand All @@ -136,15 +138,15 @@ def run(self):

if provisioned_parameters == params_to_use:
self.info(f"params unchanged")
need_to_provision = False
self.need_to_provision = False
else:
self.info(f"params changed")
else:
need_to_provision = True
self.need_to_provision = True

task_output["provisioned"] = need_to_provision
task_output["provisioned"] = self.need_to_provision
task_output["section_name"] = self.section_name
if need_to_provision:
if self.need_to_provision:
self.info(
f"about to provision with params: {json.dumps(servicecatalog_puppet.serialisation_utils.unwrap(params_to_use))}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_params_for_results_display(self):
"launch_name": self.launch_name,
"account_id": self.account_id,
"region": self.region,
"need_to_provision": False,
}

# exercise
Expand Down
11 changes: 10 additions & 1 deletion servicecatalog_puppet/workflow/ssm/ssm_outputs_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SSMOutputsTasks(tasks.TaskWithReference):
force_operation = luigi.BoolParameter()
cachable_level = constants.CACHE_LEVEL_RUN

updated = False

def params_for_results_display(self):
return {
"task_reference": self.task_reference,
Expand All @@ -33,6 +35,7 @@ def params_for_results_display(self):
"param_name": self.param_name,
"stack_output": self.stack_output,
"force_operation": self.force_operation,
"updated": self.updated,
}

@property
Expand Down Expand Up @@ -128,10 +131,15 @@ def get_ssm_parameter(self):

def run(self):
existing_parameter = None

provisioned = self.get_attribute_from_output_from_reference_dependency(
"provisioned", self.task_generating_output
)

if not self.force_operation:
existing_parameter = self.get_ssm_parameter()
parameter_details = "Parameter not updated - stack/launch did not change and there was no force_operation"
if self.force_operation or existing_parameter is None:
if provisioned or self.force_operation or existing_parameter is None:
if self.task_generating_output_section_name == constants.STACKS:
stack_output_value = self.find_stack_output()
elif self.task_generating_output_section_name == constants.LAUNCHES:
Expand All @@ -148,6 +156,7 @@ def run(self):
Type="String",
Overwrite=True,
)
self.updated = True
else:
stack_output_value = existing_parameter.get("Value")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_params_for_results_display(self):
"param_name": self.param_name,
"stack_output": self.stack_output,
"force_operation": self.force_operation,
"updated": False,
}

# exercise
Expand Down
15 changes: 9 additions & 6 deletions servicecatalog_puppet/workflow/stack/provision_stack_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class ProvisionStackTask(tasks.TaskWithParameters):
section_name = constants.STACKS
cachable_level = constants.CACHE_LEVEL_TASK

need_to_provision = False

@property
def item_name(self):
return self.stack_name
Expand All @@ -72,6 +74,7 @@ def params_for_results_display(self):
"stack_name": self.stack_name,
"account_id": self.account_id,
"region": self.region,
"need_to_provision": self.need_to_provision,
}

@property
Expand Down Expand Up @@ -249,23 +252,23 @@ def run(self):
)

if status in ["UPDATE_ROLLBACK_COMPLETE", "NoStack"]:
need_to_provision = True
self.need_to_provision = True
else:
if existing_stack_params_dict == params_to_use:
self.info(f"params unchanged")
if cfn_tools.dump_yaml(template_to_provision) == cfn_tools.dump_yaml(
existing_template_from_cloudformation
):
self.info(f"template the same")
need_to_provision = False
self.need_to_provision = False
else:
self.info(f"template changed")
need_to_provision = True
self.need_to_provision = True
else:
self.info(f"params changed")
need_to_provision = True
self.need_to_provision = True

if need_to_provision:
if self.need_to_provision:
provisioning_parameters = []
for p in params_to_use.keys():
provisioning_parameters.append(
Expand All @@ -289,6 +292,6 @@ def run(self):
]
cloudformation.create_or_update(**a)

task_output["provisioned"] = need_to_provision
task_output["provisioned"] = self.need_to_provision
task_output["section_name"] = self.section_name
self.write_output(task_output)
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_params_for_results_display(self):
"puppet_account_id": self.puppet_account_id,
"stack_name": self.stack_name,
"account_id": self.account_id,
"need_to_provision": False,
"region": self.region,
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.248.0',
'version': '0.249.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 01f773d

Please sign in to comment.