Created
June 15, 2019 16:59
-
-
Save sanudatta11/352c04b7ece20d515b5d61b31a3272ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Description: "This is the third CF Template for running Rundeck via UserData with ALB and Autoscale!" | |
Parameters: | |
KeyName: | |
Description: Name of an existing EC2 KeyPair to enable SSH access into the server | |
Type: AWS::EC2::KeyPair::KeyName | |
DatabaseName: | |
Type: String | |
Default: rundeck | |
DatabaseUser: | |
Type: String | |
Default: rundeck | |
DatabasePassword: | |
Type: String | |
Default: rundeck123 | |
NoEcho: true | |
EnvironmentSize: | |
Type: String | |
Default: SMALL | |
AllowedValues: | |
- SMALL | |
- MEDIUM | |
- LARGE | |
Description: Select Environment Size (S,M,L) | |
VpcId: | |
Description: Enter the VpcId | |
Type: AWS::EC2::VPC::Id | |
SubnetIds: | |
Description: Enter the Subnets | |
Type: List<AWS::EC2::Subnet::Id> | |
Mappings: | |
InstanceSize: | |
SMALL: | |
"EC2" : "t2.micro" | |
"DB" : "db.t2.micro" | |
MEDIUM: | |
"EC2" : "t2.small" | |
"DB" : "db.t2.small" | |
LARGE: | |
"EC2" : "t2.medium" | |
"DB" : "db.t2.medium" | |
Resources: | |
DB: | |
Type: "AWS::RDS::DBInstance" | |
Properties: | |
AllocatedStorage: '5' | |
StorageType: gp2 | |
DBInstanceClass: !FindInMap [InstanceSize, !Ref EnvironmentSize, DB] | |
DBName: !Ref DatabaseName | |
Engine: MySQL | |
MasterUsername: !Ref DatabaseUser | |
MasterUserPassword: !Ref DatabasePassword | |
LoadBalancer: # Application Load Balancer | |
Type: AWS::ElasticLoadBalancingV2::LoadBalancer | |
Properties: | |
SecurityGroups: | |
- !Ref ALBSecurityGroup | |
Subnets: !Ref SubnetIds | |
LoadBalancerListener: # Port 80 Listener for ALB | |
Type: AWS::ElasticLoadBalancingV2::Listener | |
Properties: | |
LoadBalancerArn: !Ref LoadBalancer | |
Port: 80 | |
Protocol: TCP | |
DefaultActions: | |
- Type: forward | |
TargetGroupArn: | |
Ref: TargetGroup | |
TargetGroup: | |
Type: AWS::ElasticLoadBalancingV2::TargetGroup | |
Properties: | |
Port: 4440 | |
Protocol: TCP | |
VpcId: !Ref VpcId | |
AutoScalingGroup: | |
Type: AWS::AutoScaling::AutoScalingGroup | |
Properties: | |
AvailabilityZones: !GetAZs | |
LaunchConfigurationName: !Ref LaunchConfiguration | |
MinSize: 1 | |
MaxSize: 3 | |
TargetGroupARNs: | |
- !Ref TargetGroup | |
LaunchConfiguration: | |
Type: AWS::AutoScaling::LaunchConfiguration | |
Properties: | |
ImageId: ami-00e782930f1c3dbc7 | |
InstanceType: !FindInMap [InstanceSize, !Ref EnvironmentSize, EC2] | |
KeyName: !Ref KeyName | |
UserData: | |
"Fn::Base64": | |
!Sub | | |
#!/bin/bash | |
yum -y install java-1.8.0 | |
rpm -Uvh tcps://repo.rundeck.org/latest.rpm | |
yum -y install rundeck | |
service rundeckd start | |
sed -i "s/localhost/${LoadBalancer.DNSName}/g" /etc/rundeck/rundeck-config.properties | |
yum upgrade rundeck rundeck-config | |
service rundeckd restart | |
service rundeckd start | |
SecurityGroups: | |
- !Ref EC2SecurityGroup | |
ALBSecurityGroup: | |
Type: AWS::EC2::SecurityGroup | |
Properties: | |
GroupDescription: ALB Security Group | |
VpcId: !Ref VpcId | |
SecurityGroupIngress: | |
- IpProtocol: tcp | |
FromPort: 80 | |
ToPort: 80 | |
CidrIp: 0.0.0.0/0 | |
EC2SecurityGroup: | |
Type: AWS::EC2::SecurityGroup | |
Properties: | |
GroupDescription: EC2 Instance | |
EC2InboundRule: # EC2 can only accept traffic from ALB | |
Type: AWS::EC2::SecurityGroupIngress | |
Properties: | |
IpProtocol: tcp | |
FromPort: 4440 | |
ToPort: 4440 | |
SourceSecurityGroupId: | |
!GetAtt | |
- ALBSecurityGroup | |
- GroupId | |
GroupId: | |
!GetAtt | |
- EC2SecurityGroup | |
- GroupId | |
Outputs: | |
URL: | |
Description: The Public DNS for the Rundeck EC2 Instance | |
Value: !Sub 'http://${LoadBalancer.DNSName}/' | |
DBEndpoint: | |
Description: The DB Endpoint for the RDS | |
Value: !Sub 'http://${DB.Endpoint.Address}/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment