Class: Terraspace::Terraform::Cloud::Workspace
Instance Method Summary
collapse
#http
#logger
Methods inherited from CLI::Base
#initialize
Methods included from Util
#pretty_path
Methods included from Util::Sh
#sh
Instance Method Details
#build ⇒ Object
49
50
51
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 49
def build
Terraspace::Builder.new(@options).run
end
|
#destroy ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 35
def destroy
build
return unless backend.dig('remote','workspaces') api = Terraspace::Terraform::Api.new(@mod, remote)
workspace = api.workspace(exit_on_fail: false)
unless workspace
logger.info "Workspace #{workspace_name} not found for #{@mod.type}: #{@mod.name}"
exit 0
end
sure?
logger.info "Destroying workspace #{workspace_name}"
api.destroy_workspace
end
|
#init ⇒ Object
31
32
33
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 31
def init
Terraspace::CLI::Init.new(@options.merge(calling_command: "cloud-setup")).run
end
|
#list ⇒ Object
List will not have @mod set.
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 8
def list
@mod = Terraspace::CLI::Build::Placeholder.new(@options).build
unless remote && remote['organization']
logger.info "ERROR: There was no organization found. Are you sure you configured backend.tf with it?".color(:red)
exit 1
end
org = remote['organization']
payload = http.get("/organizations/#{org}/workspaces") names = payload['data'].map { |i| i['attributes']['name'] }.sort
logger.info "Workspaces for #{org}:"
logger.info names.join("\n")
end
|
#remote ⇒ Object
57
58
59
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 57
def remote
backend["remote"]
end
|
#setup ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 22
def setup
build
unless backend.dig('remote','workspaces') logger.info "ERROR: Workspace not configured in backend.tf"
exit 1
end
init
end
|
#sure? ⇒ Boolean
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 66
def sure?
message = <<~EOL.chop + " " You are about to delete the workspace: #{workspace_name}
All variables, settings, run history, and state history will be removed.
This cannot be undone.
This will NOT remove any infrastructure managed by this workspace.
If needed, destroy the infrastructure prior to deleting the workspace with:
terraspace down #{@mod.name}
This will delete the workspace: #{workspace_name}.
Are you sure? (y/N)
EOL
if @options[:yes]
sure = 'y'
else
print message
sure = $stdin.gets
end
unless sure =~ /^y/
puts "Whew! Exiting."
exit 0
end
end
|
#workspace_name ⇒ Object
53
54
55
|
# File 'lib/terraspace/terraform/cloud/workspace.rb', line 53
def workspace_name
remote['workspaces']['name']
end
|