convox_installer 1.0.8 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "convox_installer"
4
- require "securerandom"
3
+ require 'convox_installer'
4
+ require 'securerandom'
5
5
 
6
6
  RSpec.describe ConvoxInstaller::Config do
7
- before(:each) do
7
+ before do
8
8
  stub_const('ConvoxInstaller::Config::CONFIG_FILE', '/path/to/.installer_config.json')
9
9
  end
10
10
 
11
- after(:each) do
12
- ENV.delete "AWS_REGION"
13
- ENV.delete "AWS_ACCESS_KEY_ID"
11
+ after do
12
+ ENV.delete 'AWS_REGION'
13
+ ENV.delete 'AWS_ACCESS_KEY_ID'
14
14
  end
15
15
 
16
- it "loads the saved config from ./.installer_config.json" do
16
+ it 'loads the saved config from ./.installer_config.json' do
17
17
  expect(described_class).to receive(:config_file_exists?).and_return(true)
18
18
  expect(described_class).to receive(:read_config_file).and_return(
19
19
  '{ "config": { "aws_region": "us-west-2", "aws_access_key_id": "1234" } }'
@@ -21,42 +21,42 @@ RSpec.describe ConvoxInstaller::Config do
21
21
  config = described_class.new
22
22
 
23
23
  expect(config.config).to eq(
24
- aws_region: "us-west-2",
25
- aws_access_key_id: "1234",
24
+ aws_region: 'us-west-2',
25
+ aws_access_key_id: '1234'
26
26
  )
27
27
  end
28
28
 
29
- it "loads config from ENV vars" do
29
+ it 'loads config from ENV vars' do
30
30
  expect(described_class).to receive(:config_file_exists?).and_return(false)
31
- ENV["AWS_REGION"] = "us-east-1"
32
- ENV["AWS_ACCESS_KEY_ID"] = "2345"
31
+ ENV['AWS_REGION'] = 'us-east-1'
32
+ ENV['AWS_ACCESS_KEY_ID'] = '2345'
33
33
 
34
34
  config = described_class.new
35
35
  expect(config.config).to eq(
36
- aws_region: "us-east-1",
37
- aws_access_key_id: "2345",
36
+ aws_region: 'us-east-1',
37
+ aws_access_key_id: '2345'
38
38
  )
39
39
  end
40
40
 
41
- it "prompts the user for their AWS details, and re-prompts to correct mistakes" do
41
+ it 'prompts the user for their AWS details, and re-prompts to correct mistakes' do
42
42
  expect(described_class).to receive(:config_file_exists?).and_return(false)
43
43
  input = StringIO.new
44
44
  output = StringIO.new
45
45
  highline = HighLine.new(input, output)
46
46
 
47
47
  input_details = [
48
- [:stack_name, ""],
49
- [:aws_region, ""],
50
- [:instance_type, "c5.xlarge"],
51
- [:aws_access_key_id, "asdf"],
52
- [:aws_secret_access_key, "xkcd"],
53
- [:confirm?, "n"],
54
- [:stack_name, "convox-test"],
55
- [:aws_region, "us-north-12"],
56
- [:instance_type, "t3.medium"],
57
- [:aws_access_key_id, "sdfg"],
58
- [:aws_secret_access_key, ""],
59
- [:confirm?, "y"],
48
+ [:stack_name, ''],
49
+ [:aws_region, ''],
50
+ [:instance_type, 'c5.xlarge'],
51
+ [:aws_access_key_id, 'asdf'],
52
+ [:aws_secret_access_key, 'xkcd'],
53
+ [:confirm?, 'n'],
54
+ [:stack_name, 'convox-test'],
55
+ [:aws_region, 'us-north-12'],
56
+ [:instance_type, 't3.medium'],
57
+ [:aws_access_key_id, 'sdfg'],
58
+ [:aws_secret_access_key, ''],
59
+ [:confirm?, 'y']
60
60
  ]
61
61
  input << input_details.map(&:last).join("\n") << "\n"
62
62
  input.rewind
@@ -67,59 +67,59 @@ RSpec.describe ConvoxInstaller::Config do
67
67
  expect(config.config).to eq({})
68
68
  config.prompt_for_config
69
69
  expect(config.config).to eq(
70
- :stack_name => "convox-test",
71
- :aws_region => "us-north-12",
72
- :aws_access_key_id => "sdfg",
73
- :aws_secret_access_key => "xkcd",
74
- :instance_type => "t3.medium",
70
+ stack_name: 'convox-test',
71
+ aws_region: 'us-north-12',
72
+ aws_access_key_id: 'sdfg',
73
+ aws_secret_access_key: 'xkcd',
74
+ instance_type: 't3.medium'
75
75
  )
76
76
  output.rewind
77
77
  stripped_output = output.read.lines.map(&:rstrip).join("\n")
78
- expected_output = <<-EOS
79
- Please enter a name for your Convox installation |convox|
80
- Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |t3.medium|
81
- Admin AWS Credentials
82
- ============================================
83
-
84
- Please enter your AWS Access Key ID: Please enter your AWS Secret Access Key:
85
- ============================================
86
- SUMMARY
87
- ============================================
88
-
89
- Convox Stack Name: convox
90
- AWS Region: us-east-1
91
- EC2 Instance Type: c5.xlarge
92
- AWS Access Key ID: asdf
93
- AWS Secret Access Key: xkcd
94
-
95
- We've saved your configuration to: /path/to/.installer_config.json
96
- If anything goes wrong during the installation, you can restart the script to reload the config and continue.
97
-
98
- Please double check all of these configuration details.
99
- Would you like to start the Convox installation? (press 'n' to correct any settings)
100
-
101
- Please enter a name for your Convox installation |convox|
102
- Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |c5.xlarge|
103
- Admin AWS Credentials
104
- ============================================
105
-
106
- Please enter your AWS Access Key ID: |asdf| Please enter your AWS Secret Access Key: |xkcd|
107
- ============================================
108
- SUMMARY
109
- ============================================
110
-
111
- Convox Stack Name: convox-test
112
- AWS Region: us-north-12
113
- EC2 Instance Type: t3.medium
114
- AWS Access Key ID: sdfg
115
- AWS Secret Access Key: xkcd
116
-
117
- We've saved your configuration to: /path/to/.installer_config.json
118
- If anything goes wrong during the installation, you can restart the script to reload the config and continue.
119
-
120
- Please double check all of these configuration details.
121
- Would you like to start the Convox installation? (press 'n' to correct any settings)
122
- EOS
78
+ expected_output = <<~CONVOX_INSTALLER_OUTPUT
79
+ Please enter a name for your Convox installation |convox|
80
+ Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |t3.medium|
81
+ Admin AWS Credentials
82
+ ============================================
83
+
84
+ Please enter your AWS Access Key ID: Please enter your AWS Secret Access Key:
85
+ ============================================
86
+ SUMMARY
87
+ ============================================
88
+
89
+ Convox Stack Name: convox
90
+ AWS Region: us-east-1
91
+ EC2 Instance Type: c5.xlarge
92
+ AWS Access Key ID: asdf
93
+ AWS Secret Access Key: xkcd
94
+
95
+ We've saved your configuration to: /path/to/.installer_config.json
96
+ If anything goes wrong during the installation, you can restart the script to reload the config and continue.
97
+
98
+ Please double check all of these configuration details.
99
+ Would you like to start the Convox installation? (press 'n' to correct any settings)
100
+
101
+ Please enter a name for your Convox installation |convox|
102
+ Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |c5.xlarge|
103
+ Admin AWS Credentials
104
+ ============================================
105
+
106
+ Please enter your AWS Access Key ID: |asdf| Please enter your AWS Secret Access Key: |xkcd|
107
+ ============================================
108
+ SUMMARY
109
+ ============================================
110
+
111
+ Convox Stack Name: convox-test
112
+ AWS Region: us-north-12
113
+ EC2 Instance Type: t3.medium
114
+ AWS Access Key ID: sdfg
115
+ AWS Secret Access Key: xkcd
116
+
117
+ We've saved your configuration to: /path/to/.installer_config.json
118
+ If anything goes wrong during the installation, you can restart the script to reload the config and continue.
119
+
120
+ Please double check all of these configuration details.
121
+ Would you like to start the Convox installation? (press 'n' to correct any settings)
122
+ CONVOX_INSTALLER_OUTPUT
123
123
 
124
124
  # puts stripped_output
125
125
  # puts "---------------"
@@ -127,7 +127,7 @@ EOS
127
127
  expect(stripped_output).to eq expected_output.strip
128
128
  end
129
129
 
130
- it "prompts for custom configuration" do
130
+ it 'prompts for custom configuration' do
131
131
  expect(described_class).to receive(:config_file_exists?).and_return(false)
132
132
  input = StringIO.new
133
133
  output = StringIO.new
@@ -135,99 +135,99 @@ EOS
135
135
 
136
136
  custom_prompts = ConvoxInstaller::Config::DEFAULT_PROMPTS + [
137
137
  {
138
- section: "ECR Authentication",
138
+ section: 'ECR Authentication',
139
139
  info: "You should have received authentication details for the Docker Registry\n" \
140
- "via email. If not, please contact support@example.com",
140
+ 'via email. If not, please contact support@example.com'
141
141
  },
142
142
  {
143
143
  key: :docker_registry_username,
144
- title: "Docker Registry Access Key ID",
144
+ title: 'Docker Registry Access Key ID'
145
145
  },
146
146
  {
147
147
  key: :docker_registry_password,
148
- title: "Docker Registry Secret Access Key",
148
+ title: 'Docker Registry Secret Access Key'
149
149
  },
150
150
  {
151
151
  key: :admin_email,
152
- title: "Admin Email",
153
- prompt: "Please enter the email address you would like to use " \
154
- "for the default admin user",
155
- default: "admin@example.com",
152
+ title: 'Admin Email',
153
+ prompt: 'Please enter the email address you would like to use ' \
154
+ 'for the default admin user',
155
+ default: 'admin@example.com'
156
156
  },
157
157
  {
158
158
  key: :admin_password,
159
- title: "Admin Password",
160
- value: -> (c) { SecureRandom.hex(8) },
161
- },
159
+ title: 'Admin Password',
160
+ value: ->(_c) { SecureRandom.hex(8) }
161
+ }
162
162
  ]
