elastic_beans 0.12.0 → 0.13.0.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d4b47cf9b50e2f09ca6e4aa744106b035655a6c
4
- data.tar.gz: 3878b0ff68a6b2d1aa67370d5dffc84e5a0091bc
3
+ metadata.gz: 104398081411188937dfc9c983fcde0cc98de988
4
+ data.tar.gz: ecce5ec7acf41af00e8310f05ba1b47f945e2428
5
5
  SHA512:
6
- metadata.gz: 859c5755bce3a7204a2b8226f061a9aa6ec31a00557b2a58404b91a6b8c74083baa85d59f0f97f30f3f17b126ddf5f337da07ea1bfc38b444fc0b15c3dbe3e21
7
- data.tar.gz: 688cd97b6742652ad19c5fae0ae498d263a27559bd697e3dae913ac25f6b1042031cdbc4bf6b6146c2f1d514903af4ac9209f8bf6f0ce4bcd3e9dc143a9f9d0f
6
+ metadata.gz: ece21d2d195d9d0650189a2eef7af0eb2aed66ac0ef05f7392381f9b401dd37588f0dfc6d34e1e42f402cba0d24893027ddecfb1b6492e3fc4d272a1cef76859
7
+ data.tar.gz: 70984a0532380942a69d23aca621f9664b3144986e5c21cba1c1777de128fc5bdfebf8885027ce9452dc3906cfe8b81f6804ea8e5dc096daf92bf268dd23c6c0
data/README.md CHANGED
@@ -24,8 +24,8 @@ As the SDK documentation suggests, using environment variables is recommended.
24
24
 
25
25
  # Pre-configure the application before creating environments
26
26
  beans configure -n myapp-networking -a myapp \
27
- -p INTERNAL_PUBLIC_KEY -s SSL_CERTIFICATE_ARN \
28
- -k KEYPAIR [-i IMAGE_ID] [-t INSTANCE_TYPE]
27
+ -p INTERNAL_PUBLIC_KEY -s SSL_CERTIFICATE_ARN -k KEYPAIR \
28
+ [-o 'OPTION_SETTING_NAMESPACE/OPTION_NAME=VALUE'...]
29
29
  beans setenv -a myapp \
30
30
  DATABASE_URL=mysql2://db.example.com:3306/myapp \
31
31
  SECRET_KEY_BASE=abc123
@@ -65,8 +65,8 @@ As the SDK documentation suggests, using environment variables is recommended.
65
65
 
66
66
  # Update all existing environments and configuration
67
67
  beans configure -n myapp-networking -a myapp \
68
- [-p INTERNAL_PUBLIC_KEY] [-s SSL_CERTIFICATE_ARN] \
69
- [-k KEYPAIR] [-i IMAGE_ID] [-t INSTANCE_TYPE]
68
+ [-p INTERNAL_PUBLIC_KEY] [-s SSL_CERTIFICATE_ARN] [-k KEYPAIR] \
69
+ [-o 'OPTION_SETTING_NAMESPACE/OPTION_NAME=VALUE'...]
70
70
 
71
71
  ### API
72
72
 
@@ -16,21 +16,21 @@ class ElasticBeans::CLI < Thor
16
16
  long_desc ElasticBeans::Command::Configure::LONG_DESC
17
17
  option :application, aliases: %w(-a), required: true, desc: APPLICATION_DESC
18
18
  option :network, aliases: %w(-n), required: true, desc: "The name of the CloudFormation stack that contains networking settings"
19
- option :image_id, aliases: %w(-i), desc: "A custom AMI to use instead of the default Ruby Elastic Beanstalk AMI"
20
- option :instance_type, aliases: %w(-t), desc: "A default instance type to use for all environments instead of c4.large"
21
19
  option :internal, type: :boolean, desc: "Configure the webserver to only be available for internal VPC access"
22
20
  option :keypair, aliases: %w(-k), desc: "Required on first run. The EC2 keypair to use for Elastic Beanstalk instances"
