Class: Terraspace::Terraform::Tfc::Workspace
Instance Method Summary
collapse
#http
#api, #backend, #build, #remote, #workspace_name
#logger
Methods inherited from CLI::Base
#initialize
#pretty_path, #pretty_time
Instance Method Details
#create ⇒ Object
27
28
29
30
31
|
# File 'lib/terraspace/terraform/tfc/workspace.rb', line 27
def create
build
return unless api
api.workspace.create
end
|
#destroy ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/terraspace/terraform/tfc/workspace.rb', line 33
def destroy
build
return unless api
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.workspace.destroy
end
|
#init ⇒ Object
23
24
25
|
# File 'lib/terraspace/terraform/tfc/workspace.rb', line 23
def init
Terraspace::CLI::Init.new(@options).run
end
|
#list ⇒ Object
List will not have @mod set.
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/terraspace/terraform/tfc/workspace.rb', line 9
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
|
#sure? ⇒ Boolean
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/terraspace/terraform/tfc/workspace.rb', line 46
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
|