elastic_beans 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df2c92db9341aafe114e311aa9513e262980075b
4
- data.tar.gz: e0d1656e123cc87594923df2a454692c6a5f24cb
3
+ metadata.gz: 10462aa38d3834422bab9795d785bcc62918f1a9
4
+ data.tar.gz: 976eab44cd9ef0562106c9438df39fb3936ffc28
5
5
  SHA512:
6
- metadata.gz: c71f8da1510349c373e03fa299d6106bd7b932168cfd166c797f21311442b5e34431bc817ef39063f1969d1f22b56b8865ed919a9de7968ef1190e8bebe86003
7
- data.tar.gz: 2834984b88ad858571e1f01681c5b2bc41d388635c096a84bff9bdf3ba380551dbf00b7bc00072029c98f137911704f985c285ddb4eaf169311a2293c5826769
6
+ metadata.gz: 88a3f198fd40582742329016941ea9c672b45dc7e0ef548e9c5c2766c1bbf735ad4dbccb74cce15efd6eb338cfe9cc21cf56900eb38ff957fb9edd208a4bb89d
7
+ data.tar.gz: ab100cd37d28544b0e1d1b853e3d0fca05ac922ac77fffe00d48ba831a98e5d06eb420bcd9bff914d251c8b744ee466fd50aee2fd43e1724a565cfdc7994ee0b
data/README.md CHANGED
@@ -149,6 +149,9 @@ Elastic Beans stores your configuration in configuration templates.
149
149
  This means that you can terminate and create an environment and it will remember its setup from before.
150
150
  In addition, changes to the configuration will affect existing and future environments.
151
151
 
152
+ In other words, changes made using beans are permanent and can be applied to all current and future environments.
153
+ Changes made in the Elastic Beanstalk web console only last until the environment is terminated and cannot affect other environments.
154
+
152
155
  ### Shared code between environments
153
156
 
154
157
  A Rails app supports multiple contexts with the same codebase.
@@ -222,10 +225,6 @@ Elastic Beans still has some rough edges that need to be worked out.
222
225
 
223
226
  Use the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables to authenticate with the AWS SDK.
224
227
 
225
- #### Changes to the configuration in the AWS console are not persistent
226
-
227
- Changing configuration in the AWS console will work fine, but if the setting is also saved in a configuration template it will be overwritten the next time you run `beans configure`.
228
-
229
228
  #### Creating multiple environments simultaneously causes sample application to be deployed
230
229
 
231
230
  Due to a bug in the version-finding code, creating multiple environments simultaneously can cause a sample application to be deployed to one of them (an empty version label).
@@ -236,10 +235,6 @@ Currently (pre-1.0), you must set up HTTPS yourself in nginx using an ebextensio
236
235
  Use whatever certificate you like to do so, even a self-signed certificate is fine.
237
236
  Use the public key from this certificate as the `--public-key` option to `beans configure`.
238
237
 
239
- #### Environment variables are mostly hidden
240
-
241
- `beans setenv` sets environment variables in S3, but there's no way to *get* them.
242
-
243
238
  #### Environment variables are not access-controlled
244
239
 
245
240
  Environment variables are stored in plain-text in S3.
@@ -52,6 +52,8 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
52
52
  raise EnvironmentsNotReady.new(environments: unready_environments)
53
53
  end
54
54
 
55
+ threads = []
56
+
55
57
  config_templates = 4 + application.worker_queues.size
56
58
  progressbar = ProgressBar.create(title: "Configuring", total: config_templates, output: ui.stdout)
57
59
  progressbar.log("Updating configuration templates in #{application.name}...")
@@ -70,6 +72,7 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
70
72
  iam: iam,
71
73
  )
72
74
  progressbar.increment
75
+
73
76
  progressbar.log("Updating webserver configuration template...")
74
77
  webserver_config = ElasticBeans::ConfigurationTemplate::Webserver.new(
75
78
  application: application,
@@ -86,7 +89,15 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
86
89
  public_key: public_key,
87
90
  ssl_certificate_arn: ssl_certificate_arn,
88
91
  )