163
163
 
164
164
  input_details = [
165
- [:stack_name, ""],
166
- [:aws_region, ""],
167
- [:instance_type, "c5.xlarge"],
168
- [:aws_access_key_id, "asdf"],
169
- [:aws_secret_access_key, "xkcd"],
170
- [:docker_registry_username, "bob"],
171
- [:docker_registry_password, "password1"],
172
- [:admin_email, "admin@test.com"],
173
- [:confirm?, "y"],
165
+ [:stack_name, ''],
166
+ [:aws_region, ''],
167
+ [:instance_type, 'c5.xlarge'],
168
+ [:aws_access_key_id, 'asdf'],
169
+ [:aws_secret_access_key, 'xkcd'],
170
+ [:docker_registry_username, 'bob'],
171
+ [:docker_registry_password, 'password1'],
172
+ [:admin_email, 'admin@test.com'],
173
+ [:confirm?, 'y']
174
174
  ]
175
175
  input << input_details.map(&:last).join("\n") << "\n"
176
176
  input.rewind
177
177
 
178
178
  config = described_class.new(highline: highline, prompts: custom_prompts)
179
179
  expect(config).to receive(:save_config_to_file).exactly(9).times
180
- expect(SecureRandom).to receive(:hex).with(8).and_return("99a6f67de0c7a117")
180
+ expect(SecureRandom).to receive(:hex).with(8).and_return('99a6f67de0c7a117')
181
181
 
