Skip to content

Commit

Permalink
Item: hitachienergy#58 Desc: Initial terraform runner commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Grudzien committed Mar 18, 2019
1 parent a2aeeec commit 670e5b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/epicli/cli/engine/EpiphanyEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from cli.engine.aws.AWSConfigBuilder import AWSConfigBuilder
from cli.modules.template_generator import TemplateGenerator

from core.src.epicli.cli.modules.terraform_runner.TerraformGenerator import TerraformRunner


class EpiphanyEngine:

Expand Down Expand Up @@ -62,6 +64,11 @@ def run(self):
terraform_output_file.write(content)

# todo run terraform
# todo set path to terraform files
tf = TerraformRunner()
tf.init()
tf.plan()
tf.apply(auto_approve=True)

# todo validate

Expand Down
36 changes: 36 additions & 0 deletions core/src/epicli/cli/modules/terraform_runner/TerraformGenerator.py
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.

0 comments on commit 670e5b4

Please sign in to comment.