Class: BeanstalkTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/gantree/cfn/beanstalk.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ BeanstalkTemplate

Returns a new instance of BeanstalkTemplate.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/gantree/cfn/beanstalk.rb', line 3

def initialize params
  @stack_name = params[:stack_name]
  @docker_version = params[:solution] 
  @size = params[:instance_size]
  @rds = params[:rds]
  @env = params[:env]
  @domain = params[:domain]
  @requirements = params[:requirements]
  @rds_enabled = params[:rds?]
  @env_type = params[:env_type]
end

Instance Method Details

#beanstalk_parmatersObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gantree/cfn/beanstalk.rb', line 42

def beanstalk_parmaters
  "parameter 'KeyName',
              :Description => 'The Key Pair to launch instances with',
              :Type => 'String',
              :Default => 'default'

    parameter 'InstanceSecurityGroup',
              :Type => 'String'

    parameter 'InstanceType',
              :Description => 'EC2 Instance Type',
              :Type => 'String',
              :Default => '#{@size}'

    parameter 'ApplicationName',
              :Description => 'The name of the Elastic Beanstalk Application',
              :Type => 'String',
              :Default =>  '#{@stack_name}'

    parameter 'Environment',
              :Type => 'String',
              :Default => '#{@env_type}'

    parameter 'IamInstanceProfile',
              :Type => 'String',
              :Default => 'EbApp'

    #{"parameter 'RDSHostURLPass', :Type => 'String'" if @rds_enabled }"

end

#configuration_templateObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gantree/cfn/beanstalk.rb', line 73

def configuration_template
  "resource 'ConfigurationTemplate', :Type => 'AWS::ElasticBeanstalk::ConfigurationTemplate', :Properties => {
      :ApplicationName => ref('Application'),
      :SolutionStackName => '#{@docker_version}',
      :Description => 'Default Configuration Version #{@docker_version} - with SSH access',
      :OptionSettings => [
          {
              :Namespace => 'aws:elasticbeanstalk:application:environment',
              :OptionName => 'AWS_REGION',
              :Value => aws_region,
          },
          {
              :Namespace => 'aws:autoscaling:launchconfiguration',
              :OptionName => 'EC2KeyName',
              :Value => ref('KeyName'),
          },
          {
              :Namespace => 'aws:autoscaling:launchconfiguration',
              :OptionName => 'IamInstanceProfile',
              :Value => ref('IamInstanceProfile'),
          },
          {
              :Namespace => 'aws:autoscaling:launchconfiguration',
              :OptionName => 'InstanceType',
              :Value => ref('InstanceType'),
          },
          {
              :Namespace => 'aws:autoscaling:launchconfiguration',
              :OptionName => 'SecurityGroups',
              :Value => join(',', join('-', '#{@env_type}', 'br'), ref('InstanceSecurityGroup')),
          },
          { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'RollingUpdateEnabled', :Value => 'true' },
          { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MaxBatchSize', :Value => '1' },
          { :Namespace => 'aws:autoscaling:updatepolicy:rollingupdate', :OptionName => 'MinInstancesInService', :Value => '2' },
          { :Namespace => 'aws:elasticbeanstalk:hostmanager', :OptionName => 'LogPublicationControl', :Value => 'true' },
          #{set_rds_parameters if @rds_enabled }
      ],
  }"
end

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gantree/cfn/beanstalk.rb', line 15

def create
  "#{@requirements}
  template do

    value :AWSTemplateFormatVersion => '2010-09-09'

    value :Description => '#{@stack_name} Service Parent Template (2014-08-15)'

    #{beanstalk_parmaters}

    resource 'Application', :Type => 'AWS::ElasticBeanstalk::Application', :Properties => {
        :Description => '#{@stack_name}',
        :ApplicationName => '#{@stack_name}',
    }

    #{configuration_template}

    #{resources}

    output 'URL',
           :Description => 'URL of the AWS Elastic Beanstalk Environment',
           :Value => join('', 'http://', get_att('EbEnvironment', 'EndpointURL'))

  end.exec!
  "
end

#resourcesObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/gantree/cfn/beanstalk.rb', line 113

def resources
  "resource 'EbEnvironment', :Type => 'AWS::ElasticBeanstalk::Environment', :Properties => {
      :ApplicationName => '#{@stack_name}',
      :EnvironmentName => '#{@env}',
      :Description => 'Default Environment',
      :TemplateName => ref('ConfigurationTemplate'),
      :OptionSettings => [],
  }

  resource 'HostRecord', :Type => 'AWS::Route53::RecordSet', :Properties => {
      :Comment => 'DNS name for my stack',
      :HostedZoneName => '#{@domain}',
      :Name => join('.', '#{@stack_name}', '#{@domain}'),
      :ResourceRecords => [ get_att('EbEnvironment', 'EndpointURL') ],
      :TTL => '60',
      :Type => 'CNAME',
  }"
end

#set_rds_parametersObject



131
132
133
134
135
136
137
# File 'lib/gantree/cfn/beanstalk.rb', line 131

def set_rds_parameters
  "{
    :Namespace => 'aws:elasticbeanstalk:application:environment',
    :OptionName => 'DB_HostURL',
    :Value => ref('RDSHostURLPass'),
  },"
end