182
182
  expect(config.config).to eq({})
183
183
 
184
184
  config.prompt_for_config
185
185
 
186
186
  expect(config.config).to eq(
187
- :stack_name => "convox",
188
- :aws_region => "us-east-1",
189
- :aws_access_key_id => "asdf",
190
- :aws_secret_access_key => "xkcd",
191
- :instance_type => "c5.xlarge",
192
- :docker_registry_username => "bob",
193
- :docker_registry_password => "password1",
194
- :admin_email => "admin@test.com",
195
- :admin_password => "99a6f67de0c7a117",
187
+ stack_name: 'convox',
188
+ aws_region: 'us-east-1',
189
+ aws_access_key_id: 'asdf',
190
+ aws_secret_access_key: 'xkcd',
191
+ instance_type: 'c5.xlarge',
192
+ docker_registry_username: 'bob',
193
+ docker_registry_password: 'password1',
194
+ admin_email: 'admin@test.com',
195
+ admin_password: '99a6f67de0c7a117'
196
196
  )
197
197
  output.rewind
198
198
  stripped_output = output.read.lines.map(&:rstrip).join("\n")
199
- expected_output = <<-EOS
200
- Please enter a name for your Convox installation |convox|
201
- Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |t3.medium|
202
- Admin AWS Credentials
203
- ============================================
204
-
205
- Please enter your AWS Access Key ID: Please enter your AWS Secret Access Key:
206
- ECR Authentication
207
- ============================================
208
-
209
- Please enter your Docker Registry Access Key ID: Please enter your Docker Registry Secret Access Key: Please enter the email address you would like to use for the default admin user |admin@example.com|
210
-
211
- ============================================
212
- SUMMARY
213
- ============================================
214
-
215
- Convox Stack Name: convox
216
- AWS Region: us-east-1
217
- EC2 Instance Type: c5.xlarge
218
- AWS Access Key ID: asdf
219
- AWS Secret Access Key: xkcd
220
- Docker Registry Access Key ID: bob
221
- Docker Registry Secret Access Key: password1
222
- Admin Email: admin@test.com
223
- Admin Password: 99a6f67de0c7a117
224
-
225
- We've saved your configuration to: /path/to/.installer_config.json
226
- If anything goes wrong during the installation, you can restart the script to reload the config and continue.
227
-
228
- Please double check all of these configuration details.
229
- Would you like to start the Convox installation? (press 'n' to correct any settings)
230
- EOS
199
+ expected_output = <<~CONVOX_INSTALLER_OUTPUT
200
+ Please enter a name for your Convox installation |convox|
201
+ Please enter your AWS Region: |us-east-1| Please enter your EC2 Instance Type: |t3.medium|
202
+ Admin AWS Credentials
203
+ ============================================
204
+
205
+ Please enter your AWS Access Key ID: Please enter your AWS Secret Access Key:
206
+ ECR Authentication
207
+ ============================================
208
+
209
+ Please enter your Docker Registry Access Key ID: Please enter your Docker Registry Secret Access Key: Please enter the email address you would like to use for the default admin user |admin@example.com|
210
+
211
+ ============================================
212
+ SUMMARY
213
+ ============================================
214
+
215
+ Convox Stack Name: convox
216
+ AWS Region: us-east-1
217
+ EC2 Instance Type: c5.xlarge
218
+ AWS Access Key ID: asdf
219
+ AWS Secret Access Key: xkcd
220
+ Docker Registry Access Key ID: bob
221
+ Docker Registry Secret Access Key: password1
222
+ Admin Email: admin@test.com
223
+ Admin Password: 99a6f67de0c7a117
224
+
225
+ We've saved your configuration to: /path/to/.installer_config.json
226
+ If anything goes wrong during the installation, you can restart the script to reload the config and continue.
227
+
228
+ Please double check all of these configuration details.
229
+ Would you like to start the Convox installation? (press 'n' to correct any settings)
230
+ CONVOX_INSTALLER_OUTPUT
231
231
 