21
+ option :option_settings, aliases: %w(-o), type: :array, default: [], desc: "Option settings to configure, format is NAMESPACE/OPTION_NAME=VALUE, e.g. aws:ec2:vpc/ELBScheme=internal"
22
+ option :option_settings_to_remove, aliases: %w(-r), type: :array, default: [], desc: "Option settings to remove, format is NAMESPACE/OPTION_NAME, e.g. aws:ec2:vpc/ELBScheme"
23
23
  option :public_key, aliases: %w(-p), desc: "For end-to-end encryption. The public key of the SSL certificate the ELB will verify to communicate with your Rails app"
24
24
  option :ssl_certificate_arn, aliases: %w(-s), desc: "The ARN of the SSL server certificate stored in IAM to attach to the ELB"
25
25
  def configure
26
26
  @verbose = options[:verbose]
27
27
  ElasticBeans::Command::Configure.new(
28
- image_id: options[:image_id],
29
- instance_type: options[:instance_type],
30
28
  internal: options[:internal],
31
29
  keypair: options[:keypair],
32
30
  public_key: options[:public_key],
33
31
  ssl_certificate_arn: options[:ssl_certificate_arn],
32
+ option_settings: options[:option_settings],
33
+ option_settings_to_remove: options[:option_settings_to_remove],
34
34
  application: application(name: options[:application]),
35
35
  network: network(stack_name: options[:network]),
36
36
  elastic_beanstalk: elastic_beanstalk_client,
@@ -16,24 +16,24 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
16
16
  LONG_DESC
17
17
 
18
18
  def initialize(
19
- image_id:,
20
- instance_type:,
21
19
  internal:,
22
20
  keypair:,
23
21
  public_key:,
24
22
  ssl_certificate_arn:,
23
+ option_settings:,
24
+ option_settings_to_remove:,
25
25
  application:,
26
26
  network:,
27
27
  elastic_beanstalk:,
28
28
  iam:,
29
29
  ui:
30
30
  )
31
- @image_id = image_id
32
- @instance_type = instance_type
33
31
  @internal = internal
34
32
  @keypair = keypair
35
33
  @public_key = public_key
36
34
  @ssl_certificate_arn = ssl_certificate_arn
35
+ @option_setting_strings = option_settings
36
+ @option_strings_to_remove = option_settings_to_remove
37
37
  @application = application
38
38
  @network = network
39
39
  @elastic_beanstalk = elastic_beanstalk
@@ -71,9 +71,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
71
71
  )
72
72
  base_config.upsert(
73
73
  network: network,
74
- image_id: image_id,
75
- instance_type: instance_type,
76
74
  keypair: keypair,
75
+ option_settings: option_settings,
76
+ options_to_remove: options_to_remove,
77
77
  iam: iam,
78
78
  )
79
79
  progressbar.increment
@@ -85,10 +85,10 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
85
85
  )
86
86
  webserver_config.upsert(
87
87
  network: network,
88
- image_id: image_id,
89
- instance_type: instance_type,
90
88
  internal: internal,
91
89
  keypair: keypair,
90
+ option_settings: option_settings,
91
+ options_to_remove: options_to_remove,
92
92
  iam: iam,
93
93
  public_key: public_key,
94
94
  ssl_certificate_arn: ssl_certificate_arn,
@@ -109,9 +109,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
109
109
  )
110
110
  exec_config.upsert(
111
111
  network: network,
112
- image_id: image_id,
113
- instance_type: instance_type,
114
112
  keypair: keypair,
113
+ option_settings: option_settings,
114
+ options_to_remove: options_to_remove,
115
115
  iam: iam,
116
116
  )
117
117
  exec_environment = exec_config.environment
@@ -130,9 +130,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
130
130
  )
131
131
  scheduler_config.upsert(
132
132
  network: network,
133
- image_id: image_id,
134
- instance_type: instance_type,
135
133
  keypair: keypair,
134
+ option_settings: option_settings,
135
+ options_to_remove: options_to_remove,
136
136
  iam: iam,
137
137
  )
