Skip to content

Commit a6edd7d

Browse files
howbazaarkapilt
andauthored
for library usage of tfrunner Make plan=False work. (#73)
Co-authored-by: Kapil Thangavelu <[email protected]>
1 parent bec746d commit a6edd7d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pytest_terraform/tf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def __init__(
6464

6565
def apply(self, plan=True):
6666
"""run terraform apply"""
67-
if plan is True:
67+
if plan:
6868
plan_path = os.path.join(self.work_dir, "tfplan")
6969
self.plan(plan_path)
7070
apply_args = self._get_cmd_args("apply", plan=plan_path)
71-
elif plan:
71+
else:
7272
apply_args = self._get_cmd_args("apply", plan="")
7373
try:
7474
self._run_cmd(apply_args)

tests/test_terraform.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def test_tf_statejson_update_bad():
151151

152152

153153
@pytest.mark.skipif(not shutil.which("terraform"), reason="Terraform binary missing")
154-
def test_tf_runner(testdir, tmpdir):
154+
@pytest.mark.parametrize("plan", (True, False))
155+
def test_tf_runner(testdir, tmpdir, plan):
155156
# ** requires network access to install plugin **
156157
with open(tmpdir.join("resources.tf"), "w") as fh:
157158
fh.write(
@@ -165,7 +166,7 @@ def test_tf_runner(testdir, tmpdir):
165166

166167
trunner = tf.TerraformRunner(tmpdir.strpath, tf_bin=shutil.which("terraform"))
167168
trunner.init()
168-
state = trunner.apply()
169+
state = trunner.apply(plan=plan)
169170
assert state.get("foo")["content"] == "foo!"
170171
with open(tmpdir.join("foo.bar")) as fh:
171172
assert fh.read() == "foo!"

0 commit comments

Comments
 (0)