aws-rds 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: b1cc2d54119dcd95b2c9fb03197051035846442c9ca4e7436203076a112b1686
4
- data.tar.gz: c64db50775c8374124698dd728927d1334e7fa372b153bfc067e6fa1b166077f
3
+ metadata.gz: 28ec4b294e4916cb3a60b0635b8b7af526639ac9b05949b5d4e53637840409d0
4
+ data.tar.gz: acaa3428a63f54e84078c1615b934a416e92e0161961d84e58684ee3d4c65eb1
5
5
  SHA512:
6
- metadata.gz: cffc7a7f694829c749e2bee6aac07b8961d5a5041b5287d4c7d8fd50d76e950f8fa01527487ccf9f9b55d7bf47676d6594d1e7b952d4b1703b245b8fced4399a
7
- data.tar.gz: fe1240c028f158d1a7e4d479edd3c4c8c5b4c19d1108449ef21b5f09526d258f542244574ee149168e8780a345ef1d2ca9c0ea23136970a6acf0075ffae9dacd
6
+ metadata.gz: 516dc4b01e868ba041c9d56eeaea5fdde322f00a79b29529afe378f83eff09980614b5017a0dfcddb55b2e90f0c7119aee6ef79a191054bcade5b7c787371d6f
7
+ data.tar.gz: be2fac1b8f4cbd8e1bceed188a7d7257fc56ed5a4300064c6a4385034b1113416a5eda544aae6bceb4d8af6a3eac1af4c93c7bcc2bcd477ac437d7a6f676414c
@@ -3,6 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.4.0]
7
+ - security-group-name option to create a security group if not specified in profile with vpc_security_group_ids
8
+
6
9
  ## [0.3.0]
7
10
  - dont auto create security group when specified in the profile
8
11
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws-rds (0.1.2)
4
+ aws-rds (0.3.0)
5
5
  activesupport
6
6
  aws-sdk-ec2
7
7
  aws-sdk-rds
File without changes
@@ -0,0 +1,20 @@
1
+ ---
2
+ # main vpc_id and db_subnet_group_name are set here.
3
+ # This could be the AWS default vpc or a custom VPC.
4
+ main:
5
+ # vpc_id is used by the --security-group-name option.
6
+ # The --security-group-name option tells aws-rds to use the existing security group
7
+ # with the specified name. Or it will create it under the vpc_id if it does
8
+ # not yet exist. You can override this in the profile files.
9
+ vpc_id: vpc-111 # custom main vpc, can also override and profile
10
+ # db_subnet_group_name used by the create_db_instance command and specifies
11
+ # a list of subnets that the RDS db can be launched in. This db_subnet_group_name
12
+ # needs to belong to the same vpc_id above. You can also override this in the
13
+ # profiles.
14
+ db_subnet_group_name: my-db-subnet-group-name # db subnet group contains private subnets only
15
+
16
+ # config variables to be used in profiles below. Example usage:
17
+ #
18
+ # <%= config["vpc_security_group_ids"].inspect %> in your profile file
19
+ vpc_security_group_ids:
20
+ - sg-111
@@ -0,0 +1,10 @@
1
+ ---
2
+ allocated_storage: 20
3
+ db_instance_class: db.t2.micro
4
+ master_user_password: changeme
5
+ master_username: changeme
6
+ engine: postgres
7
+ vpc_security_group_ids: <%= config["vpc_security_group_ids"].inspect %>
8
+ # db_name: mydb # can be overridden at the cli
9
+ # vpc_security_group_ids: # can be also automatically set by specifying --security-group-name at the CLI
10
+ # db_instance_identifier: not respected here. always set from the cli
@@ -1,4 +1,5 @@
1
1
  ---
2
+ db_name: demo
2
3
  allocated_storage: 20
3
4
  db_instance_class: db.t2.micro
4
5
  master_user_password: changeme
@@ -9,8 +9,7 @@ module AwsRds
9
9
  option :db_name, desc: "database name"
10
10
  option :db_user, desc: "database user"
11
11
  option :db_password, desc: "database password"
12
- option :security_group, type: :boolean, default: true, desc: "use separate security group"
13
- option :security_group_name, desc: "optional. security group name"
12
+ option :security_group_name, desc: "security group to create if not vpc_security_group_ids not set in profile"
14
13
  def create(name)
15
14
  Create.new(options.merge(name: name)).run
16
15
  end
@@ -23,11 +23,15 @@ class AwsRds::Create
23
23
  end
24
24
 
25
25
  def set_security_groups(params)
26
- return params unless @options[:security_group]
27
26
  return params if @options[:noop]
28
-
29
- # return early and dont auto-create SG if user has set one
30
- return params if params['vpc_security_group_ids']
27
+ # dont create SG if user has set one
28
+ # db_security_groups: classic RDS db security groups, separtae groups from
29
+ # from ec2 security groups.
30
+ # vpc_security_group_ids: vpc security groups. same groups as what the ec2
31
+ # security groups use.
32
+ # db_security_groups is not really recommended anymore because it is the
33
+ # EC2-classic network.
34
+ return params if params['vpc_security_group_ids'] || params['db_security_groups']
31
35
 
32
36
  security_group_name = @options[:security_group_name] || @options[:name]
33
37
  sg = AwsRds::SecurityGroup.find_or_create(security_group_name)
@@ -36,8 +40,26 @@ class AwsRds::Create
36
40
  end
37
41
 
38
42
  def set_db_subnet_group(params)
39
- params["db_subnet_group_name"] ||= AwsRds.config["db_subnet_group_name"]
43
+ params["db_subnet_group_name"] ||= main_db_subnet_group_name
40
44
  params
41
45
  end
46
+
47
+ def main_db_subnet_group_name
48
+ AwsRds.config["defaults"]["db_subnet_group_name"]
49
+ rescue NoMethodError => e
50
+ puts e.message
51
+ puts <<-EOL
52
+ No db_subnet_group_name was specified in your profile. Also, a default db subnet group name was set.
53
+
54
+ Please add a db_subnet_group_name in your profile file or add a default db_subnet_group_name to your config/#{AwsRds.env}.yml.
55
+
56
+ To specify a default db_subnet_group_name setting. Example config/#{AwsRds.env}.yml:
57
+
58
+ ---
59
+ defaults:
60
+ db_subnet_group_name: my-db-subnet-group
61
+ EOL
62
+ exit 1
63
+ end
42
64
  end
43
65
  end
@@ -1,13 +1,19 @@
1
- The create command creates an RDS database with a profile file with some pre-configured settings. The profile file is in the profiles folder. If a profile is not specified, it will only use the `profiles/default.yml` profile.
1
+ The create command creates an RDS database with pre-configured settings from a profile file. If a profile is not specified, it will use the `profiles/default.yml` profile.
2
2
 
3
3
  Examples:
4
4
 
5
- aws-rds create my-db --profile my-db
5
+ aws-rds create mydb --profile mydb # uses profiles/mydb.yml
6
6
 
7
7
  Security Groups:
8
8
 
9
- By default, instead of using the default security group, a new security group is created and associated with the database.
9
+ It is recommended that you configure an explicit security group in your profiles so that the RDS DB does not use the default security group. Using an explicit security group allows you to control access to the DB in a finely tuned manner.
10
10
 
11
- This security group's name is the same as database name by convention. This can be overridden at with `--security-group-name`. If the security group already exists, it will use the existing security group that matches the name.
11
+ If you do not have an existing security groups and want would like aws-rds to create a security group for you, use the --security-group-name option:
12
12
 
13
- If you do not want to specify the security group name every time, you can configure the security group id in the profile file by setting vpc_security_group_ids.
13
+ aws-rds create mydb --profile mydb --security-group-name mydbsg
14
+
15
+ When using the `--security-group-name` option, you need to set the vpc_id and db_subnet_group_group variables in your config/ENV.yml settings file. Example config/development.yml:
16
+
17
+ ---
18
+ vpc_id: vpc-123
19
+ db_subnet_group_group: my-db-subnet-group
@@ -6,7 +6,7 @@ module AwsRds
6
6
  def find_or_create(name)
7
7
  resp = ec2.describe_security_groups(
8
8
  filters: [
9
- {name: 'vpc-id', values: [AwsRds.config["vpc_id"]]},
9
+ {name: 'vpc-id', values: [main_vpc_id]},
10
10
  {name: 'group-name', values: [name]}]
11
11
  )
12
12
  sg = resp.security_groups.first
@@ -16,7 +16,7 @@ module AwsRds
16
16
  result = ec2.create_security_group(
17
17
  group_name: name,
18
18
  description: name,
19
- vpc_id: AwsRds.config["vpc_id"],
19
+ vpc_id: main_vpc_id,
20
20
  )
21
21
  # TODO: add waiter
22
22
  # ec2.create_tags(
@@ -27,6 +27,22 @@ module AwsRds
27
27
  resp.security_groups.first
28
28
  end
29
29
 
30
+ def main_vpc_id
31
+ AwsRds.config["defaults"]["vpc_id"]
32
+ rescue NoMethodError => e
33
+ puts e.message
34
+ puts <<-EOL
35
+ Unable to load a default vpc id from your config/#{AwsRds.env}.yml.
36
+ Please specify a default vpc_id setting.
37
+
38
+ Example config/#{AwsRds.env}.yml:
39
+ ---
40
+ defaults:
41
+ vpc_id: vpc-123
42
+ EOL
43
+ exit 1
44
+ end
45
+
30
46
  def self.find_or_create(name)
31
47
  new.find_or_create(name)
32
48
  end
@@ -1,3 +1,3 @@
1
1
  module AwsRds
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-rds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -169,10 +169,10 @@ files:
169
169
  - README.md
170
170
  - Rakefile
171
171
  - aws-rds.gemspec
172
- - example/README.md
173
- - example/config/development.yml
174
- - example/profiles/default.yml
175
- - example/profiles/mydb.yml
172
+ - docs/example/README.md
173
+ - docs/example/config/development.yml
174
+ - docs/example/profiles/default.yml
175
+ - docs/example/profiles/mydb.yml
176
176
  - exe/aws-rds
177
177
  - lib/aws-rds.rb
178
178
  - lib/aws_rds/aws_services.rb
@@ -1,3 +0,0 @@
1
- ---
2
- vpc_id: vpc-123 # custom main vpc, use this when not specified in profile
3
- db_subnet_group_name: private-db-subnet-group # private subnet group
@@ -1 +0,0 @@
1
- db_name: demo