138
138
  scheduler_environment = scheduler_config.environment
@@ -153,9 +153,9 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
153
153
  )
154
154
  worker_config.upsert(
155
155
  network: network,
156
- image_id: image_id,
157
- instance_type: instance_type,
158
156
  keypair: keypair,
157
+ option_settings: option_settings,
158
+ options_to_remove: options_to_remove,
159
159
  iam: iam,
160
160
  )
161
161
  worker_environment = worker_config.environment
@@ -175,8 +175,6 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
175
175
 
176
176
  attr_reader(
177
177
  :application,
178
- :image_id,
179
- :instance_type,
180
178
  :internal,
181
179
  :keypair,
182
180
  :network,
@@ -186,6 +184,66 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
186
184
  :iam,
187
185
  :ui,
188
186
  )
187
+
188
+ # Coerces +@option_setting_strings+ into object format.
189
+ def option_settings
190
+ @option_settings ||= @option_setting_strings.map { |option_setting_string|
191
+ setting, value = option_setting_string.split('=', 2)
192
+ if !setting || setting.empty? || !value || value.empty?
193
+ raise InvalidOptionSettingFormatError
194
+ end
195
+ namespace, option_name = setting.split('/', 2)
196
+ if !namespace || namespace.empty? || !option_name || option_name.empty?
197
+ raise InvalidOptionSettingFormatError
198
+ end
199
+ {namespace: namespace, option_name: option_name, value: value}
200
+ }
201
+ end
202
+
203
+ # Coerces +@option_strings_to_remove+ into object format.
204
+ def options_to_remove
205
+ @options_to_remove ||= @option_strings_to_remove.map { |option_setting_string|
206
+ namespace, option_name = option_setting_string.split('/', 2)
207
+ if !namespace || namespace.empty? || !option_name || option_name.empty? || option_name.include?('=')
208
+ raise InvalidOptionSettingFormatError
209
+ end
210
+ {namespace: namespace, option_name: option_name}
211
+ }
212
+ end
213
+
214
+ # :nodoc: all
215
+ # @!visibility private
216
+ class InvalidOptionSettingFormatError < ElasticBeans::Error
217
+ def message
218
+ require "elastic_beans/cli"
219
+ require "elastic_beans/cli/string_shell"
220
+ <<-MESSAGE
221
+ Invalid format for --option-settings.
222
+ Option settings should in the format 'NAMESPACE/OPTION_NAME=VALUE', e.g. 'aws:autoscaling:asg/Cooldown=180'.
223
+ If you'd like to *remove* option settings, use --option-settings-to-remove 'NAMESPACE/OPTION_NAME'.
224
+ Please re-run `#{command_as_string "configure"}` with updated syntax.
225
+
226
+ #{command_help "configure"}
227
+ MESSAGE
228
+ end
229
+ end
230
+
231
+ # :nodoc: all
232
+ # @!visibility private
233
+ class InvalidOptionSettingsToRemoveFormatError < ElasticBeans::Error
234
+ def message
235
+ require "elastic_beans/cli"
236
+ require "elastic_beans/cli/string_shell"
237
+ <<-MESSAGE
238
+ Invalid format for --option-settings-to-remove.
239
+ Option settings to remove should in the format 'NAMESPACE/OPTION_NAME', e.g. 'aws:autoscaling:asg/Cooldown'.
240
+ If you'd like to *set* option settings, use --option-settings 'NAMESPACE/OPTION_NAME=VALUE'.
241
+ Please re-run `#{command_as_string "configure"}` with updated syntax.
242
+
243
+ #{command_help "configure"}
244
+ MESSAGE
245
+ end
246
+ end
189
247
  end
190
248
  end
191
249
  end
@@ -1,4 +1,5 @@
1
1
  require "ruby-progressbar"
2
+ require "elastic_beans/error"
2
3
  require "elastic_beans/error/environments_not_ready"