92
+ webserver_environment = webserver_config.environment
93
+ if webserver_environment
94
+ progressbar.log("Updating `#{webserver_environment.name}'...")
95
+ threads << Thread.new do
96
+ webserver_environment.update_configuration(webserver_config)
97
+ end
98
+ end
89
99
  progressbar.increment
100
+
90
101
  progressbar.log("Updating exec configuration template...")
91
102
  exec_config = ElasticBeans::ConfigurationTemplate::Exec.new(
92
103
  application: application,
@@ -102,7 +113,15 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
102
113
  iam: iam,
103
114
  logging_endpoint: logging_endpoint,
104
115
  )
116
+ exec_environment = exec_config.environment
117
+ if exec_environment
118
+ progressbar.log("Updating `#{exec_environment.name}'...")
119
+ threads << Thread.new do
120
+ exec_environment.update_configuration(exec_config)
121
+ end
122
+ end
105
123
  progressbar.increment
124
+
106
125
  progressbar.log("Updating scheduler configuration template...")
107
126
  scheduler_config = ElasticBeans::ConfigurationTemplate::Scheduler.new(
108
127
  application: application,
@@ -117,7 +136,15 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
117
136
  keypair: keypair,
118
137
  iam: iam,
119
138
  )
139
+ scheduler_environment = scheduler_config.environment
140
+ if scheduler_environment
141
+ progressbar.log("Updating `#{scheduler_environment.name}'...")
142
+ threads << Thread.new do
143
+ scheduler_environment.update_configuration(scheduler_config)
144
+ end
145
+ end
120
146
  progressbar.increment
147
+
121
148
  application.worker_queues.each do |queue|
122
149
  progressbar.log("Updating worker-#{queue} configuration template...")
123
150
  worker_config = ElasticBeans::ConfigurationTemplate::Worker.new(
@@ -134,32 +161,17 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
134
161
  keypair: keypair,
135
162
  iam: iam,
136
163
  )
137
- progressbar.increment
138
- end
139
- progressbar.finish
140
-
141
- if environments.any?
142
- progressbar = ProgressBar.create(title: "Updating", total: nil, output: ui.stdout)
143
- threads = environments.map { |environment|
144
- progressbar.log("Updating `#{environment.name}'...")
145
- thread = Thread.new do
146
- environment.update_configuration
147
- end
148
- progressbar.increment
149
- thread
150
- }
151
-
152
- loop do
153
- sleep 0.5
154
- progressbar.increment
155
- if threads.none?(&:alive?)
156
- progressbar.total = progressbar.progress
157
- break
164
+ worker_environment = worker_config.environment
165
+ if worker_environment
166
+ progressbar.log("Updating `#{worker_environment.name}'...")
167
+ threads << Thread.new do
168
+ worker_environment.update_configuration(worker_config)
158
169
  end
159
170
  end
160
-
161
- threads.each(&:join)
162
171
  end
172
+ threads.each(&:join)
173
+ progressbar.increment
174
+ progressbar.finish
163
175
  end
164
176
 
165
177
  private
@@ -33,9 +33,7 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
33
33
  progressbar = ProgressBar.create(title: "Updating", total: nil, output: ui.stdout)
34
34
 
35
35
  progressbar.log("Updating configuration in #{application.name}...")
36
- threads << Thread.new do
37
- application.env_vars.update(env_vars)
38
- end
36
+ application.env_vars.update(env_vars)
39
37
  progressbar.increment
40
38
 
