Class: Subspace::Commands::Terraform
- Inherits:
-
Base
- Object
- Commander::Command
- Base
- Subspace::Commands::Terraform
show all
- Defined in:
- lib/subspace/commands/terraform.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#confirm_overwrite, #copy, #dest_dir, #gem_path, #inventory, #pass_through_params, #playbook_dir, #project_name, #project_path, #require_configuration, #set_subspace_version, #template, #template!, #template_dir
Methods included from Ansible
#ansible_command, #ansible_playbook
Constructor Details
#initialize(args, options) ⇒ Terraform
37
38
39
40
41
42
|
# File 'lib/subspace/commands/terraform.rb', line 37
def initialize(args, options)
@env = args.shift
@args = args
@options = options
run
end
|
Class Method Details
.check_aws_credentials(project_name) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/subspace/commands/terraform.rb', line 6
def self.check_aws_credentials(project_name)
ENV["AWS_ACCESS_KEY_ID"] = nil
ENV["AWS_SECRET_ACCESS_KEY"] = nil
profile = "subspace-#{project_name}"
system("aws --profile #{profile} configure list &> /dev/null ")
if $? != 0
puts "No AWS Profile '#{profile}' configured. Please enter your credentials."
system("aws --profile #{profile} configure")
system("aws --profile #{profile} configure list &> /dev/null ")
if $? != 0
puts "FATAL: could not configure aws. Please try again"
exit
end
else
puts "Using AWS Profile #{profile}"
end
true
end
|
27
28
29
30
31
32
33
34
35
|
# File 'lib/subspace/commands/terraform.rb', line 27
def self.ensure_terraform
if `terraform -v --json | jq -r .terraform_version` =~ /1\.\d+/
puts "Terraform found."
return true
else
puts "Please install terraform at least 1.1 locally"
return false
end
end
|
Instance Method Details
#run ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/subspace/commands/terraform.rb', line 44
def run
self.class.check_aws_credentials(project_name) or exit
self.class.ensure_terraform or exit
if @args.any?
terraform_command(@args.shift, *@args)
else
puts "No command specified, running plan/apply"
terraform_command("init", "-upgrade") or return
terraform_command("apply") or return
update_inventory
end
end
|