3
4
 
4
5
  module ElasticBeans
@@ -75,10 +76,23 @@ Requires AWS credentials to be set in the environment, i.e. AWS_ACCESS_KEY_ID an
75
76
  def pairs_as_hash(pairs)
76
77
  pairs.reduce({}) { |acc, pair|
77
78
  key, value = pair.split('=', 2)
79
+ raise MissingValueError.new(key: key) if value.nil?
78
80
  acc[key] = value
79
81
  acc
80
82
  }
81
83
  end
84
+
85
+ class MissingValueError < ElasticBeans::Error
86
+ def initialize(key:)
87
+ @key = key
88
+ end
89
+
90
+ def message
91
+ "Missing value for key '#{@key}'. " \
92
+ "Should it be part of the previous value? " \
93
+ "You may need to quote the key/value pair (e.g. 'MYVAR=myvalue, myvalue2') or escape a space (e.g. 'MYVAR=myvalue,\\ myvalue2')."
94
+ end
95
+ end
82
96
  end
83
97
  end
84
98
  end
@@ -18,20 +18,19 @@ module ElasticBeans
18
18
  network: nil,
19
19
  keypair: nil,
20
20
  iam: nil,
21
- image_id: nil,
22
- instance_type: nil,
23
21
  min_size: nil,
24
22
  max_size: nil,
23
+ option_settings: [],
25
24
  **_
26
25
  )
27
26
  template = configuration_settings_description("base")
28
27
 
29
- instance_profile_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam))
28
+ instance_profile_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "IamInstanceProfile", override: instance_profile(iam), new_settings: option_settings)
30
29
  if instance_profile_setting[:value].nil?
31
30
  raise MissingInstanceProfileError
32
31
  end
33
32
 
34
- keypair_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair)
33
+ keypair_setting = template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "EC2KeyName", override: keypair, new_settings: option_settings)
35
34
  if keypair_setting[:value].nil?
36
35
  raise MissingOptionsError.new(
37
36
  keypair: keypair_setting[:value],
@@ -39,32 +38,31 @@ module ElasticBeans
39
38
  end
40
39
 
41
40
  config_path = "#{application.bucket_name}/#{application.env_vars.s3_key}"
42
- settings = [
43
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1"),
44
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed"),
45
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling"),
46
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true"),
47
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path),
48
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role"),
49
- template_option_setting(template: template, namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced"),
50
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false"),
51
- template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size),
52
- template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size),
53
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "InstanceType", default: "c4.large", override: instance_type),
54
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32"),
55
- template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health"),
56
- template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true"),
57
- template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network)),
58
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network)),
59
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network)),
60
- template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network)),
41
+ super + [
42
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSize", default: "1", new_settings: option_settings),
43
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "BatchSizeType", default: "Fixed", new_settings: option_settings),
44
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:command", option_name: "DeploymentPolicy", default: "Rolling", new_settings: option_settings),
45
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", default: "true", new_settings: option_settings),
46
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_ENV_VARS", default: config_path, new_settings: option_settings),
47
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:environment", option_name: "ServiceRole", default: "aws-elasticbeanstalk-service-role", new_settings: option_settings),
48
+ template_option_setting(template: template, namespace: "aws:elasticbeanstalk:healthreporting:system", option_name: "SystemType", default: "enhanced", new_settings: option_settings),
49
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "AssociatePublicIpAddress", default: "false", new_settings: option_settings),
50
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MinSize", default: "1", override: min_size, new_settings: option_settings),
51
+ template_option_setting(template: template, namespace: "aws:autoscaling:asg", option_name: "MaxSize", default: "4", override: max_size, new_settings: option_settings),
52
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SSHSourceRestriction", default: "tcp, 22, 22, 0.0.0.0/32", new_settings: option_settings),
53
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateType", default: "Health", new_settings: option_settings),
54
+ template_option_setting(template: template, namespace: "aws:autoscaling:updatepolicy:rollingupdate", option_name: "RollingUpdateEnabled", default: "true", new_settings: option_settings),
55
+ template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "SecurityGroups", override: security_groups(network), new_settings: option_settings),
56
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "ELBSubnets", override: elb_subnets(network), new_settings: option_settings),
57
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "Subnets", override: subnets(network), new_settings: option_settings),
58
+ template_option_setting(template: template, namespace: "aws:ec2:vpc", option_name: "VPCId", override: vpc_id(network), new_settings: option_settings),
61
59
  instance_profile_setting,
