-
Notifications
You must be signed in to change notification settings - Fork 12
/
pre-kitchen.rb
executable file
·48 lines (39 loc) · 1.21 KB
/
pre-kitchen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/ruby
require 'yaml'
@run_kitchen = true
my_vars =
[
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'TF_VAR_aws_ssh_key_id',
'TF_VAR_aws_access_key',
'TF_VAR_aws_secret_key',
'AWS_DEFAULT_REGION',
'AWS_DEFAULT_INSTANCE_TYPE',
'SSH_SG_CIDR',
]
my_vars.each do |value|
if ENV.fetch(value,nil).to_s != ''
puts "#{value} is: " + ENV.fetch(value,nil).to_s
else
@run_kitchen=false
puts "Please set #{value}"
end
end
puts "If you want to get JSON output, please set the USE_JSON = 'true'"
puts ''
puts '----------'
puts 'You are OK to run Test Kitchen' if @run_kitchen == true
puts 'Please SET the above Envrioment variables before running kitchen' if @run_kitchen == false
require 'rubygems'; require 'json';
my_vpcs = JSON.parse(%x[aws ec2 describe-vpcs]);
re = Regexp.union('false')
if my_vpcs['Vpcs'][0]['IsDefault'].to_s.match(re)
puts 'Default VPC does NOT exist'
puts ' --- '
puts ' - please use an account/region with default VPC'
puts ' - alternativelly, consider hard-coding default vpc with terraform by setting Environment Variable to your VPC (below)'
puts ' export TF_VAR_vpc_id=' + my_vpcs['Vpcs'][0]['VpcId']
else
puts 'Default VPC Exists'
end