scout-camp 0.1.1
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 +7 -0
- data/.vimproject +81 -0
- data/LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/bin/scout-camp +5 -0
- data/lib/scout/aws/s3.rb +157 -0
- data/lib/scout/offsite/exceptions.rb +9 -0
- data/lib/scout/offsite/ssh.rb +175 -0
- data/lib/scout/offsite/step.rb +100 -0
- data/lib/scout/offsite/sync.rb +55 -0
- data/lib/scout/offsite.rb +3 -0
- data/lib/scout/terraform_dsl/deployment.rb +285 -0
- data/lib/scout/terraform_dsl/util.rb +100 -0
- data/lib/scout/terraform_dsl.rb +317 -0
- data/lib/scout-camp.rb +6 -0
- data/scout_commands/offsite +30 -0
- data/scout_commands/terraform/add +78 -0
- data/scout_commands/terraform/apply +31 -0
- data/scout_commands/terraform/destroy +31 -0
- data/scout_commands/terraform/list +36 -0
- data/scout_commands/terraform/remove +39 -0
- data/scout_commands/terraform/status +33 -0
- data/share/terraform/aws/bucket/main.tf +8 -0
- data/share/terraform/aws/bucket/output.tf +3 -0
- data/share/terraform/aws/bucket/variables.tf +4 -0
- data/share/terraform/aws/cluster/main.tf +66 -0
- data/share/terraform/aws/cluster/output.tf +9 -0
- data/share/terraform/aws/cluster/variables.tf +49 -0
- data/share/terraform/aws/host/locals.tf +15 -0
- data/share/terraform/aws/host/main.tf +22 -0
- data/share/terraform/aws/host/output.tf +9 -0
- data/share/terraform/aws/host/variables.tf +67 -0
- data/share/terraform/aws/lambda/main.tf +40 -0
- data/share/terraform/aws/lambda/variables.tf +23 -0
- data/share/terraform/aws/provider/data.tf +35 -0
- data/share/terraform/aws/provider/output.tf +16 -0
- data/test/scout/aws/test_s3.rb +82 -0
- data/test/scout/offsite/test_ssh.rb +15 -0
- data/test/scout/offsite/test_step.rb +33 -0
- data/test/scout/offsite/test_sync.rb +36 -0
- data/test/scout/test_terraform_dsl.rb +519 -0
- data/test/test_helper.rb +19 -0
- metadata +99 -0
@@ -0,0 +1,317 @@
|
|
1
|
+
require_relative 'terraform_dsl/util'
|
2
|
+
require_relative 'terraform_dsl/deployment'
|
3
|
+
require 'scout-gear'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# Objects of this class contain the elements that will form
|
7
|
+
# a terraform deployment configuration
|
8
|
+
class TerraformDSL
|
9
|
+
|
10
|
+
attr_accessor :elements, :modules, :name, :processed_elements, :processed_custom_files
|
11
|
+
|
12
|
+
# Module objects hold the identity of a module and
|
13
|
+
# its :name, and can be used to create
|
14
|
+
# references to its outputs to pass as inputs for
|
15
|
+
# another module
|
16
|
+
class Module
|
17
|
+
|
18
|
+
attr_accessor :name, :type, :deployment
|
19
|
+
|
20
|
+
# Output objects are references to a Module output
|
21
|
+
# that can be used as parameters for other modules
|
22
|
+
# inputs
|
23
|
+
class Output
|
24
|
+
|
25
|
+
attr_accessor :module, :name
|
26
|
+
|
27
|
+
# Create an Output object
|
28
|
+
#
|
29
|
+
# @param mod [String] module template name
|
30
|
+
# @param name [String] instance name
|
31
|
+
def initialize(mod, name)
|
32
|
+
@module = mod
|
33
|
+
@name = name
|
34
|
+
end
|
35
|
+
|
36
|
+
# Callback to produce the json content when we serialize
|
37
|
+
# variable values. It becomes a reference to a Module
|
38
|
+
# output variable
|
39
|
+
#
|
40
|
+
# @param args [Array] Extra arguments to to_json, not used
|
41
|
+
# @return [String] A reference of an output for terraform
|
42
|
+
# (e.g.module.<modulename>.<name>)
|
43
|
+
def to_json(*_args)
|
44
|
+
['module', @module, @name].join('.')
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create a new Module
|
50
|
+
#
|
51
|
+
# @param name [String] instance name
|
52
|
+
# @param type [String] module template name
|
53
|
+
def initialize(name, type, deployment)
|
54
|
+
@name = name
|
55
|
+
@type = type
|
56
|
+
@deployment = deployment
|
57
|
+
end
|
58
|
+
|
59
|
+
# Construct output variable references to use on templates. They
|
60
|
+
# will be serialized when used in templates
|
61
|
+
#
|
62
|
+
# @param output [String] the name of the output
|
63
|
+
# @return [Output] An output variable for Terraform templates
|
64
|
+
def method_missing(output)
|
65
|
+
Output.new(@name, output)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Any missing method call can be the name of an output
|
69
|
+
def respond_to_missing?(_method_name, _include_private = false)
|
70
|
+
true
|
71
|
+
end
|
72
|
+
|
73
|
+
# Callback to produce the json content when we serialize
|
74
|
+
# variable values. It becomes a reference to a Module itself,
|
75
|
+
# and can be used in depends_on statements
|
76
|
+
#
|
77
|
+
# @param args [Array] Extra arguments to to_json, not used
|
78
|
+
# @return [String] A reference to a module in Terraform format
|
79
|
+
# (e.g. module.<modulename>)
|
80
|
+
def to_json(*_args)
|
81
|
+
['module', @name].join('.')
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
MODULES_DIR = Scout.share.terraform
|
87
|
+
ANSIBLE_DIR = Scout.share.ansible
|
88
|
+
WORK_DIR = Scout.var.terraform
|
89
|
+
|
90
|
+
# Create a new terraform deployment configuration
|
91
|
+
#
|
92
|
+
# @param modules [String] directory containing module templates
|
93
|
+
def initialize(modules = MODULES_DIR)
|
94
|
+
@modules = modules
|
95
|
+
@elements = []
|
96
|
+
@custom_files = []
|
97
|
+
@variables = {}
|
98
|
+
@element_files = []
|
99
|
+
end
|
100
|
+
|
101
|
+
# Add a new module instance
|
102
|
+
#
|
103
|
+
# @param provider [String] first level of template organization subdirectory
|
104
|
+
# @param module_name [String] subdirectory containing the module to use
|
105
|
+
# @param variables [Hash] values for variables in the module template, and
|
106
|
+
# :name to name the module instance, and :outputs to define the module
|
107
|
+
# variables that will become deployment outputs
|
108
|
+
# @return [Module] A module object used as a reference in Terraform templates
|
109
|
+
def add(provider = nil, module_name = nil, variables = {})
|
110
|
+
variables[:name] ||= variables["name"] ||= [provider, module_name].join('_')
|
111
|
+
module_directory = @modules[provider][module_name]
|
112
|
+
@elements << [provider, module_name, module_directory, variables]
|
113
|
+
@variables.merge!(variables)
|
114
|
+
Module.new(variables[:name], module_name, self)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Terraform text that describes variables passed to a given module instance
|
118
|
+
#
|
119
|
+
# @param variables [Hash] module variables and their values, :name and
|
120
|
+
# :outputs are ignored as they are not module variables themselves
|
121
|
+
#
|
122
|
+
# @return [String] text to include inside the terraform module definition
|
123
|
+
# containing the variable assignments
|
124
|
+
def variable_block(variables)
|
125
|
+
variables.each_with_object([]) do |p, acc|
|
126
|
+
name, value = p
|
127
|
+
next acc if name.to_s == 'name'
|
128
|
+
next acc if name.to_s == 'outputs'
|
129
|
+
|
130
|
+
if value.is_a?(String) && (m = value.match(/^module\.(.*)\.(.*)/))
|
131
|
+
value = Module::Output.new m[1], m[2]
|
132
|
+
end
|
133
|
+
|
134
|
+
acc << " #{name} = #{value.to_json}"
|
135
|
+
end * "\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
# Populate a directory with the terraform templates corresponding to the
|
139
|
+
# defined elements
|
140
|
+
#
|
141
|
+
# @param dir [String] directory from which to manage the deployment
|
142
|
+
def main(dir)
|
143
|
+
@elements.each do |info|
|
144
|
+
_provider, _module_name, template, variables = info
|
145
|
+
|
146
|
+
template = template.find
|
147
|
+
# Add an additional / to mark the base_path of the module directory and
|
148
|
+
# allow modules to reference other modules relatively
|
149
|
+
template = template.split('/').tap {|l| l[-2] = '/'+l[-2] } * '/'
|
150
|
+
|
151
|
+
name = variables[:name]
|
152
|
+
|
153
|
+
text =<<~EOF
|
154
|
+
module "#{name}" {
|
155
|
+
source = "#{template}"
|
156
|
+
#{variable_block(variables)}
|
157
|
+
}
|
158
|
+
EOF
|
159
|
+
|
160
|
+
element_file = [_module_name, name.to_s.sub(/_#{_module_name}$/,'')] * "."
|
161
|
+
|
162
|
+
# rubocop: disable Layout/LineLength
|
163
|
+
raise Deployment::TerraformException,
|
164
|
+
"Warning: element file '#{element_file}' already exists, consider renaming it by using the parameter ':name'" if @element_files.include?(element_file)
|
165
|
+
# rubocop: enable Layout/LineLength
|
166
|
+
|
167
|
+
@element_files << element_file
|
168
|
+
|
169
|
+
Open.write(dir[element_file + '.tf'], text)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Add a terraform file with custom content. Used only
|
174
|
+
# to support defining non Hashicorp provider configuration
|
175
|
+
#
|
176
|
+
# @param file [String] name of the file
|
177
|
+
# @param text [String] content of the file
|
178
|
+
def custom(file, text)
|
179
|
+
@custom_files << [file, text]
|
180
|
+
nil
|
181
|
+
end
|
182
|
+
|
183
|
+
# Add a provider template file without using modules.
|
184
|
+
# Defining providers in modules is problematic when providers
|
185
|
+
# are not managed by Hashicorp. Hopefully we can
|
186
|
+
# find a fix for this soon.
|
187
|
+
#
|
188
|
+
# @param name [String] name of the provider
|
189
|
+
# @param variables [Hash] variables for the provider:
|
190
|
+
# :source & :version
|
191
|
+
# @return [nil, Module] If a Module is found at <modules_dir>/<name>/provider
|
192
|
+
# it returns it
|
193
|
+
def provider(name, variables = {})
|
194
|
+
variables = variables.dup
|
195
|
+
|
196
|
+
if Open.exist?(@modules[name].provider)
|
197
|
+
provider = add name, :provider
|
198
|
+
else
|
199
|
+
provider = nil
|
200
|
+
end
|
201
|
+
|
202
|
+
source = variables.delete :source
|
203
|
+
version = variables.delete :version
|
204
|
+
|
205
|
+
text = ''
|
206
|
+
|
207
|
+
if source
|
208
|
+
if version
|
209
|
+
text +=<<~EOF
|
210
|
+
terraform {
|
211
|
+
required_providers {
|
212
|
+
#{name} = {
|
213
|
+
source = "#{source}"
|
214
|
+
version = "#{version}"
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
EOF
|
219
|
+
else
|
220
|
+
text +=<<~EOF
|
221
|
+
terraform {
|
222
|
+
required_providers {
|
223
|
+
#{name} = {
|
224
|
+
source = "#{source}"
|
225
|
+
}
|
226
|
+
}
|
227
|
+
}
|
228
|
+
EOF
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
text +=<<~EOF
|
233
|
+
provider "#{name}" {
|
234
|
+
#{variable_block(variables)}
|
235
|
+
}
|
236
|
+
EOF
|
237
|
+
|
238
|
+
element_file = ['provider_config', name.to_s].join('.')
|
239
|
+
|
240
|
+
custom(element_file, text)
|
241
|
+
|
242
|
+
provider
|
243
|
+
end
|
244
|
+
|
245
|
+
# Populate a directory with the terraform templates corresponding to the
|
246
|
+
# custom defined elements
|
247
|
+
#
|
248
|
+
# @param dir [String] directory from which to manage the deployment
|
249
|
+
def custom_files(dir)
|
250
|
+
@custom_files.each do |element_file, text|
|
251
|
+
Open.write(dir[element_file + '.tf'], text)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
# Populate a directory with the terraform templates corresponding to the
|
256
|
+
# defined element outputs variables
|
257
|
+
#
|
258
|
+
# @param dir [String] directory from which to manage the deployment
|
259
|
+
def outputs(dir)
|
260
|
+
@elements.each do |info|
|
261
|
+
_provider, module_name, template, variables = info
|
262
|
+
outputs = variables[:outputs]
|
263
|
+
module_outputs = TerraformDSL.module_outputs(template)
|
264
|
+
outputs = module_outputs.keys if outputs.to_s == 'all'
|
265
|
+
next unless outputs && outputs.any?
|
266
|
+
|
267
|
+
name = variables[:name]
|
268
|
+
|
269
|
+
outputs = outputs.collect do |o|
|
270
|
+
(o.is_a?(String) || o.is_a?(Symbol)) && o.to_s == 'all' ? module_outputs.keys : o
|
271
|
+
end.flatten.uniq if outputs.is_a?(Array)
|
272
|
+
|
273
|
+
text = ''
|
274
|
+
outputs.each do |output, output_rename = nil|
|
275
|
+
output, output_rename = output.collect.first if output.is_a?(Hash)
|
276
|
+
|
277
|
+
output_rename = output if output_rename.nil?
|
278
|
+
|
279
|
+
description = module_outputs[output.to_s][:description]
|
280
|
+
description ||= "Value of #{output} from module #{name} (type #{module_name})"
|
281
|
+
|
282
|
+
text +=<<~EOF
|
283
|
+
output "#{name}_#{output_rename}"{
|
284
|
+
description = "#{description}"
|
285
|
+
value = module.#{name}.#{output}
|
286
|
+
}
|
287
|
+
EOF
|
288
|
+
end
|
289
|
+
|
290
|
+
element_file = [module_name, name.to_s] * "."
|
291
|
+
|
292
|
+
Open.write(dir[element_file + '.outputs.tf'], text)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
# Populate a directory all the necessary templates: modules, outputs,
|
297
|
+
# and custom
|
298
|
+
#
|
299
|
+
# @param dir [String] directory from which to manage the deployment. If none
|
300
|
+
# provided a unique one will be generated based on a md5 digest of
|
301
|
+
# the elements defined
|
302
|
+
def config(dir = nil)
|
303
|
+
dir = WORK_DIR[TerraformDSL.obj2digest(@elements)] if dir.nil?
|
304
|
+
Open.mkdir dir
|
305
|
+
main(dir)
|
306
|
+
outputs(dir)
|
307
|
+
custom_files(dir)
|
308
|
+
@processed_elements ||= []
|
309
|
+
@processed_elements.concat(@elements)
|
310
|
+
@processed_custom_files ||= []
|
311
|
+
@processed_custom_files.concat(@custom_files)
|
312
|
+
@elements = []
|
313
|
+
@custom_files = []
|
314
|
+
dir
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
data/lib/scout-camp.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
require 'scout/offsite'
|
5
|
+
|
6
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
7
|
+
|
8
|
+
options = SOPT.setup <<EOF
|
9
|
+
|
10
|
+
Description of the tool
|
11
|
+
|
12
|
+
$ #{$0} [<options>] <where> <command> ... -- [<protected options>]
|
13
|
+
|
14
|
+
Run a command offsite. Use -- to make sure options reach the offsite
|
15
|
+
|
16
|
+
-h--help Print this help
|
17
|
+
EOF
|
18
|
+
if options[:help]
|
19
|
+
if defined? scout_usage
|
20
|
+
scout_usage
|
21
|
+
else
|
22
|
+
puts SOPT.doc
|
23
|
+
end
|
24
|
+
exit 0
|
25
|
+
end
|
26
|
+
|
27
|
+
where = ARGV.shift
|
28
|
+
command = ARGV.shift
|
29
|
+
|
30
|
+
puts SSHLine.command(where, command, ARGV)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
Add a new deployment
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <name>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
-w--workflows* Workflows to provision
|
15
|
+
EOF
|
16
|
+
if options[:help]
|
17
|
+
if defined? scout_usage
|
18
|
+
scout_usage
|
19
|
+
else
|
20
|
+
puts SOPT.doc
|
21
|
+
end
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
|
25
|
+
name = ARGV.shift
|
26
|
+
raise MissingParameterException, :name if name.nil?
|
27
|
+
|
28
|
+
deployments = Scout.var.deployments.glob_all("*").collect(&:basename)
|
29
|
+
raise "Deployment clash" if deployments.include? name
|
30
|
+
dir = Scout.var.deployments[name]
|
31
|
+
|
32
|
+
IndiferentHash.add_defaults options, workflows: '', dependencies: 'scout-gear'
|
33
|
+
|
34
|
+
workflows = options[:workflows].split(",")
|
35
|
+
dependencies = options[:dependencies].split(",")
|
36
|
+
|
37
|
+
code =<<-EOF
|
38
|
+
def lambda_handler(event:, context:)
|
39
|
+
require 'scout/workflow'
|
40
|
+
|
41
|
+
wf = Workflow.require_workflow event["workflow"]
|
42
|
+
job = wf.job(event["task_name"], event["jobname"], event["inputs"])
|
43
|
+
id = job.short_path
|
44
|
+
id
|
45
|
+
end
|
46
|
+
EOF
|
47
|
+
|
48
|
+
def lambda_package(dependencies, workflows, code)
|
49
|
+
TmpFile.with_path do |dir|
|
50
|
+
dir["lambda_function.rb"].write code
|
51
|
+
dir["Gemfile"].write "source 'https://rubygems.org'\n" + dependencies.collect{|d| "gem '#{d}'"}*"\n"
|
52
|
+
workflows.each do |workflow|
|
53
|
+
Open.mkdir dir[".scout"].workflows
|
54
|
+
Open.cp Scout.workflows[workflow], dir[".scout"].workflows[workflow]
|
55
|
+
end
|
56
|
+
Misc.in_dir dir do
|
57
|
+
`bundle config set path 'vendor/bundle'`
|
58
|
+
`bundle install`
|
59
|
+
`rm -Rf vendor/bundle/ruby/*/cache`
|
60
|
+
`rm -Rf vendor/bundle/ruby/*/gems/RubyInline*`
|
61
|
+
TmpFile.with_file nil, extension: :zip do |zip|
|
62
|
+
`zip -r "#{zip}" vendor/bundle lambda_function.rb .scout`
|
63
|
+
yield zip
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
require 'aws-sdk'
|
70
|
+
lambda_package dependencies, workflows, code do |file|
|
71
|
+
terraform = TerraformDSL.new
|
72
|
+
filename = 'lambda_package.zip'
|
73
|
+
Open.cp file, dir[filename]
|
74
|
+
terraform.add :aws, :lambda, function_name: "ScoutJob", filename: filename, environment_variables: {HOME: '.'}
|
75
|
+
terraform.config dir
|
76
|
+
end
|
77
|
+
|
78
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
Work with deployment
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <name>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
EOF
|
15
|
+
if options[:help]
|
16
|
+
if defined? scout_usage
|
17
|
+
scout_usage
|
18
|
+
else
|
19
|
+
puts SOPT.doc
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
name = ARGV.shift
|
25
|
+
raise MissingParameterException, :name if name.nil?
|
26
|
+
|
27
|
+
dir = Scout.var.deployments.glob_all(name).first
|
28
|
+
|
29
|
+
deployment = TerraformDSL::Deployment.new dir
|
30
|
+
deployment.apply
|
31
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
Work with deployment
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <name>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
EOF
|
15
|
+
if options[:help]
|
16
|
+
if defined? scout_usage
|
17
|
+
scout_usage
|
18
|
+
else
|
19
|
+
puts SOPT.doc
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
name = ARGV.shift
|
25
|
+
raise MissingParameterException, :name if name.nil?
|
26
|
+
|
27
|
+
dir = Scout.var.deployments.glob_all(name).first
|
28
|
+
|
29
|
+
deployment = TerraformDSL::Deployment.new dir
|
30
|
+
deployment.destroy
|
31
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
List all deployments
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <filename>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
EOF
|
15
|
+
if options[:help]
|
16
|
+
if defined? scout_usage
|
17
|
+
scout_usage
|
18
|
+
else
|
19
|
+
puts SOPT.doc
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
deployments = Scout.var.deployments.glob_all("*")
|
25
|
+
|
26
|
+
deployments.each do |dir|
|
27
|
+
name = File.basename dir
|
28
|
+
deployment = TerraformDSL::Deployment.new dir
|
29
|
+
active = deployment.provisioned_elements.any?
|
30
|
+
|
31
|
+
if active
|
32
|
+
puts Log.color(:title, name ) + "\t" + dir + "\t" + "Active"
|
33
|
+
else
|
34
|
+
puts Log.color(:title, name) + "\t" + dir
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
Work with deployment
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <name>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
EOF
|
15
|
+
if options[:help]
|
16
|
+
if defined? scout_usage
|
17
|
+
scout_usage
|
18
|
+
else
|
19
|
+
puts SOPT.doc
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
name = ARGV.shift
|
25
|
+
raise MissingParameterException, :name if name.nil?
|
26
|
+
|
27
|
+
dir = Scout.var.deployments.glob_all(name).first
|
28
|
+
|
29
|
+
begin
|
30
|
+
deployment = TerraformDSL::Deployment.new dir
|
31
|
+
deployment.destroy
|
32
|
+
rescue
|
33
|
+
end
|
34
|
+
|
35
|
+
if deployment.provisioned_elements.empty?
|
36
|
+
Open.rm_rf dir
|
37
|
+
else
|
38
|
+
"Not removed"
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'scout'
|
4
|
+
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
6
|
+
|
7
|
+
options = SOPT.setup <<EOF
|
8
|
+
|
9
|
+
Work with deployment
|
10
|
+
|
11
|
+
$ #{$0} [<options>] <name>
|
12
|
+
|
13
|
+
-h--help Print this help
|
14
|
+
EOF
|
15
|
+
if options[:help]
|
16
|
+
if defined? scout_usage
|
17
|
+
scout_usage
|
18
|
+
else
|
19
|
+
puts SOPT.doc
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
name = ARGV.shift
|
25
|
+
raise MissingParameterException, :name if name.nil?
|
26
|
+
|
27
|
+
dir = Scout.var.deployments.glob_all(name).first
|
28
|
+
|
29
|
+
deployment = TerraformDSL::Deployment.new dir
|
30
|
+
deployment.provisioned_elements.each do |element|
|
31
|
+
ppp deployment.element_state(element)
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
locals {
|
2
|
+
cidr_block = "${var.cidr_block_base}/${var.cidr_block_mask}"
|
3
|
+
cidr_block_dest = "0.0.0.0/0"
|
4
|
+
|
5
|
+
}
|
6
|
+
|
7
|
+
resource "aws_vpc" "this" {
|
8
|
+
cidr_block = local.cidr_block
|
9
|
+
|
10
|
+
tags = {
|
11
|
+
Name = var.cidr_nametag
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
resource "aws_subnet" "this" {
|
16
|
+
vpc_id = aws_vpc.this.id
|
17
|
+
cidr_block = local.cidr_block
|
18
|
+
|
19
|
+
map_public_ip_on_launch = var.map_public_ip_on_launch
|
20
|
+
|
21
|
+
tags = {
|
22
|
+
Name = var.subnet_nametag
|
23
|
+
}
|
24
|
+
|
25
|
+
availability_zone = var.availability_zone
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
resource "aws_internet_gateway" "this" {
|
30
|
+
vpc_id = aws_vpc.this.id
|
31
|
+
|
32
|
+
tags = {
|
33
|
+
Name = var.gateway_nametag
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
resource "aws_route" "this" {
|
38
|
+
route_table_id = aws_vpc.this.main_route_table_id
|
39
|
+
destination_cidr_block = local.cidr_block_dest
|
40
|
+
gateway_id = aws_internet_gateway.this.id
|
41
|
+
}
|
42
|
+
|
43
|
+
resource "aws_security_group" "this" {
|
44
|
+
name = "allow_all"
|
45
|
+
description = "Allow all traffic"
|
46
|
+
vpc_id = aws_vpc.this.id
|
47
|
+
|
48
|
+
ingress {
|
49
|
+
from_port = 0
|
50
|
+
to_port = 0
|
51
|
+
protocol = "-1"
|
52
|
+
cidr_blocks = [local.cidr_block_dest]
|
53
|
+
}
|
54
|
+
|
55
|
+
egress {
|
56
|
+
from_port = 0
|
57
|
+
to_port = 0
|
58
|
+
protocol = "-1"
|
59
|
+
cidr_blocks = [local.cidr_block_dest]
|
60
|
+
}
|
61
|
+
|
62
|
+
tags = {
|
63
|
+
Name = var.security_group_nametag
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|