232
232
  # puts stripped_output
233
233
  # puts "---------------"
@@ -1,56 +1,84 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "convox_installer"
3
+ require 'convox_installer'
4
4
 
5
5
  RSpec.describe ConvoxInstaller::Requirements do
6
- context "with no missing packages" do
7
- it "should do nothing" do
8
- req = ConvoxInstaller::Requirements.new
9
- expect(req).to receive(:find_command).with("convox").and_return(true)
10
- expect(req).to receive(:find_command).with("aws").and_return(true)
11
- expect(req).to_not receive(:quit!)
6
+ let(:convox_cli_version) { '3.3.4' }
12
7
 
13
- expect(req.logger).to_not receive(:error)
8
+ before do
9
+ allow_any_instance_of(
10
+ Convox::Client
11
+ ).to receive(:cli_version_string).and_return(convox_cli_version)
12
+ end
13
+
14
+ context 'with no missing packages and correct CLI version' do
15
+ it 'does nothing' do
16
+ req = described_class.new
17
+ expect(req).to receive(:find_command).with('convox').and_return(true)
18
+ expect(req).to receive(:find_command).with('aws').and_return(true)
19
+ expect(req).not_to receive(:quit!)
20
+
21
+ expect(req.logger).not_to receive(:error)
14
22
 
