forked from brettswift/cumulus
/
alb_port.py
31 lines (22 loc) · 846 Bytes
/
alb_port.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from troposphere import (
Ref, ec2, Join)
from cumulus.chain import step
from cumulus.steps.ec2 import META_SECURITY_GROUP_REF
class AlbPort(step.Step):
def __init__(self,
port_to_open,
alb_sg_name):
step.Step.__init__(self)
self.port_to_open = port_to_open
self.alb_sg_name = alb_sg_name
def handle(self, chain_context):
template = chain_context.template
name = '%sElbToASGPort%s' % (chain_context.instance_name, self.port_to_open)
template.add_resource(ec2.SecurityGroupIngress(
name,
IpProtocol="tcp",
FromPort=self.port_to_open,
ToPort=self.port_to_open,
SourceSecurityGroupId=Ref(self.alb_sg_name),
GroupId=chain_context.metadata[META_SECURITY_GROUP_REF]
))