-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathterraform.py
More file actions
54 lines (39 loc) · 1.12 KB
/
terraform.py
File metadata and controls
54 lines (39 loc) · 1.12 KB
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
49
50
51
52
53
54
import os
import tasks
def is_initialized(path):
"""
Check if Terraform is initialized in a given path.
"""
return os.path.exists(f"{path}/.terraform")
def init(path):
"""
Initialize Terraform in a given path.
"""
if not is_initialized(path):
return tasks.run(f"cd {path} && terraform init -no-color")
return tasks.success()
def workspace(path, workspace):
"""
Switch to a new Terraform workspace.
"""
return tasks.run(f"cd {path} && terraform workspace new {workspace} -no-color")
def apply(path):
"""
Launch Terraform and apply the changes.
"""
return tasks.run(f"cd {path} && terraform apply -auto-approve -no-color")
def refresh(path):
"""
Launch Terraform and refresh output.
"""
return tasks.run(f"cd {path} && terraform refresh")
def destroy(path):
"""
Launch Terraform and eliminate all infrastructure.
"""
return tasks.run(f"cd {path} && terraform destroy -auto-approve -no-color")
def output(path):
"""
Get Terraform output as json
"""
return tasks.run(f"cd {path} && terraform output -json")