62
60
  keypair_setting,
63
61
  ]
64
- if image_id
65
- settings << template_option_setting(template: template, namespace: "aws:autoscaling:launchconfiguration", option_name: "ImageId", override: image_id)
66
- end
67
- settings
62
+ end
63
+
64
+ def source_configuration
65
+ nil
68
66
  end
69
67
 
70
68
  private
@@ -12,14 +12,18 @@ module ElasticBeans
12
12
  protected
13
13
 
14
14
  # Constructs the configuration for the exec environment.
15
- def build_option_settings(**_)
15
+ def build_option_settings(option_settings: [], **_)
16
16
  super + [
17
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
18
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
19
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_EXEC_QUEUE_URL", override: application.exec_queue_url),
20
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
17
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
18
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
19
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "ELASTIC_BEANS_EXEC_QUEUE_URL", override: application.exec_queue_url, new_settings: option_settings),
20
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
21
21
  ]
22
22
  end
23
+
24
+ def source_configuration
25
+ SOURCE_CONFIGURATION
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -11,13 +11,17 @@ module ElasticBeans
11
11
 
12
12
  # Constructs the configuration for the scheduler environment.
13
13
  # No special options here!
14
- def build_option_settings(**_)
14
+ def build_option_settings(option_settings: [], **_)
15
15
  super + [
16
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
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_MIGRATIONS", default: "true"),
16
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
17
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
18
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
19
19
  ]
20
20
  end
21
+
22
+ def source_configuration
23
+ SOURCE_CONFIGURATION
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -13,35 +13,35 @@ module ElasticBeans
13
13
 
14
14
  # Constructs the configuration for the webserver environment.
15
15
  # All arguments are required on first run.
16
- def build_option_settings(network: nil, public_key: nil, ssl_certificate_arn: nil, internal: nil, **_)
17
- public_key_policy_names_setting = template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "PublicKeyPolicyNames", default: "backendkey")
18
- public_key_setting = template_option_setting(namespace: "aws:elb:policies:#{public_key_policy_names_setting[:value]}", option_name: "PublicKey", override: public_key)
19
- ssl_certificate_setting = template_option_setting(namespace: "aws:elb:listener:443", option_name: "SSLCertificateId", override: ssl_certificate_arn)
16
+ def build_option_settings(network: nil, public_key: nil, ssl_certificate_arn: nil, internal: nil, option_settings: [], **_)
17
+ public_key_policy_names_setting = template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "PublicKeyPolicyNames", default: "backendkey", new_settings: option_settings)
18
+ public_key_setting = template_option_setting(namespace: "aws:elb:policies:#{public_key_policy_names_setting[:value]}", option_name: "PublicKey", override: public_key, new_settings: option_settings)
19
+ ssl_certificate_setting = template_option_setting(namespace: "aws:elb:listener:443", option_name: "SSLCertificateId", override: ssl_certificate_arn, new_settings: option_settings)
20
20
  if public_key_setting[:value].nil? || ssl_certificate_setting[:value].nil?
21
21
  raise NoEncryptionSettingsError
22
22
  end
23
23
 