41
39
  threads += environments.map { |environment|
@@ -4,38 +4,12 @@ module ElasticBeans
4
4
  class ConfigurationTemplate
5
5
  # The "base" configuration template stored in the Elastic Beanstalk application.
6
6
  # Common settings are stored here, such as networking settings and environment variables.
7
- # Used as a "source configuration" when creating other configuration templates, so that new templates share the
8
- # existing configuration.
7
+ # Other configuration templates inherit from this one, so they all share this configuration.
9
8
  class Base < ElasticBeans::ConfigurationTemplate
10
- # The solution stack used for a new application. Should not be hardcoded, but here we are.
11
- SOLUTION_STACK_NAME = "64bit Amazon Linux 2016.09 v2.2.0 running Ruby 2.3 (Puma)"
12
-
13
9
  def initialize(**args)
14
10
  super(name: "base", **args)
15
11
  end
16
12
 
17
- # Overrides ElasticBeans::ConfigurationTemplate#upsert to add the solution stack to the base configuration.
18
- def upsert(**args)
19
- @option_settings = build_option_settings(**args)
20
- if configuration_settings_description
21
- elastic_beanstalk.update_configuration_template(
22
- application_name: application.name,
23
- template_name: name,
24
- option_settings: option_settings,
25
- )
26
- else
27
- elastic_beanstalk.create_configuration_template(
28
- application_name: application.name,
29
- template_name: name,
30
- solution_stack_name: SOLUTION_STACK_NAME,
31
- option_settings: option_settings,
32
- )
33
- end
34
- rescue ::Aws::ElasticBeanstalk::Errors::Throttling
35
- sleep 5
36
- retry
37
- end
38
-
39
13
  protected
40
14
 
41
15
  # Constructs the common configuration for all environments.
@@ -52,14 +26,16 @@ module ElasticBeans
52
26
  max_size: nil,
53
27
  **_
54
28
  )
55
- instance_profile_setting = template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam))
29
+ template = configuration_settings_description("base")
30
+
31
+ instance_profile_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam))
56
32
  if instance_profile_setting[:value].nil?
57
33
  raise MissingInstanceProfileError
58
34
  end
59
35
 
60
- keypair_setting = template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair)
61
- database_url_setting = template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DATABASE_URL", override: database_url)
62
- secret_key_base_setting = template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "SECRET_KEY_BASE", override: secret_key_base)
36
+ keypair_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair)
37
+ database_url_setting = template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DATABASE_URL", override: database_url)
38
+ secret_key_base_setting = template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "SECRET_KEY_BASE", override: secret_key_base)
63
39
  if database_url_setting[:value].nil? || secret_key_base_setting[:value].nil? || keypair_setting[:value].nil?
64
40
  raise MissingOptionsError.new(
65
41
  database_url: database_url_setting[:value],
@@ -70,31 +46,31 @@ module ElasticBeans
70
46
 
71
47
  config_path = "#{application.bucket_name}/#{application.env_vars.s3_key}"
72
48
  settings = [
73
- template_option_setting(namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1"),
74
- template_option_setting(namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed"),
75
- template_option_setting(namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling"),
76
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true"),
77
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path),
78
- template_option_setting(namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role"),
79
- template_option_setting(namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced"),
80
- template_option_setting(namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false"),
81
- template_option_setting(namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size),
82
- template_option_setting(namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size),
83
- template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "InstanceType", default: "c4.large", override: instance_type),
84
- template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32"),
85
- template_option_setting(namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health"),
86
- template_option_setting(namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true"),
87
- template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network)),
88
- template_option_setting(namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network)),
89
- template_option_setting(namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network)),
90
- template_option_setting(namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network)),
49
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1"),
50
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed"),
51
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling"),
52
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true"),
53
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path),
54
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role"),
55
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced"),
56
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false"),
57
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size),
58
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size),
59
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "InstanceType", default: "c4.large", override: instance_type),
60
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32"),
61
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health"),
62
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true"),
63
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network)),
64
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network)),
65
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network)),
66
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network)),
91
67
  instance_profile_setting,
92
68
  keypair_setting,
93
69
  database_url_setting,
94
70
  secret_key_base_setting,
95
71
  ]
96
72
  if image_id
97
- settings << template_option_setting(namespace: "aws:autoscaling:launchconfiguration", option_name: "ImageId", override: image_id)
73
+ settings << template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "ImageId", override: image_id)
98
74
  end
99
75
  settings
100
76
  end
@@ -31,7 +31,6 @@ module ElasticBeans
31
31
  template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
32
32
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
33
33
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_EXEC_QUEUE_URL", override: application.exec_queue_url),
34
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "true"),
35
34
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
36
35
  ]
37
36
  if logging_endpoint