15
23
  req.ensure_requirements!
16
24
  end
17
25
  end
18
26
 
19
- context "on Mac" do
20
- context "with two missing packages" do
21
- it "should show the correct error message and quit" do
27
+ context 'with Mac' do
28
+ context 'with two missing packages' do
29
+ it 'shows the correct error message and quit' do
22
30
  expect(OS).to receive(:mac?).and_return(true)
23
31
 
24
- req = ConvoxInstaller::Requirements.new
25
- expect(req).to receive(:find_command).with("convox").and_return(false)
26
- expect(req).to receive(:find_command).with("aws").and_return(false)
32
+ req = described_class.new
33
+ expect(req).to receive(:find_command).with('convox').and_return(false)
34
+ expect(req).to receive(:find_command).with('aws').and_return(false)
35
+ expect(req).to receive(:quit!)
36
+
37
+ expect(req.logger).to receive(:error).with(
38
+ 'This script requires the convox and AWS CLI tools.'
39
+ )
40
+ expect(req.logger).to receive(:error).with(
41
+ 'Please run: brew install convox awscli'
42
+ )
43
+
44
+ req.ensure_requirements!
45
+ end
46
+ end
47
+
48
+ context 'with Convox CLI version 20210208170413' do
49
+ let(:convox_cli_version) { '20210208170413' }
50
+
51
+ it 'shows the correct error message and quit' do
52
+ req = described_class.new
53
+ expect(req).to receive(:find_command).with('convox').and_return(true)
54
+ expect(req).to receive(:find_command).with('aws').and_return(true)
27
55
  expect(req).to receive(:quit!)
28
56
 
29
57
  expect(req.logger).to receive(:error).with(
30
- "This script requires the convox and AWS CLI tools."
58
+ 'This script requires Convox CLI version 3.x.x. Your Convox CLI version is: 20210208170413'
31
59
  )
32
60
  expect(req.logger).to receive(:error).with(
33
- "Please run: brew install convox awscli"
61
+ "Please run 'brew update convox' or follow the instructions at https://docs.convox.com/getting-started/introduction"
34
62
  )
35
63
 
36
64
  req.ensure_requirements!
37
65
  end
38
66
  end
39
67
 
40
- context "with one missing packages" do
41
- it "should show the correct error message and quit" do
68
+ context 'with one missing packages' do
69
+ it 'shows the correct error message and quit' do
42
70
  expect(OS).to receive(:mac?).and_return(true)
43
71
 