24
- option_settings = [
25
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTPS:443/", allow_blank: false),
26
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "false"),
27
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "false"),
28
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstancePort", default: "443"),
29
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstanceProtocol", default: "HTTPS"),
30
- template_option_setting(namespace: "aws:elb:listener:443", option_name: "ListenerProtocol", default: "HTTPS"),
31
- template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "ManagedSecurityGroup", override: managed_security_group(network)),
32
- template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "SecurityGroups", override: elb_security_groups(network)),
33
- template_option_setting(namespace: "aws:elb:policies", option_name: "ConnectionDrainingEnabled", default: "true"),
34
- template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "InstancePorts", default: "443"),
24
+ settings = [
25
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTPS:443/", allow_blank: false, new_settings: option_settings),
26
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_ASSET_COMPILATION", default: "false", new_settings: option_settings),
27
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "false", new_settings: option_settings),
28
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstancePort", default: "443", new_settings: option_settings),
29
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "InstanceProtocol", default: "HTTPS", new_settings: option_settings),
30
+ template_option_setting(namespace: "aws:elb:listener:443", option_name: "ListenerProtocol", default: "HTTPS", new_settings: option_settings),
31
+ template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "ManagedSecurityGroup", override: managed_security_group(network), new_settings: option_settings),
32
+ template_option_setting(namespace: "aws:elb:loadbalancer", option_name: "SecurityGroups", override: elb_security_groups(network), new_settings: option_settings),
33
+ template_option_setting(namespace: "aws:elb:policies", option_name: "ConnectionDrainingEnabled", default: "true", new_settings: option_settings),
34
+ template_option_setting(namespace: "aws:elb:policies:backendencryption", option_name: "InstancePorts", default: "443", new_settings: option_settings),
35
35
  public_key_policy_names_setting,
36
36
  public_key_setting,
37
37
  ssl_certificate_setting,
38
38
  ]
39
39
  if internal
40
- internal_setting = template_option_setting(namespace: "aws:ec2:vpc", option_name: "ELBScheme", override: "internal")
41
- option_settings << internal_setting
40
+ internal_setting = template_option_setting(namespace: "aws:ec2:vpc", option_name: "ELBScheme", override: "internal", new_settings: option_settings)
41
+ settings << internal_setting
42
42
  end
43
43
 
44
- super + option_settings
44
+ super + settings
45
45
  end
46
46
 
47
47
  # Removes the "internal" ELB scheme if explicitly disabled with --no-internal.
@@ -64,6 +64,10 @@ module ElasticBeans
64
64
  network.elb_security_groups[0] if network
65
65
  end
66
66
 
67
+ def source_configuration
68
+ SOURCE_CONFIGURATION
69
+ end
70
+
67
71
  # :nodoc: all
68
72
  # @!visibility private
69
73
  class NoEncryptionSettingsError < ElasticBeans::Error
@@ -24,17 +24,21 @@ module ElasticBeans
24
24
  # Constructs the configuration for the worker environments.
25
25
  # No special arguments, the +queue+ name is stored from the initializer and is used to look up the appropriate
26
26
  # URL.
27
- def build_option_settings(**_)
27
+ def build_option_settings(option_settings: [], **_)
28
28
  super + [
29
- template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/"),
30
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false"),
31
- template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true"),
32
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "InactivityTimeout", default: "1800"),
33
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "MaxRetries", default: "10"),
34
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "VisibilityTimeout", default: "1800"),
35
- template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "WorkerQueueURL", override: application.worker_queue_url(queue)),
29
+ template_option_setting(namespace: "aws:elasticbeanstalk:application", option_name: "Application Healthcheck URL", default: "HTTP:80/", new_settings: option_settings),
30
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "DISABLE_SQS_CONSUMER", override: "false", new_settings: option_settings),
31
+ template_option_setting(namespace: "aws:elasticbeanstalk:application:environment", option_name: "RAILS_SKIP_MIGRATIONS", default: "true", new_settings: option_settings),
32
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "InactivityTimeout", default: "1800", new_settings: option_settings),
33
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "MaxRetries", default: "10", new_settings: option_settings),
34
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "VisibilityTimeout", default: "1800", new_settings: option_settings),
35
+ template_option_setting(namespace: "aws:elasticbeanstalk:sqsd", option_name: "WorkerQueueURL", override: application.worker_queue_url(queue), new_settings: option_settings),
36
36
  ]