@@ -15,7 +15,6 @@ module ElasticBeans
15
15
  super + [
16
16
  template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
17
17
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
18
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "true"),
19
18
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
20
19
  ]
21
20
  end
@@ -11,6 +11,14 @@ module ElasticBeans
11
11
  super(name: "worker-#{queue}", **args)
12
12
  end
13
13
 
14
+ # Fetches the running worker environment using the same queue from the application.
15
+ def environment
16
+ if defined? @environment
17
+ return @environment
18
+ end
19
+ @environment = application.environments.find { |environment| environment.is_a?(Environment::Worker) && environment.queue == queue }
20
+ end
21
+
14
22
  protected
15
23
 
16
24
  # Constructs the configuration for the worker environments.
@@ -20,7 +28,6 @@ module ElasticBeans
20
28
  super + [
21
29
  template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
22
30
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
23
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "true"),
24
31
  template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
25
32
  template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "InactivityTimeout", default: "1800"),
26
33
  template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "MaxRetries", default: "10"),
@@ -10,6 +10,8 @@ module ElasticBeans
10
10
  # This is an abstract class; use the provided factories in this class or use a subclass (contained within this
11
11
  # namespace) directly.
12
12
  class ConfigurationTemplate
13
+ # The solution stack used for a new application. Should not be hardcoded, but here we are.
14
+ SOLUTION_STACK_NAME = "64bit Amazon Linux 2016.09 v2.2.0 running Ruby 2.3 (Puma)"
13
15
  # :category: Internal
14
16
  WORKER_TEMPLATE_NAME_PATTERN = /\Aworker-(?<queue>\w+)\z/
15
17
 
@@ -70,12 +72,26 @@ module ElasticBeans
70
72
  @elastic_beanstalk = elastic_beanstalk
71
73
  end
72
74
 
73
- # :category: Internal
75
+ # Fetches the running environment from the application.
76
+ def environment
77
+ if defined? @environment
78
+ return @environment
79
+ end
80
+
81
+ environment_type = self.class.name.split("::").last
82
+ if Environment.constants.none? { |name| name.to_s == environment_type }
83
+ return @environment = nil
84
+ end
85
+
86
+ environment_class = Environment.const_get(environment_type)
87
+ @environment = application.environments.find { |environment| environment.is_a?(environment_class) }
88
+ end
89
+
90
+ # Returns option settings built in #upsert, or fetches their current values from Elastic Beanstalk if #upsert has not been called.
74
91
  def option_settings
75
92
  # do not fetch option settings from Elastic Beanstalk, because those cannot be naively used.
76
93
  # the set built in #build_option_settings is what we care about.
77
- return @option_settings if @option_settings
78
- raise MissingConfigurationError
94
+ @option_settings ||= build_option_settings
79
95
  end
80
96
 
81
97
  # Create or update the configuration template in Elastic Beanstalk.
@@ -93,7 +109,7 @@ module ElasticBeans
93
109
  elastic_beanstalk.create_configuration_template(
94
110
  application_name: application.name,
95
111
  template_name: name,
96
- source_configuration: {application_name: application.name, template_name: "base"},
112
+ solution_stack_name: SOLUTION_STACK_NAME,
97
113
  option_settings: option_settings,
98
114
  )
99
115
  end
@@ -113,43 +129,79 @@ module ElasticBeans
113
129
  []
114
130
  end
115
131
 
