forked from hitachienergy/epiphany
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item: hitachienergy#58 Desc: Initial terraform runner commit
- Loading branch information
Pawel Grudzien
committed
Mar 18, 2019
1 parent
a2aeeec
commit 670e5b4
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/epicli/cli/modules/terraform_runner/TerraformGenerator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import subprocess | ||
|
||
|
||
class TerraformRunner: | ||
|
||
def __init__(self): | ||
self.command = "terraform" | ||
self.apply_command = "apply" | ||
self.destroy_command = "destroy" | ||
self.plan_command = "plan" | ||
self.init_command = "init" | ||
|
||
def apply(self, auto_approve): | ||
self.run(self.command, self.apply_command, auto_approve=auto_approve) | ||
|
||
def destroy(self, auto_approve): | ||
self.run(self.command, self.destroy_command, auto_approve=auto_approve) | ||
|
||
def plan(self): | ||
self.run(self.command, self.plan_command) | ||
|
||
def init(self): | ||
self.run(self.command, self.init_command) | ||
|
||
@staticmethod | ||
def run(command, terraform_command, auto_approve=False): | ||
|
||
if auto_approve: | ||
status_run = subprocess.run([command, terraform_command, "--auto-approve"]) | ||
else: | ||
status_run = subprocess.run([command, terraform_command]) | ||
|
||
if status_run.returncode != 0: | ||
print(command + " " + terraform_command + " run failed") | ||
else: | ||
print(command + " " + terraform_command + " run successfully.") |
Empty file.