37
37
  end
38
+
39
+ def source_configuration
40
+ SOURCE_CONFIGURATION
41
+ end
38
42
  end
39
43
  end
40
44
  end
@@ -12,6 +12,9 @@ module ElasticBeans
12
12
  class ConfigurationTemplate
13
13
  # The solution stack used for a new application. Should not be hardcoded, but here we are.
14
14
  SOLUTION_STACK_NAME = "64bit Amazon Linux 2016.09 v2.2.0 running Ruby 2.3 (Puma)"
15
+ # The source configuration for new configuration templates.
16
+ # Set to ElasticBeans::ConfigurationTemplate::Base to include all custom configuration that has already been performed.
17
+ SOURCE_CONFIGURATION = {template_name: "base"}
15
18
  # :category: Internal
16
19
  WORKER_TEMPLATE_NAME_PATTERN = /\Aworker-(?<queue>\w+)\z/
17
20
 
@@ -120,6 +123,7 @@ module ElasticBeans
120
123
  application_name: application.name,
121
124
  template_name: name,
122
125
  solution_stack_name: SOLUTION_STACK_NAME,
126
+ source_configuration: source_configuration,
123
127
  option_settings: option_settings,
124
128
  )
125
129
  end
@@ -135,12 +139,17 @@ module ElasticBeans
135
139
  # :category: Internal
136
140
  attr_reader :elastic_beanstalk
137
141
 
138
- def build_option_settings(**_)
139
- []
142
+ # Returns option settings that should be set on the template.
143
+ def build_option_settings(option_settings: [], **_)
144
+ option_settings
140
145
  end
141
146
 
142
- def build_options_to_remove(**_)
143
- []
147
+ # Returns option settings that should be removed from the template.
148
+ # Will not remove settings that beans has defaults for, even if they aren't being changed right now.
149
+ def build_options_to_remove(options_to_remove: [], **_)
150
+ options_to_remove.reject { |setting|
151
+ option_settings.any? { |new_setting| new_setting[:namespace] == setting[:namespace] && new_setting[:option_name] == setting[:option_name] }
152
+ }
144
153
  end
145
154
 
146
155
  def configuration_settings_description(template_name = name)
@@ -181,6 +190,10 @@ module ElasticBeans
181
190
  retry
182
191
  end
183
192
 
193
+ def source_configuration
194
+ SOURCE_CONFIGURATION
195
+ end
196
+
184
197
  def template_option_setting(
185
198
  template: configuration_settings_description,
186
199
  environment: environment_configuration_settings_description,
@@ -188,13 +201,21 @@ module ElasticBeans
188
201
  option_name:,
189
202
  default: nil,
190
203
  override: nil,
191
- allow_blank: true
204
+ allow_blank: true,
205
+ new_settings:
192
206
  )
193
207
  option_setting = {namespace: namespace, option_name: option_name, value: default}
194
208
  if override
195
209
  return option_setting.merge!(value: override)
196
210
  end
197
211
 
212
+ new_setting = new_settings.find { |setting|
213
+ setting[:namespace] == namespace && setting[:option_name] == option_name
214
+ }
215
+ if new_setting
216
+ return new_setting
217
+ end
218
+
198
219
  existing_settings = []
199
220
  if environment
200
221
  # Persist changes made directly to the environment from the AWS console UI
@@ -1,3 +1,3 @@
1
1
  module ElasticBeans
2
- VERSION = "0.12.0"
2
+ VERSION = "0.13.0.alpha1"
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.12.0
4
+ version: 0.13.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stegman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -250,9 +250,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
250
  version: '0'
251
251
  required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  requirements:
253
- - - ">="
253
+ - - ">"
254
254
  - !ruby/object:Gem::Version
255
- version: '0'
255
+ version: 1.3.1
256
256
  requirements: []
257
257
  rubyforge_project:
258
258
  rubygems_version: 2.6.11