Skip to content

Commit

Permalink
Issue/54.1 (#56)
Browse files Browse the repository at this point in the history
Changing parameters now forces an update on the provisioned product.
  • Loading branch information
eamonnfaherty committed May 29, 2019
1 parent bc66cdf commit f0a9094
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
78 changes: 47 additions & 31 deletions servicecatalog_puppet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ def deploy_stream(streams_name, streams, parameters, puppet_account_id, deployme
thread.join()


def is_launch_deployed_to_account_and_region_already(service_catalog, launch, provisioning_artifact_id, product_id):
def terminate_if_need_to(service_catalog, launch, provisioning_artifact_id, product_id):
logger.info('is launch: {} deployed'.format(launch.get('launch_name')))

provisioned_product_id = False
response = service_catalog.search_provisioned_products(
Filters={'SearchQuery': [
"productId:{}".format(product_id)
Expand All @@ -320,11 +320,7 @@ def is_launch_deployed_to_account_and_region_already(service_catalog, launch, pr
for r in response.get('ProvisionedProducts', []):
if r.get('Name') == launch.get('launch_name'):
if r.get('Status') == "AVAILABLE":
logger.info("Product and version has been provisioned already")
if r.get('ProvisioningArtifactId') == provisioning_artifact_id:
return True
else:
return False
provisioned_product_id = r.get('Id')
else:
logger.info("Product and version needs terminating: {}".format(r.get('Status')))
service_catalog.terminate_provisioned_product(
Expand All @@ -341,7 +337,8 @@ def is_launch_deployed_to_account_and_region_already(service_catalog, launch, pr
time.sleep(5)
else:
break
return False

return provisioned_product_id


def deploy_launch_to_account_and_region(
Expand Down Expand Up @@ -543,30 +540,49 @@ def process_stream(stream_name, stream, parameters, puppet_account_id, deploymen
provisioned_product_name = template_properties.get('ProvisionedProductName')
launch_name = launch.get('launch_name')

if not is_launch_deployed_to_account_and_region_already(
service_catalog,
launch,
provisioning_artifact_id,
product_id,
):
logger.info('Getting path for product')
response = service_catalog.list_launch_paths(ProductId=product_id)
if len(response.get('LaunchPathSummaries')) != 1:
raise Exception("Found unexpected amount of LaunchPathSummaries")
path_id = response.get('LaunchPathSummaries')[0].get('Id')
logger.info('Got path for product')

params = generate_params(
account,
deployment_map,
launch_name,
parameters,
path_id,
product_id,
provisioning_artifact_id,
service_catalog
)
provisioned_product_id = terminate_if_need_to(service_catalog, launch, provisioning_artifact_id, product_id)

logger.info('Getting path for product')
response = service_catalog.list_launch_paths(ProductId=product_id)
if len(response.get('LaunchPathSummaries')) != 1:
raise Exception("Found unexpected amount of LaunchPathSummaries")
path_id = response.get('LaunchPathSummaries')[0].get('Id')
logger.info('Got path for product')

params = generate_params(
account,
deployment_map,
launch_name,
parameters,
path_id,
product_id,
provisioning_artifact_id,
service_catalog
)

should_deploy = True

if provisioned_product_id:
# [{'Key': 'Path', 'Value': '/human-roles/'}, {'Key': 'RoleName', 'Value': 'DevOps'}]
with betterboto_client.CrossAccountClientContextManager(
'cloudformation', role, f"cfn-{account}-{region}", region_name=region
) as cloudformation:
stack = cloudformation.describe_stacks(
StackName=f"SC-{account}-{provisioned_product_id}"
).get('Stacks')[0]
existing_stack_params_dict = {}
for stack_param in stack.get('Parameters'):
existing_stack_params_dict[stack_param.get('ParameterKey')] = stack_param.get('ParameterValue')

new_stack_params_dict = {}
for existing_param in params:
new_stack_params_dict[existing_param.get('Key')] = existing_param.get('Value')

if new_stack_params_dict == existing_stack_params_dict:
logger.info("Skipping deploy as parameters are the same")
should_deploy = False

if should_deploy:
deploy_launch_to_account_and_region(
service_catalog,
launch,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="aws-service-catalog-puppet",
version="0.0.43",
version="0.0.44",
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 f0a9094

Please sign in to comment.