-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
47 lines (40 loc) · 1.55 KB
/
Rakefile
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
require 'rake'
require 'semantic'
inputs = {
'stack_item_label' => 'expl-tst',
'stack_item_fullname' => 'Example Stack',
'vpc_id' => 'vpc-xxxxxx',
'region' => 'us-east-1',
'subnets' => 'subnet-111111,subnet-222222',
'instance_type' => 't2.small',
'key_name' => 'example',
'route_cidrs' => '10.10.0.0/25,10.10.0.128/25,10.10.4.0/25,10.10.4.128/25',
's3_bucket' => 'openvpn-certs',
's3_bucket_prefix' => '20160603',
'openvpn_host' => 'vpn.example.io'
}
task :default => :verify
desc "Verify the stack"
task :verify do
vars = []
inputs.each() do |var, value|
vars.push("-var '#{var}=\"#{value}\"'")
end
['server','cert-gen'].each do |stack|
task_args = {:stack => stack, :args => vars.join(' ')}
Rake::Task['clean'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values))
Rake::Task['plan'].execute(Rake::TaskArguments.new(task_args.keys, task_args.values))
end
end
desc "Remove existing local state if present"
task :clean, [:stack] do |t, args|
sh "cd examples/#{args['stack']} && rm -fr .terraform *.tfstate*"
terraform_version = `terraform version`.split("\n", 2)[0].gsub('Terraform v','')
if Semantic::Version.new(terraform_version) >= Semantic::Version.new("0.10.0")
sh "cd examples/#{args['stack']} && terraform init"
end
end
desc "Create execution plan"
task :plan, [:stack, :args] do |t, args|
sh "cd examples/#{args['stack']} && terraform get && terraform plan -module-depth=-1 -input=false #{args['args']}"
end