44
- req = ConvoxInstaller::Requirements.new
45
- expect(req).to receive(:find_command).with("convox").and_return(false)
46
- expect(req).to receive(:find_command).with("aws").and_return(true)
72
+ req = described_class.new
73
+ expect(req).to receive(:find_command).with('convox').and_return(false)
74
+ expect(req).to receive(:find_command).with('aws').and_return(true)
47
75
  expect(req).to receive(:quit!)
48
76
 
49
77
  expect(req.logger).to receive(:error).with(
50
- "This script requires the convox and AWS CLI tools."
78
+ 'This script requires the convox and AWS CLI tools.'
51
79
  )
52
80
  expect(req.logger).to receive(:error).with(
53
- "Please run: brew install convox"
81
+ 'Please run: brew install convox'
54
82
  )
55
83
 
56
84
  req.ensure_requirements!
@@ -58,26 +86,26 @@ RSpec.describe ConvoxInstaller::Requirements do
58
86
  end
59
87
  end
60
88
 
61
- context "on Linux" do
62
- context "with two missing packages" do
63
- it "should show the correct error message and quit" do
89
+ context 'with Linux' do
90
+ context 'with two missing packages' do
91
+ it 'shows the correct error message and quit' do
64
92
  expect(OS).to receive(:mac?).and_return(false)
65
93
 
66
- req = ConvoxInstaller::Requirements.new
67
- expect(req).to receive(:find_command).with("convox").and_return(false)
68
- expect(req).to receive(:find_command).with("aws").and_return(false)
94
+ req = described_class.new
95
+ expect(req).to receive(:find_command).with('convox').and_return(false)
96
+ expect(req).to receive(:find_command).with('aws').and_return(false)
69
97
  expect(req).to receive(:quit!)
70
98
 
71
99
  expect(req.logger).to receive(:error).with(
72
- "This script requires the convox and AWS CLI tools."
100
+ 'This script requires the convox and AWS CLI tools.'
73
101
  )
74
- expect(req.logger).to receive(:error).with("Installation Instructions:")
102
+ expect(req.logger).to receive(:error).with('Installation Instructions:')
75
103
  expect(req.logger).to receive(:error).with(
76
- "* convox: https://docs.convox.com/introduction/installation"
104
+ '* convox: https://docs.convox.com/introduction/installation'
77
105
  )
78
106
  expect(req.logger).to receive(:error).with(
79
- "* aws: https://docs.aws.amazon.com/cli/latest/" \
80
- "userguide/cli-chap-install.html"
107
+ '* aws: https://docs.aws.amazon.com/cli/latest/' \
108
+ 'userguide/cli-chap-install.html'
81
109
  )
82
110
 
83
111
  req.ensure_requirements!
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,7 @@ $LOAD_PATH << File.expand_path(__dir__, '../lib')
20
20
 
21
21
  require 'vcr'
22
22
  require 'webmock/rspec'
23
- require 'pry-byebug'
23
+ # require 'pry-byebug'
24
24
 
25
25
  VCR.configure do |config|
26
26
  config.cassette_library_dir = 'spec/vcr_cassettes'