116
- def configuration_settings_description
117
- @configuration_template ||= elastic_beanstalk.describe_configuration_settings(
132
+ def configuration_settings_description(template_name = name)
133
+ @configuration_templates ||= {}
134
+ return @configuration_templates[template_name] if @configuration_templates[template_name]
135
+
136
+ @configuration_templates[template_name] = elastic_beanstalk.describe_configuration_settings(
118
137
  application_name: application.name,
119
- template_name: name,
138
+ template_name: template_name,
120
139
  ).configuration_settings[0]
121
140
  rescue ::Aws::ElasticBeanstalk::Errors::InvalidParameterValue => e
122
141
  if e.message =~ /\bconfiguration template\b/i
123
142
  return nil
124
143
  end
125
144
  raise MissingConfigurationError.new(cause: e)
145
+ rescue ::Aws::ElasticBeanstalk::Errors::Throttling
146
+ sleep 5
147
+ retry
148
+ end
149
+
150
+ # Fetches configuration settings from the environment created from this configuration template.
151
+ # This is to look for differences in the running environment from the saved configuration.
152
+ def environment_configuration_settings_description
153
+ if defined? @environment_configuration
154
+ return @environment_configuration
155
+ end
156
+
157
+ if environment.nil?
158
+ return @environment_configuration = nil
159
+ end
160
+
161
+ @environment_configuration = elastic_beanstalk.describe_configuration_settings(
162
+ application_name: application.name,
163
+ environment_name: environment.name,
164
+ ).configuration_settings[0]
165
+ rescue ::Aws::ElasticBeanstalk::Errors::Throttling
166
+ sleep 5
167
+ retry
126
168
  end
127
169
 
128
- def template_option_setting(template: configuration_settings_description, namespace:, option_name:, default: nil, override: nil, allow_blank: true)
170
+ def template_option_setting(
171
+ template: configuration_settings_description,
172
+ environment: environment_configuration_settings_description,
173
+ namespace:,
174
+ option_name:,
175
+ default: nil,
176
+ override: nil,
177
+ allow_blank: true
178
+ )
129
179
  option_setting = {namespace: namespace, option_name: option_name, value: default}
130
180
  if override
131
181
  return option_setting.merge!(value: override)
132
182
  end
133
183
 
134
- if template.nil?
135
- return option_setting
184
+ existing_settings = []
185
+ if environment
186
+ # Persist changes made directly to the environment from the AWS console UI
187
+ existing_settings = environment.to_h[:option_settings]
188
+ elsif template
189
+ # Maintain settings that are already persisted
190
+ existing_settings = template.to_h[:option_settings]
136
191
  end
137
-
138
- setting = template.to_h[:option_settings].find { |setting|
192
+ existing_setting = existing_settings.find { |setting|
139
193
  setting[:namespace] == namespace && setting[:option_name] == option_name
140
194
  }
141
-
142
- if setting.nil?
143
- return option_setting
144
- end
145
-
146
- # So, here's the thing. AWS might return NULL on items that actually DO have a value set, in which case,
147
- # we should tell beans NOT to use this erroneous NULL value, and to use our specified default value.
148
- if !allow_blank && (setting[:value].nil? || setting[:value].empty?)
149
- return option_setting
195
+ if existing_setting
196
+ # So, here's the thing. AWS might return NULL on items that actually DO have a value set, in which case,
197
+ # we should tell beans NOT to use this erroneous NULL value, and to use our specified default value.
198
+ if (existing_setting[:value] && !existing_setting[:value].empty?) || allow_blank
199
+ return option_setting.merge!(value: existing_setting[:value])
200
+ end
150
201
  end
151
202
 
152
- option_setting.merge!(value: setting[:value])
203
+ # Use the default value when no other setting takes precedence
204
+ option_setting
153
205
  end
154
206
 
155
207
  # :nodoc: all
@@ -180,16 +180,15 @@ module ElasticBeans
180
180
  retry
181
181
  end
182
182
 
183
- # Updates the environment configuration with its configuration template.
183
+ # Updates the environment configuration with the option settings from the given configuration template.
184
184
  # Handy when the configuration template has been updated and you want those changes to take effect immediately.
185
185
  # Blocks until the environment is Ready.
186
186
  #
187
187
  # Raises an error if the environment is not healthy.
188
- def update_configuration
188
+ def update_configuration(configuration_template)
189
189
  elastic_beanstalk.update_environment(
190
190
  environment_name: name,
191
- template_name: template_name,
192
- tier: {name: tier_name, type: tier_type},
191
+ option_settings: configuration_template.option_settings,
193
192
  )
194
193
  wait_environment(wait_status: "Updating", wait_health_status: "Info")
195
194
  rescue ::Aws::ElasticBeanstalk::Errors::InvalidParameterValue
@@ -1,3 +1,3 @@
1
1
  module ElasticBeans
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_beans
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stegman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk