kumogata-template 0.0.32 → 0.0.33

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: 9d33d48dd2211389e7f29644bf76c4980e96c897
4
- data.tar.gz: fb141899507ce1094ef036664d5d32ce964acfce
3
+ metadata.gz: ae8579ef67a536e816f1044e3f6d61d55c2d22b2
4
+ data.tar.gz: a615fd47c3ffc560524002bb655501a0a2fdb6be
5
5
  SHA512:
6
- metadata.gz: 2c3efe00793ebf4640aaa4d59cfdef9be243f8319d5d97bf4655e14d9d9e2a40d224bc1d617320f2d2740a8ef7330296492e8dbc9eba6395fb2a4b9cbbf16b79
7
- data.tar.gz: d189c3ab32d1df96cb7108206fa52c55e6089ee2dde3cecbf2df2d494ba2c9a4fd4635f8b510391f793fb0538beb9d9f13b51dbdb0ec34d0a3fe83fd848dcbf6
6
+ metadata.gz: 15358466f358d1dd05be9d4f72134a5e9bb31cd9f186dd0b817fa3794ecac885c915f16f5f4a85a36e075a8f38c69d5e39e432dc28b9db086aa2bb460a457aca
7
+ data.tar.gz: 70cd674c8a2ed82bfef4300f264cfd5486ba4d887bd0095a0975d579c3a77a17fad34e98eebef86fab7105892ae32c700afe084b49d43b55d4f32c37fc17e0b7
data/Gemfile.lock CHANGED
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kumogata-template (0.0.31)
4
+ kumogata-template (0.0.33)
5
5
  aws-sdk (~> 2.3)
