Skip to content

Commit

Permalink
- Implemented SQLServerExpress RDS
Browse files Browse the repository at this point in the history
- Implemented SSM Agent Update using SSM Document for Windows
- Added redirect_path to IListenerRules
- Implemented VPC Endpoints in network.vpc for ssm, ssmmessages, and ec2messages.
  • Loading branch information
gitwater committed Jun 3, 2021
1 parent 0f6352f commit d30907b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 151 deletions.
2 changes: 1 addition & 1 deletion src/paco/application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from paco.application.reseng_lambda import LambdaResourceEngine
from paco.application.reseng_lb import LBApplicationResourceEngine, LBNetworkResourceEngine
from paco.application.reseng_rds import RDSMysqlResourceEngine, RDSMysqlAuroraResourceEngine, RDSPostgresqlResourceEngine, \
RDSPostgresqlAuroraResourceEngine, DBParameterGroupResourceEngine, DBClusterParameterGroupResourceEngine
RDSPostgresqlAuroraResourceEngine, DBParameterGroupResourceEngine, DBClusterParameterGroupResourceEngine, RDSSQLServerExpressResourceEngine
from paco.application.reseng_snstopic import SNSTopicResourceEngine
from paco.application.reseng_s3bucket import S3BucketResourceEngine
from paco.application.reseng_eip import EIPResourceEngine
Expand Down
30 changes: 28 additions & 2 deletions src/paco/application/reseng_asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from paco.core.yaml import YAML
from paco.models.references import get_model_obj_from_ref
from paco.stack import StackHooks
from paco.utils import md5sum
from paco.utils import md5sum, prefixed_name
from paco.aws_api.ecs.capacityprovider import ECSCapacityProviderClient
import paco.cftemplates
import paco.models
Expand Down Expand Up @@ -114,13 +114,24 @@ def init_resource(self):
)
if self.resource.instance_ami_type.startswith("windows") == False:
self.stack.hooks.add(
name='UpdateExistingInstances.' + self.resource.name,
name='EC2LMUpdateInstances.' + self.resource.name,
stack_action='update',
stack_timing='pre',
hook_method=self.app_engine.ec2_launch_manager.ec2lm_update_instances_hook,
cache_method=self.app_engine.ec2_launch_manager.ec2lm_update_instances_cache,
hook_arg=(bucket.paco_ref_parts, self.resource)
)
else:
# TODO: Make this work with Linux too
self.stack.hooks.add(
name='UpdateSSMAgent.' + self.resource.name,
stack_action=['create', 'update'],
stack_timing='post',
hook_method=self.asg_hook_update_ssm_agent,
cache_method=None,
hook_arg=self.resource
)

# For ECS ASGs add an ECS Hook
if self.resource.ecs != None and self.resource.is_enabled() == True:
self.stack.hooks.add(
Expand All @@ -138,6 +149,21 @@ def get_ec2lm_cache_id(self, hook, hook_arg):
"EC2LM cache id"
return self.ec2lm_cache_id

def asg_hook_update_ssm_agent(self, hook, asg):
ssm_client = self.account_ctx.get_aws_client('ssm', aws_region=self.aws_region)
ssm_log_group_name = prefixed_name(asg, 'paco_ssm', self.paco_ctx.legacy_flag)
response = ssm_client.send_command(
Targets=[{
'Key': 'tag:aws:cloudformation:stack-name',
'Values': [asg.stack.get_name()]
},],
CloudWatchOutputConfig={
'CloudWatchLogGroupName': ssm_log_group_name,
'CloudWatchOutputEnabled': True,
},
DocumentName='AWS-UpdateSSMAgent',
)

def provision_ecs_capacity_provider_cache(self, hook, asg):
"Cache method for ECS ASG"
cp = asg.ecs.capacity_provider
Expand Down
9 changes: 9 additions & 0 deletions src/paco/application/reseng_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def init_resource(self):
stack_tags=self.stack_tags,
)

class RDSSQLServerExpressResourceEngine(ResourceEngine):
def init_resource(self):
self.stack_group.add_new_stack(
self.aws_region,
self.resource,
paco.cftemplates.RDS,
stack_tags=self.stack_tags,
)

class RDSMysqlAuroraResourceEngine(ResourceEngine):
def init_resource(self):
self.stack_group.add_new_stack(
Expand Down
25 changes: 12 additions & 13 deletions src/paco/cftemplates/lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,29 +301,28 @@ def init_lb(self, aws_name, template_title):
continue
logical_rule_name = self.create_cfn_logical_id(rule_name)
cfn_export_dict = {}
field = None
rule_values = None
rule_conditions = []
if rule.rule_type == "forward":
logical_target_group_id = self.create_cfn_logical_id('TargetGroup' + rule.target_group)
cfn_export_dict['Actions'] = [
{'Type': 'forward', 'TargetGroupArn': troposphere.Ref(logical_target_group_id) }
]
if rule.host != None:
field = 'host-header'
rule_values = [rule.host]
elif len(rule.path_pattern) > 0:
field = 'path-pattern'
rule_values = rule.path_pattern
rule_conditions.append({'Field': 'host-header', 'Values': [rule.host]})
if len(rule.path_pattern) > 0:
rule_conditions.append({'Field': 'path-pattern', 'Values': rule.path_pattern})
elif rule.rule_type == "redirect":
redirect_config = {'Type': 'redirect', 'RedirectConfig': {'Host': rule.redirect_host, 'StatusCode': 'HTTP_301'} }
if rule.redirect_path != None:
redirect_config['RedirectConfig']['Path'] = rule.redirect_path
cfn_export_dict['Actions'] = [
{'Type': 'redirect', 'RedirectConfig': {'Host': rule.redirect_host, 'StatusCode': 'HTTP_301'} }
redirect_config
]
field = 'host-header'
rule_values = [rule.host]
rule_conditions.append({'Field': 'host-header', 'Values': [rule.host]})
if len(rule.path_pattern) > 0:
rule_conditions.append({'Field': 'path-pattern', 'Values': rule.path_pattern})

cfn_export_dict['Conditions'] = [
{'Field': field, 'Values': rule_values }
]
cfn_export_dict['Conditions'] = rule_conditions

cfn_export_dict['ListenerArn'] = troposphere.Ref(logical_listener_name)
cfn_export_dict['Priority'] = rule.priority
Expand Down

0 comments on commit d30907b

Please sign in to comment.