@@ -0,0 +1,46 @@
1
+ resource "aws_elasticache_cluster" "elasticache_cluster" {
2
+ cluster_id = "<%= config.fetch(:stack_name) %>-elasticache-<%= config.fetch(:random_id) %>"
3
+ engine = "<%= config[:elasticache_engine] || 'redis' %>"
4
+ engine_version = "<%= config[:elasticache_engine_version] || '6.x' %>"
5
+ node_type = "<%= config[:elasticache_node_type] || 'cache.t3.medium' %>"
6
+ num_cache_nodes = <%= config[:elasticache_num_cache_nodes] || 1 %>
7
+ port = <%= config[:elasticache_port] || 6379 %>
8
+
9
+ subnet_group_name = aws_elasticache_subnet_group.elasticache_subnet_group.name
10
+ security_group_ids = [aws_security_group.elasticache_security_group.id]
11
+
12
+ # Workaround for weird engine_version issue where 6.x works for creation, and fails for update
13
+ # See: https://github.com/hashicorp/terraform-provider-aws/issues/15625#issuecomment-727759811
14
+ # Fixed in version 3.38.0 of the Terraform AWS provider.
15
+ lifecycle {
16
+ ignore_changes = [engine_version]
17
+ }
18
+ }
19
+
20
+ resource "aws_elasticache_subnet_group" "elasticache_subnet_group" {
21
+ name = "<%= config.fetch(:stack_name) %>-elasticache-cluster-subnetgroup-<%= config.fetch(:random_id) %>"
22
+ subnet_ids = module.system.cluster.subnets
23
+ }
24
+
25
+ resource "aws_security_group" "elasticache_security_group" {
26
+ name = "<%= config.fetch(:stack_name) %>-elasticache-securitygroup-<%= config.fetch(:random_id) %>"
27
+
28
+ description = "Elasticache Security Group (Managed by Terraform)"
29
+ vpc_id = module.system.cluster.vpc
30
+
31
+ # Only Redis in
32
+ ingress {
33
+ from_port = 6379
34
+ to_port = 6379
35
+ protocol = "tcp"
36
+ cidr_blocks = ["10.1.0.0/16"]
37
+ }
38
+
39
+ # Allow all outbound traffic
40
+ egress {
41
+ from_port = 0
42
+ to_port = 0
43
+ protocol = "-1"
44
+ cidr_blocks = ["0.0.0.0/0"]
45
+ }
46
+ }
@@ -0,0 +1,45 @@
1
+ resource "aws_db_instance" "rds_database" {
2
+ allocated_storage = <%= config[:database_allocated_storage] || 30 %>
3
+ engine = "<%= config[:database_engine] || 'postgres' %>"
4
+ engine_version = "<%= config[:database_engine_version] || '14.2' %>"
5
+ instance_class = "<%= config[:database_instance_class] || 'db.t3.medium' %>"
6
+ name = "<%= config.fetch(:stack_name).gsub('-', '_') %>_database"
7
+ identifier = "<%= config.fetch(:stack_name) %>-rds-<%= config.fetch(:random_id) %>"
8
+ multi_az = <%= config[:database_multi_az] || true %>
9
+ username = "<%= config.fetch(:database_username) %>"
10
+ password = "<%= config.fetch(:database_password) %>"
11
+
12
+ final_snapshot_identifier = "<%= config.fetch(:stack_name) %>-rds-<%= config.fetch(:random_id) %>-final-snapshot"
13
+ skip_final_snapshot = false
14
+
15
+ db_subnet_group_name = aws_db_subnet_group.rds_subnet_group.name
16
+ vpc_security_group_ids = [aws_security_group.rds_security_group.id]
17
+ }
18
+
19
+ resource "aws_db_subnet_group" "rds_subnet_group" {
20
+ name = "<%= config.fetch(:stack_name) %>-rds-subnetgroup-<%= config.fetch(:random_id) %>"
21
+ subnet_ids = module.system.cluster.subnets
22
+ }
23
+
24
+ resource "aws_security_group" "rds_security_group" {
25
+ name = "<%= config.fetch(:stack_name) %>-rds-database-securitygroup-<%= config.fetch(:random_id) %>"
26
+
27
+ description = "RDS Security Group (Managed by Terraform)"
28
+ vpc_id = module.system.cluster.vpc
29
+
30
+ # Only Postgres in
31
+ ingress {
32
+ from_port = 5432
33
+ to_port = 5432
34
+ protocol = "tcp"
35
+ cidr_blocks = ["10.1.0.0/16"]
36
+ }
37
+
38
+ # Allow all outbound traffic
39
+ egress {
40
+ from_port = 0
41
+ to_port = 0
42
+ protocol = "-1"
43
+ cidr_blocks = ["0.0.0.0/0"]
44
+ }
45
+ }