Skip to content

Commit

Permalink
feat: Setting Guidance has no affect (#332) (#333)
Browse files Browse the repository at this point in the history
* feat: Setting Guidance has no affect (#332)
* feat: Terminating a product version does not delete the provisioning artefact (#334)
  • Loading branch information
eamonnfaherty authored Mar 13, 2023
1 parent 458a035 commit 6653387
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 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-factory"
version = "0.99.0"
version = "0.100.0"
description = "Making it easier to build 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
1 change: 1 addition & 0 deletions servicecatalog_factory/commands/task_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ def generate_tasks_for_product(
section_name=section_names.ENSURE_PRODUCT_VERSION_DETAILS_CORRECT_TASK,
region=region,
version=version,
status=version.get("Status", constants.STATUS_ACTIVE),
create_product_task_ref=create_product_task_ref,
dependencies_by_reference=[create_product_task_ref],
)
Expand Down
24 changes: 10 additions & 14 deletions servicecatalog_factory/workflow/dependencies/task_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,17 @@ def create(
)

elif section_name == section_names.ENSURE_PRODUCT_VERSION_DETAILS_CORRECT_TASK:
if status == "terminated":
raise Exception("NOT BUILT YET")
else:
from servicecatalog_factory.workflow.portfolios import (
ensure_product_version_details_correct_task,
)
from servicecatalog_factory.workflow.portfolios import (
ensure_product_version_details_correct_task,
)

return ensure_product_version_details_correct_task.EnsureProductVersionDetailsCorrectTask(
**minimum_common_parameters,
region=parameters_to_use.get("region"),
version=parameters_to_use.get("version"),
create_product_task_ref=parameters_to_use.get(
"create_product_task_ref"
),
)
return ensure_product_version_details_correct_task.EnsureProductVersionDetailsCorrectTask(
**minimum_common_parameters,
region=parameters_to_use.get("region"),
status=parameters_to_use.get("status"),
version=parameters_to_use.get("version"),
create_product_task_ref=parameters_to_use.get("create_product_task_ref"),
)

elif section_name == section_names.CREATE_CODE_REPO_TASK:
if status == "terminated":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

import luigi

from servicecatalog_factory import constants
from servicecatalog_factory.workflow.tasks import FactoryTask, logger


class EnsureProductVersionDetailsCorrectTask(FactoryTask):
status = luigi.Parameter()
region = luigi.Parameter()
version = luigi.DictParameter()
create_product_task_ref = luigi.Parameter()

def params_for_results_display(self):
return {
"region": self.region,
"status": self.status,
"task_reference": self.task_reference,
}

Expand All @@ -24,7 +26,6 @@ def run(self):
product_id = create_product_task_output.get("ProductId")
product_name = create_product_task_output.get("Name")
version_name = self.version.get("Name")
version_active = self.version.get("Active", True)

with self.regional_client("servicecatalog") as service_catalog:
response = service_catalog.list_provisioning_artifacts(ProductId=product_id)
Expand All @@ -35,16 +36,31 @@ def run(self):
logger.info(
f"Found matching: {version_name}: {provisioning_artifact_detail}"
)
if provisioning_artifact_detail.get("Active") != version_active:
logger.info(
f"Active status needs to change for: {product_name} {version_name}"
)
service_catalog.update_provisioning_artifact(
if self.status == constants.STATUS_ACTIVE:
version_active = self.version.get("Active", True)
guidance = self.version.get("Guidance", "DEFAULT").upper()

if (
provisioning_artifact_detail.get("Active") != version_active
or provisioning_artifact_detail.get("Guidance") != guidance
):
logger.info(
f"Active or Guidance status needs to change for: {product_name} {version_name}"
)
service_catalog.update_provisioning_artifact(
ProductId=product_id,
ProvisioningArtifactId=provisioning_artifact_detail.get(
"Id"
),
Active=version_active,
Guidance=guidance,
)
elif self.status == constants.STATUS_TERMINATED:
service_catalog.delete_provisioning_artifact(
ProductId=product_id,
ProvisioningArtifactId=provisioning_artifact_detail.get(
"Id"
),
Active=version_active,
)

self.write_output_raw("{}")
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
# SPDX-License-Identifier: Apache-2.0

from unittest import skip

from servicecatalog_factory import constants
from servicecatalog_factory.workflow import tasks_unit_tests_helper


class EnsureProductVersionDetailsCorrectTest(
tasks_unit_tests_helper.FactoryTaskUnitTest
):

region = "rergion"
version = dict()
region = "region"
create_product_task_ref = "create_product_task_ref"
status = constants.STATUS_ACTIVE

def setUp(self) -> None:
from servicecatalog_factory.workflow.portfolios import (
Expand All @@ -24,6 +27,7 @@ def setUp(self) -> None:
**self.minimal_common_params,
region=self.region,
version=self.version,
status=self.status,
create_product_task_ref=self.create_product_task_ref
)

Expand All @@ -32,7 +36,7 @@ def setUp(self) -> None:
def test_params_for_results_display(self):
# setup
expected_result = {
"region": self.region,
"status": self.status,
"task_reference": self.task_reference,
}

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

setup_kwargs = {
'name': 'aws-service-catalog-factory',
'version': '0.99.0',
'version': '0.100.0',
'description': 'Making it easier to build ServiceCatalog products',
'long_description': '# aws-service-catalog-factory\n\n![logo](./docs/logo.png) \n\n## What is it?\nThis is a python3 framework that makes it easier to build multi region AWS Service Catalog portfolios.\n\nWith this framework you define a portfolio in YAML. For each product version in your portfolio you specify which git \nrepository it is in and the framework will build out AWS CodePipelines for each product version.\n\nThese CodePipelines can run CFN_NAG and Cloudformation_rspec on your templates enabling you to check your templates are \ngood quality that they are functionally correct.\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/20-service-catalog-factory.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-factory.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-puppet](https://github.com/awslabs/aws-service-catalog-puppet).\nWith Service Catalog Puppet you can provision products into multiple regions of multiple accounts using YAML and you can \nshare portfolios across multiple regions of multiple accounts. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit 6653387

Please sign in to comment.