6
6
  kumogata2-plugin-ruby (= 0.1.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws-sdk (2.10.9)
12
- aws-sdk-resources (= 2.10.9)
13
- aws-sdk-core (2.10.9)
11
+ aws-sdk (2.10.47)
12
+ aws-sdk-resources (= 2.10.47)
13
+ aws-sdk-core (2.10.47)
14
14
  aws-sigv4 (~> 1.0)
15
15
  jmespath (~> 1.0)
16
- aws-sdk-resources (2.10.9)
17
- aws-sdk-core (= 2.10.9)
18
- aws-sigv4 (1.0.0)
19
- coderay (1.1.1)
16
+ aws-sdk-resources (2.10.47)
17
+ aws-sdk-core (= 2.10.47)
18
+ aws-sigv4 (1.0.2)
19
+ coderay (1.1.2)
20
20
  diffy (3.2.0)
21
21
  dslh (0.4.8)
22
- hashie (3.5.5)
22
+ hashie (3.5.6)
23
23
  highline (1.7.8)
24
24
  jmespath (1.3.1)
25
- kumogata2 (0.1.12)
25
+ kumogata2 (0.1.15)
26
26
  aws-sdk (>= 2.3.0)
27
27
  coderay
28
28
  diffy
@@ -32,8 +32,8 @@ GEM
32
32
  kumogata2-plugin-ruby (0.1.3)
33
33
  dslh (>= 0.3.7)
34
34
  kumogata2
35
- minitest (5.10.2)
36
- rake (12.0.0)
35
+ minitest (5.10.3)
36
+ rake (12.1.0)
37
37
  term-ansicolor (1.6.0)
38
38
  tins (~> 1.0)
39
39
  tins (1.15.0)
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  rake
49
49
 
50
50
  BUNDLED WITH
51
- 1.15.1
51
+ 1.15.4
@@ -133,11 +133,10 @@ ELASTICACHE_NODE_TYPES =
133
133
  ELASTICACHE_DEFAULT_NODE_TYPE = "cache.t2.medium"
134
134
 
135
135
  # https://aws.amazon.com/rds/pricing/
136
+ # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
136
137
  RDS_INSTANCE_CLASSES =
137
138
  [
138
139
  # Instance Class vCPU ECU Memory (GB) EBS Optimized Network Performance
139
- # db.t1.micro 1 1 .615 No Very Low
140
- # db.m1.small 1 1 1.7 No Very Low
141
140
  # db.m4.large 2 6.5 8 450 Mbps Moderate
142
141
  # db.m4.xlarge 4 13 16 750 Mbps High
143
142
  # db.m4.2xlarge 8 25.5 32 1000 Mbps High
@@ -152,18 +151,17 @@ RDS_INSTANCE_CLASSES =
152
151
  # db.t2.small 1 1 2 No Low
153
152
  # db.t2.medium 2 2 4 No Moderate
154
153
  # db.t2.large 2 2 8 No Moderate
155
- "db.t1.micro",
156
- "db.m1.small", "db.m4.large", "db.m4.xlarge", "db.m4.2xlarge", "db.m4.4xlarge", "db.m4.10xlarge",
154
+ "db.m4.large", "db.m4.xlarge", "db.m4.2xlarge", "db.m4.4xlarge", "db.m4.10xlarge",
157
155
  "db.r3.large", "db.r3.xlarge", "db.r3.2xlarge", "db.r3.4xlarge", "db.r3.8xlarge",
158
- "db.t2.micro", "db.t2.small", "db.t2.medium", "db.t2.large"
156
+ "db.t2.micro", "db.t2.small", "db.t2.medium", "db.t2.large",
159
157
  ]
160
158
  RDS_DEFAULT_INSTANCE_CLASS = "db.t2.medium"
161
159
  RDS_DEFAULT_ENGINE = "mysql"
162
160
  RDS_DEFAULT_ENGINE_VERSION = {
163
161
  mysql: "5.7.17",
164
- mariadb: "10.1.19",
162
+ mariadb: "10.1.23",
165
163
  aurora: "5.6.10a",
166
- postgres: "9.6.2-R1",
164
+ postgres: "9.6.2",
167
165
  }
168
166
 
169
167
  # https://aws.amazon.com/redshift/pricing/
@@ -39,6 +39,14 @@ def _description(name)
39
39
  chomp.slice(0, 1024)
40
40
  end
41
41
 
42
+ def _empty?(value)
43
+ return true if value.nil?
44
+ return false if value.is_a? Integer
45
+ return false if value.is_a? TrueClass or value.is_a? FalseClass
46
+
47
+ value.empty?
48
+ end
49
+
42
50
  def _valid_values(value, values, default = nil)
43
51
  return default if value.nil?
44
52
  values.collect{|v| return v if v =~ /^#{value}$/i }
@@ -1 +1 @@
1
- KUMOGATA_TEMPLATE_VERSION = '0.0.32'
1
+ KUMOGATA_TEMPLATE_VERSION = '0.0.33'
@@ -10,7 +10,7 @@ backup_retention = args[:backup_retention] || 7
10
10
  db_name = _ref_name("database", args, "database")
11
11
  parameter = _ref_string("parameter", args, "db cluster parameter group")
12
12
  parameter = "default.aurora5.6" if parameter.empty?
13
- subnet_group = _ref_string("subnet_group", args, "db subnet group")
13
+ subnet_group = _ref_string("subnet", args, "db subnet group")
14
14
  engine = "aurora"
15
15
  engine_version = RDS_DEFAULT_ENGINE_VERSION[:aurora]
16
16
  user_name = _ref_string("user_name", args, "db master user name")
@@ -5,92 +5,167 @@
5
5
  require 'kumogata/template/helper'
6
6
 
7
7
  name = _resource_name(args[:name], "db instance")
8
- engine = _valid_values(args[:engine],
9
- %w( mysql mariadb
10
- oracle-se1 oracle-se oracle-ee
11
- sqlserver-ee sqlserver-se sqlserver-ex sqlserver-web
12
- postgres aurora ), RDS_DEFAULT_ENGINE)
13
- allocated = args[:allocated] || 5
8
+ allocated = _ref_string_default("allocated", args, "", 5)
14
9
  allow = _bool("allow", args, true)
15
10
  auto = _bool("auto", args, true)
16
11
  az = _availability_zone(args, false)
17
- backup_retention = args[:backup_retention] || 7
18
- character = args[:character] || ""
12
+ backup_retention = _ref_string_default("backup_retention", args, "", 7)
13
+ character = _ref_string_default("character", args)
19
14
  copy_tags =
20
15
  if args.key? :copy_tags
21
16
  _bool("copy_tags", args, true)
22
17
  else
23
18
  ""
24
19
  end
25
- cluster = _ref_string("cluster", args, "db cluster")
26
- instance_class = _ref_string("instance_class", args, "db instance classes")
27
- instance_class = _valid_values(instance_class, RDS_INSTANCE_CLASSES, RDS_DEFAULT_INSTANCE_CLASS) unless instance_class.is_a? Hash
20
+ cluster = _ref_string_default("cluster", args, "db cluster")
21
+ instance_class = _ref_string_default("instance_class", args, "db instance classes", RDS_DEFAULT_INSTANCE_CLASS)
22
+ instance_class = _valid_values(instance_class, RDS_INSTANCE_CLASSES, RDS_DEFAULT_INSTANCE_CLASS) if instance_class.is_a? String
28
23
  instance_id = _ref_name("instance_id", args, "db instance id")
29
24
  db_name = _ref_string("db_name", args, "db name")
25
+ db_name = _ref_string("database", args, "database") if _empty? db_name
30
26
  parameter = _ref_string("parameter", args, "db parameter group")
31
- parameter = "default.mysql5.7" if parameter.empty?
32
- security = _ref_array("security_groups", args, "security group")
33
- subnet_group = _ref_string("subnet_group", args, "db subnet group")
27
+ # TODO support AWS::RDS::DBSecurityGroup
28
+ # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-security-group.html
29
+ db_security_groups = _ref_array("db_security_groups", args, "db security group")
34
30
  snapshot = _ref_string("snapshot", args, "db snapshot")
35
- domain = args[:domain] || ""
36
- domain_iam = args[:domain_iam] || ""
37
- engine_version = _ref_string("engine_version", args, "db engine version")
38
- engine_version = RDS_DEFAULT_ENGINE_VERSION[engine.to_sym] if engine_version.empty?
39
- iops = args[:iops] || ""
31
+ subnet = _ref_string("subnet", args, "db subnet group")
32
+ domain = _ref_string("domain", args, "db domain")
33
+ domain_iam = _ref_string("domain_iam", args, "db domain iam")
34
+ # http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html
35
+ engine = _valid_values(args[:engine],
36
+ %w( aurora mariadb mysql
37
+ oracle-ee oracle-se2 oracle-se1 oracle-se postgres
38
+ sqlserver-ee sqlserver-se sqlserver-ex sqlserver-web ), RDS_DEFAULT_ENGINE)
39
+ engine_version = _ref_string_default("engine_version", args, "db engine version", RDS_DEFAULT_ENGINE_VERSION[engine.to_sym])
40
+ iops =
41
+ if _ref_key?("iops", args, "db iops")
42
+ _ref_string_default("iops", args, "db iops", 1000)
43
+ else
44
+ ""
45
+ end
46
+ kms = _ref_attr_string("kms", "Arn", args)
47
+ license = _valid_values(args[:license], %w( license-included bring-your-own-license general-public-license ), "general-public-license")
40
48
  user_name = _ref_string("user_name", args, "db master user name")
41
49
  user_password = _ref_string("user_password", args, "db master user password")
42
50
  multi_az = _bool("multi_az", args, false)
43
51
  option = _ref_string("option", args, "db option group")
44
- port = _ref_string("port", args, "db port")
45
- port = PORT[args[:engine]] if port.empty?
52
+ port = _ref_string_default("port", args, "db port", PORT[engine.to_sym])
46
53
  backup_window = _window_time("rds", args[:backup_start] || DEFAULT_SNAPSHOT_TIME[:rds])
47
54
  maintenance = _maintenance_window("rds", args[:maintenance] || DEFAULT_MAINTENANCE_TIME[:rds])
48
55
  publicly = _bool("publicly", args, false)
49
- source_db = _ref_string("source_db", args, "db source db")
50
- storage_encrypted = _bool("encrypted", args, false)
56
+ source_db = _ref_string("source_db", args, "db instance id")
57
+ encrypted = _bool("encrypted", args, false)
51
58
  storage_type = _valid_values(args[:storage_type], %w( standard gp2 io1 ), "gp2")
52
59
  tags = _tags(args)
53
- timezone = args[:timezone] || ""
60
+ timezone = _ref_string_default("timezone", args, "db timezone")
54
61
  security_groups = _ref_array("security_groups", args, "security group")
62
+ ## TODO use helper
63
+ depends = _resource_name(args[:master_instance], "db instance") unless _empty? source_db
64
+
65
+ allocated = "" unless _empty? cluster
66
+ character = "" if engine =~ /aurora/
67
+ parameter =
68
+ if _empty? parameter
69
+ if engine == "mysql" and engine_version =~ /5.7/
70
+ "default.mysql5.7"
71
+ elsif engine == "aurora" and engine_version =~ /5.6/
72
+ "default.aurora5.6"
73
+ elsif engine == "postgres" and engine_version =~ /9.4/
74
+ "default.postgres9.4"
75
+ elsif engine == "mariadb" and engine_version =~ /10.0/
76
+ "default.mariadb10.0"
77
+ else
78
+ nil
79
+ end
80
+ else
81
+ nil
82
+ end
83
+ instance_id = instance_id.downcase if instance_id.is_a? String
84
+ if engine !~ /sqlserver/
85
+ domain = ""
86
+ domain_iam = ""
87
+ end
88
+ db_name = "" unless _empty? snapshot
89
+ iops = "" if storage_type != "io1"
90
+ multi_az = false unless _empty? az
91
+ source_db = "" if engine !~ /(mysql|mariadb|postgres)/
92
+ unless _empty? source_db
93
+ multi_az = false
94
+ snapshot = ""
95
+ backup_retention = ""
96
+ db_name = ""
97
+ subnet = ""
98
+ user_name = ""
99
+ user_password = ""
100
+ backup_window = ""
101
+ end
102
+ encrypted = true unless _empty? kms
103
+ if encrypted
104
+ cluster = ""
105
+ snapshot = ""
106
+ source_db = ""
107
+ end
108
+ security_groups = "" unless _empty? db_security_groups
109
+ unless _empty? cluster
110
+ allocated = ""
111
+ backup_retention = ""
112
+ character = ""
113
+ db_security_groups = []
114
+ db_name = ""
115
+ subnet = ""
116
+ user_name = ""
117
+ user_password = ""
118
+ multi_az = ""
119
+ option = ""
120
+ backup_window = ""
121
+ maintenance = ""
122
+ port = ""
123
+ source_db = ""
124
+ security_groups = []
125
+ backup_window = ""
126
+ maintenance = ""
127
+ storage_type = ""
128
+ end
55
129
 
56
130
  _(name) do
57
131
  Type "AWS::RDS::DBInstance"
58
132
  Properties do
59
- AllocatedStorage allocated
133
+ AllocatedStorage allocated unless _empty? allocated
60
134
  AllowMajorVersionUpgrade allow
61
135
  AutoMinorVersionUpgrade auto
62
- AvailabilityZone az unless multi_az
63
- BackupRetentionPeriod backup_retention if 0 < backup_retention
64
- CharacterSetName character if !character.empty? and engine =~ /^oracle.*$/
65
- CopyTagsToSnapshot copy_tags unless copy_tags.empty?
66
- DBClusterIdentifier cluster if engine == "aurora" and !cluster.empty?
136
+ AvailabilityZone az unless _empty? az
137
+ BackupRetentionPeriod backup_retention unless _empty? backup_retention
138
+ CharacterSetName character unless _empty? character
139
+ CopyTagsToSnapshot copy_tags unless _empty? copy_tags
140
+ DBClusterIdentifier cluster unless _empty? cluster
67
141
  DBInstanceClass instance_class
68
- DBInstanceIdentifier instance_id
69
- DBName db_name if snapshot.empty?
70
- DBParameterGroupName parameter unless parameter.empty?
71
- DBSecurityGroups security if security_groups.empty?
72
- DBSnapshotIdentifier snapshot unless snapshot.empty?
73
- DBSubnetGroupName subnet_group
74
- Domain domain unless domain.empty? and engine !~ /sqlserver/
75
- DomainIAMRoleName domain_iam unless domain_iam.empty? and engine !~ /sqlserver/
142
+ DBInstanceIdentifier instance_id unless _empty? instance_id
143
+ DBName db_name unless _empty? db_name
144
+ DBParameterGroupName parameter unless _empty? parameter
145
+ DBSecurityGroups db_security_groups unless _empty? db_security_groups
146
+ DBSnapshotIdentifier snapshot unless _empty? snapshot
147
+ DBSubnetGroupName subnet unless _empty? subnet
148
+ Domain domain unless _empty? domain
149
+ DomainIAMRoleName domain_iam unless _empty? domain_iam
76
150
  Engine engine
77
151
  EngineVersion engine_version
78
- Iops iops unless iops.empty?
79
- #KmsKeyId
80
- #LicenseModel
81
- MasterUsername user_name
82
- MasterUserPassword user_password
83
- MultiAZ multi_az
84
- OptionGroupName option unless option.empty?
85
- Port port
86
- PreferredBackupWindow backup_window
87
- PreferredMaintenanceWindow maintenance
152
+ Iops iops unless _empty? iops
153
+ KmsKeyId kms unless _empty? kms
154
+ LicenseModel license unless _empty? license
155
+ MasterUsername user_name unless _empty? user_name
156
+ MasterUserPassword user_password unless _empty? user_password
157
+ MultiAZ multi_az unless _empty? multi_az
158
+ OptionGroupName option unless _empty? option
159
+ Port port unless _empty? port
160
+ PreferredBackupWindow backup_window unless _empty? backup_window
161
+ PreferredMaintenanceWindow maintenance unless _empty? maintenance
88
162
  PubliclyAccessible publicly
89
- SourceDBInstanceIdentifier source_db unless source_db.empty?
90
- StorageEncrypted storage_encrypted if storage_encrypted == true
91
- StorageType storage_type
163
+ SourceDBInstanceIdentifier source_db unless _empty? source_db
164
+ StorageEncrypted encrypted unless _empty? kms
165
+ StorageType storage_type unless _empty? storage_type
92
166
  Tags tags
93
- Timezone timezone unless timezone.empty?
94
- VPCSecurityGroups security_groups unless security_groups.empty?
167
+ Timezone timezone unless _empty? timezone
168
+ VPCSecurityGroups security_groups unless _empty? security_groups
95
169
  end
170
+ DependsOn depends unless _empty? depends
96
171
  end
data/test/helper_test.rb CHANGED
@@ -56,6 +56,18 @@ EOS
56
56
  assert_equal description, "test description, test"
57
57
  end
58
58
 
59
+ def test_empty
60
+ assert_equal _empty?(nil), true
61
+ assert_equal _empty?(""), true
62
+ assert_equal _empty?("test"), false
63
+ assert_equal _empty?([]), true
64
+ assert_equal _empty?([ "test" ]), false
65
+ assert_equal _empty?(true), false
66
+ assert_equal _empty?(false), false
67
+ assert_equal _empty?({}), true
68
+ assert_equal _empty?({ test: "test" }), false
69
+ end
70
+
59
71
  def test_valid_values
60
72
  assert_equal _valid_values("test1", ["test1", "test2"]), "test1"
61
73
  assert_equal _valid_values("test3", ["test1", "test2"], "test1"), "test1"
@@ -3,7 +3,7 @@ require 'abstract_unit'
3
3
  class RdsDbClusterTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _rds_db_cluster "test", ref_parameter: "test", ref_subnet_group: "test", ref_user_name: "test", ref_user_password: "test", ref_security_groups: "test"
6
+ _rds_db_cluster "test", ref_parameter: "test", ref_subnet: "test", ref_user_name: "test", ref_user_password: "test", ref_security_groups: "test"
7
7
  EOS
8
8
  act_template = run_client_as_json(template)
9
9
  exp_template = <<-EOS
@@ -11,6 +11,12 @@ _rds_db_cluster "test", ref_parameter: "test", ref_subnet_group: "test", ref_use
11
11
  "TestDbCluster": {
12
12
  "Type": "AWS::RDS::DBCluster",
13
13
  "Properties": {
14
+ "AvailabilityZone": {
15
+ "Fn::GetAtt": [
16
+ "TestSubnet",
17
+ "AvailabilityZone"
18
+ ]
19
+ },
14
20
  "BackupRetentionPeriod": "7",
15
21
  "DatabaseName": {
16
22
  "Fn::Join": [
@@ -3,7 +3,14 @@ require 'abstract_unit'
3
3
  class RdsDbInstanceTest < Minitest::Test
4
4
  def test_normal
5
5
  template = <<-EOS
6
- _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group: "test", ref_security_groups: "test", ref_user_name: "test", ref_user_password: "test", az: "test"
6
+ _rds_db_instance "test",
7
+ ref_db_name: "test",
8
+ ref_port: "test",
9
+ ref_subnet: "test",
10
+ ref_security_groups: "test",
11
+ ref_user_name: "test",
12
+ ref_user_password: "test",
13
+ az: "test"
7
14
  EOS
8
15
  act_template = run_client_as_json(template)
9
16
  exp_template = <<-EOS
@@ -39,6 +46,7 @@ _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group
39
46
  },
40
47
  "Engine": "mysql",
41
48
  "EngineVersion": "5.7.17",
49
+ "LicenseModel": "general-public-license",
42
50
  "MasterUsername": {
43
51
  "Ref": "TestDbMasterUserName"
44
52
  },
@@ -88,6 +96,367 @@ _rds_db_instance "test", ref_db_name: "test", ref_port: "test", ref_subnet_group
88
96
  ]
89
97
  }
90
98
  }
99
+ }
100
+ EOS
101
+ assert_equal exp_template.chomp, act_template
102
+ end
103
+
104
+ def test_single_master
105
+ template = <<-EOS
106
+ _rds_db_instance 'test',
107
+ instance_class: 'db.t2.micro',
108
+ engine: 'mysql', engine_version: '5.7.17',
109
+ ref_db_name: 'test',
110
+ ref_subnet: 'test',
111
+ ref_security_groups: %w( test ),
112
+ ref_port: 'test',
113
+ ref_user_name: 'test',
114
+ ref_user_password: 'test'
115
+ EOS
116
+ act_template = run_client_as_json(template)
117
+ exp_template = <<-EOS
118
+ {
119
+ "TestDbInstance": {
120
+ "Type": "AWS::RDS::DBInstance",
121
+ "Properties": {
122
+ "AllocatedStorage": "5",
123
+ "AllowMajorVersionUpgrade": "true",
124
+ "AutoMinorVersionUpgrade": "true",
125
+ "BackupRetentionPeriod": "7",
126
+ "DBInstanceClass": "db.t2.micro",
127
+ "DBInstanceIdentifier": {
128
+ "Fn::Join": [
129
+ "-",
130
+ [
131
+ {
132
+ "Ref": "Service"
133
+ },
134
+ {
135
+ "Ref": "Name"
136
+ }
137
+ ]
138
+ ]
139
+ },
140
+ "DBName": {
141
+ "Ref": "TestDbName"
142
+ },
143
+ "DBParameterGroupName": "default.mysql5.7",
144
+ "DBSubnetGroupName": {
145
+ "Ref": "TestDbSubnetGroup"
146
+ },
147
+ "Engine": "mysql",
148
+ "EngineVersion": "5.7.17",
149
+ "LicenseModel": "general-public-license",
150
+ "MasterUsername": {
151
+ "Ref": "TestDbMasterUserName"
152
+ },
153
+ "MasterUserPassword": {
154
+ "Ref": "TestDbMasterUserPassword"
155
+ },
156
+ "MultiAZ": "false",
157
+ "Port": {
158
+ "Ref": "TestDbPort"
159
+ },
160
+ "PreferredBackupWindow": "21:30-22:00",
161
+ "PreferredMaintenanceWindow": "Thu:20:30-Thu:21:00",
162
+ "PubliclyAccessible": "false",
163
+ "StorageType": "gp2",
164
+ "Tags": [
165
+ {
166
+ "Key": "Name",
167
+ "Value": {
168
+ "Fn::Join": [
169
+ "-",
170
+ [
171
+ {
172
+ "Ref": "Service"
173
+ },
174
+ "test"
175
+ ]
176
+ ]
177
+ }
178
+ },
179
+ {
180
+ "Key": "Service",
181
+ "Value": {
182
+ "Ref": "Service"
183
+ }
184
+ },
185
+ {
186
+ "Key": "Version",
187
+ "Value": {
188
+ "Ref": "Version"
189
+ }
190
+ }
191
+ ],
192
+ "VPCSecurityGroups": [
193
+ {
194
+ "Ref": "TestSecurityGroup"
195
+ }
196
+ ]
197
+ }
198
+ }
199
+ }
200
+ EOS
201
+ assert_equal exp_template.chomp, act_template
202
+ end
203
+
204
+ def test_cluster
205
+ template = <<-EOS
206
+ _rds_db_instance 'test cluster',
207
+ engine: 'aurora',
208
+ instance_class: 'db.t2.medium',
209
+ ref_cluster: 'test'
210
+ EOS
211
+ act_template = run_client_as_json(template)
212
+ exp_template = <<-EOS
213
+ {
214
+ "TestClusterDbInstance": {
215
+ "Type": "AWS::RDS::DBInstance",
216
+ "Properties": {
217
+ "AllowMajorVersionUpgrade": "true",
218
+ "AutoMinorVersionUpgrade": "true",
219
+ "DBClusterIdentifier": {
220
+ "Ref": "TestDbCluster"
221
+ },
222
+ "DBInstanceClass": "db.t2.medium",
223
+ "DBInstanceIdentifier": {
224
+ "Fn::Join": [
225
+ "-",
226
+ [
227
+ {
228
+ "Ref": "Service"
229
+ },
230
+ {
231
+ "Ref": "Name"
232
+ }
233
+ ]
234
+ ]
235
+ },
236
+ "DBParameterGroupName": "default.aurora5.6",
237
+ "Engine": "aurora",
238
+ "EngineVersion": "5.6.10a",
239
+ "LicenseModel": "general-public-license",
240
+ "PubliclyAccessible": "false",
241
+ "Tags": [
242
+ {
243
+ "Key": "Name",
244
+ "Value": {
245
+ "Fn::Join": [
246
+ "-",
247
+ [
248
+ {
249
+ "Ref": "Service"
250
+ },
251
+ "test-cluster"
252
+ ]
253
+ ]
254
+ }
255
+ },
256
+ {
257
+ "Key": "Service",
258
+ "Value": {
259
+ "Ref": "Service"
260
+ }
261
+ },
262
+ {
263
+ "Key": "Version",
264
+ "Value": {
265
+ "Ref": "Version"
266
+ }
267
+ }
268
+ ]
269
+ }
270
+ }
271
+ }
272
+ EOS
273
+ assert_equal exp_template.chomp, act_template
274
+ end
275
+
276
+ def test_slave
277
+ template = <<-EOS
278
+ _rds_db_instance 'test',
279
+ master_instance: 'master',
280
+ ref_port: 'test',
281
+ source_db: 'master',
282
+ instance_class: 'db.t2.micro',
283
+ engine: 'mysql',
284
+ engine_version: '5.7.17',
285
+ ref_security_groups: %w( test )
286
+ EOS
287
+ act_template = run_client_as_json(template)
288
+ exp_template = <<-EOS
289
+ {
290
+ "TestDbInstance": {
291
+ "Type": "AWS::RDS::DBInstance",
292
+ "Properties": {
293
+ "AllocatedStorage": "5",
294
+ "AllowMajorVersionUpgrade": "true",
295
+ "AutoMinorVersionUpgrade": "true",
296
+ "DBInstanceClass": "db.t2.micro",
297
+ "DBInstanceIdentifier": {
298
+ "Fn::Join": [
299
+ "-",
300
+ [
301
+ {
302
+ "Ref": "Service"
303
+ },
304
+ {
305
+ "Ref": "Name"
306
+ }
307
+ ]
308
+ ]
309
+ },
310
+ "DBParameterGroupName": "default.mysql5.7",
311
+ "Engine": "mysql",
312
+ "EngineVersion": "5.7.17",
313
+ "LicenseModel": "general-public-license",
314
+ "MultiAZ": "false",
315
+ "Port": {
316
+ "Ref": "TestDbPort"
317
+ },
318
+ "PreferredMaintenanceWindow": "Thu:20:30-Thu:21:00",
319
+ "PubliclyAccessible": "false",
320
+ "SourceDBInstanceIdentifier": "master",
321
+ "StorageType": "gp2",
322
+ "Tags": [
323
+ {
324
+ "Key": "Name",
325
+ "Value": {
326
+ "Fn::Join": [
327
+ "-",
328
+ [
329
+ {
330
+ "Ref": "Service"
331
+ },
332
+ "test"
333
+ ]
334
+ ]
335
+ }
336
+ },
337
+ {
338
+ "Key": "Service",
339
+ "Value": {
340
+ "Ref": "Service"
341
+ }
342
+ },
343
+ {
344
+ "Key": "Version",
345
+ "Value": {
346
+ "Ref": "Version"
347
+ }
348
+ }
349
+ ],
350
+ "VPCSecurityGroups": [
351
+ {
352
+ "Ref": "TestSecurityGroup"
353
+ }
354
+ ]
355
+ },
356
+ "DependsOn": "MasterDbInstance"
357
+ }
358
+ }
359
+ EOS
360
+ assert_equal exp_template.chomp, act_template
361
+ end
362
+
363
+ def test_multiaz
364
+ template = <<-EOS
365
+ _rds_db_instance 'test',
366
+ instance_class: 'db.t2.micro',
367
+ engine: 'mysql',
368
+ engine_version: '5.7.17',
369
+ ref_db_name: 'test',
370
+ ref_subnet: 'test',
371
+ ref_security_groups: %w( test ),
372
+ ref_user_name: 'test',
373
+ ref_user_password: 'test',
374
+ ref_port: 'test',
375
+ multi_az: true
376
+ EOS
377
+ act_template = run_client_as_json(template)
378
+ exp_template = <<-EOS
379
+ {
380
+ "TestDbInstance": {
381
+ "Type": "AWS::RDS::DBInstance",
382
+ "Properties": {
383
+ "AllocatedStorage": "5",
384
+ "AllowMajorVersionUpgrade": "true",
385
+ "AutoMinorVersionUpgrade": "true",
386
+ "BackupRetentionPeriod": "7",
387
+ "DBInstanceClass": "db.t2.micro",
388
+ "DBInstanceIdentifier": {
389
+ "Fn::Join": [
390
+ "-",
391
+ [
392
+ {
393
+ "Ref": "Service"
394
+ },
395
+ {
396
+ "Ref": "Name"
397
+ }
398
+ ]
399
+ ]
400
+ },
401
+ "DBName": {
402
+ "Ref": "TestDbName"
403
+ },
404
+ "DBParameterGroupName": "default.mysql5.7",
405
+ "DBSubnetGroupName": {
406
+ "Ref": "TestDbSubnetGroup"
407
+ },
408
+ "Engine": "mysql",
409
+ "EngineVersion": "5.7.17",
410
+ "LicenseModel": "general-public-license",
411
+ "MasterUsername": {
412
+ "Ref": "TestDbMasterUserName"
413
+ },
414
+ "MasterUserPassword": {
415
+ "Ref": "TestDbMasterUserPassword"
416
+ },
417
+ "MultiAZ": "true",
418
+ "Port": {
419
+ "Ref": "TestDbPort"
420
+ },
421
+ "PreferredBackupWindow": "21:30-22:00",
422
+ "PreferredMaintenanceWindow": "Thu:20:30-Thu:21:00",
423
+ "PubliclyAccessible": "false",
424
+ "StorageType": "gp2",
425
+ "Tags": [
426
+ {
427
+ "Key": "Name",
428
+ "Value": {
429
+ "Fn::Join": [
430
+ "-",
431
+ [
432
+ {
433
+ "Ref": "Service"
434
+ },
435
+ "test"
436
+ ]
437
+ ]
438
+ }
439
+ },
440
+ {
441
+ "Key": "Service",
442
+ "Value": {
443
+ "Ref": "Service"
444
+ }
445
+ },
446
+ {
447
+ "Key": "Version",
448
+ "Value": {
449
+ "Ref": "Version"
450
+ }
451
+ }
452
+ ],
453
+ "VPCSecurityGroups": [
454
+ {
455
+ "Ref": "TestSecurityGroup"
456
+ }
457
+ ]
458
+ }
459
+ }
91
460
  }
92
461
  EOS
93
462
  assert_equal exp_template.chomp, act_template
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoya Nakazawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk