Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Description: >
This stack provisions the required resources for a per-branch strigo app.
The main idea here is that it creates host-header based listener rules which direct specific
hosts (e.g. test.app-dev.strigo.io) to a specific ALB Target Group behind which is the
instance containing the branch's code.
See http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-listenerrule.html
Parameters:
Branch:
Description: The name of the branch to build for
Type: String
ConstraintDescription: 'Must not be longer than 255'
MaxLength: 255
AMI:
Description: AMI ID to use for the Instance
Type: String
Default: ami-1f83aa79
HttpListenerArn:
Description: The HTTP Listener arn in which the host-based rule should be set.
Type: String
Default: arn:aws:elasticloadbalancing:...
HttpsListenerArn:
Description: The HTTPS Listener arn in which the host-based rule should be set.
Type: String
Default: arn:aws:elasticloadbalancing...
LoadBalancerPriority:
Description: 'The priority for the rule. Elastic Load Balancing evaluates rules in priority order, from the lowest value to the highest value. If a request satisfies a rule, Elastic Load Balancing ignores all subsequent rules. A target group can have only one rule with a given priority.'
Type: Number
Default: 1
ConstraintDescription: 'Must be in the range [1-99999]'
MinValue: 1
MaxValue: 99999
Resources:
LoadBalancerTargetGroup:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Port: 2545
Protocol: HTTP
VpcId: vpc-xxxxxxxx
Targets:
- Id: !Ref Instance
LoadBalancerHttpListenerRule:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref LoadBalancerTargetGroup
Conditions:
- Field: host-header
Values:
- !Join [ '.', [ !Ref Branch, 'app-dev.strigo.io' ] ]
ListenerArn: !Ref HttpListenerArn
Priority: !Ref LoadBalancerPriority
LoadBalancerHttpsListenerRule:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref LoadBalancerTargetGroup
Conditions:
- Field: host-header
Values:
- !Join [ '.', [ !Ref Branch, 'app-dev.strigo.io' ] ]
ListenerArn: !Ref HttpsListenerArn
Priority: !Ref LoadBalancerPriority
Instance:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: eu-west-1a
ImageId: !Ref AMI
InstanceType: t2.medium
KeyName: strigo
SecurityGroupIds:
- sg-xxxxxxxx
- !Ref InstanceSecurityGroup
SubnetId: subnet-xxxxxxxx
Tags:
- Key: Name
Value: !Join [ '.', [ 'strigo-app-dev', !Ref Branch ] ]
- Key: Type
Value: strigo-app-dev
- Key: Index
Value: 0
InstanceSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
VpcId: vpc-xxxxxxxx
GroupDescription: !Join [ ' ', [ 'Development instance security group for', !Ref Branch ] ]
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2545
ToPort: 2545
SourceSecurityGroupId: sg-081c3871
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment