Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration.tfvars #26

Merged
merged 3 commits into from
Dec 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.8.4
current_version = 0.9.0
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_requirements(req_file):
if __name__ == "__main__":
setup(
name="terraform-ci",
version="0.8.4",
version="0.9.0",
description="Terraform CI runs terraform in Travis-CI",
long_description=dedent(
"""
Expand Down
23 changes: 16 additions & 7 deletions terraform_ci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import boto3


__version__ = "0.8.4"
__version__ = "0.9.0"

DEFAULT_TERRAFORM_VARS = ".env/tf_env.json"
LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -393,10 +393,12 @@ def setup_logging(logger, debug=False): # pragma: no cover

def terraform_output(path):
"""
Run terraform output and return the json results as a dict
Run terraform output and return the json results as a dict.

:param path: Path to directory with terraform module.
:type path: str
:return: dict from terraform output
:rtype: dict
"""
cmd = "terraform output -json"
ret, cout, cerr = execute(cmd.split(), stdout=PIPE, stderr=None, cwd=path)
Expand All @@ -406,7 +408,12 @@ def terraform_output(path):


@contextmanager
def terraform_apply(path, destroy_after=True, json_output=False):
def terraform_apply(
path, # pylint: disable=bad-continuation
destroy_after=True, # pylint: disable=bad-continuation
json_output=False, # pylint: disable=bad-continuation
var_file="configuration.tfvars", # pylint: disable=bad-continuation
):
"""
Run terraform init and apply, then return a generator.
If destroy_after is True, run terraform destroy afterwards.
Expand All @@ -417,6 +424,8 @@ def terraform_apply(path, destroy_after=True, json_output=False):
:type destroy_after: bool
:param json_output: Yield terraform output result as a dict (available in the context)
:type json_output: bool
:param var_file: Path to a file with terraform variables.
:type var_file: str
:return: If json_output is true then yield the result from terraform_output otherwise nothing.
Use it in the ``with`` block.
:raise CalledProcessError: if either of terraform commands (except ``terraform destroy``)
Expand All @@ -426,8 +435,8 @@ def terraform_apply(path, destroy_after=True, json_output=False):
"terraform init -no-color",
"terraform get -update=true -no-color",
(
"terraform apply -var-file=configuration.tfvars -input=false "
"-auto-approve"
"terraform apply -var-file={var_file} -input=false "
"-auto-approve".format(var_file=var_file)
),
]
try:
Expand All @@ -445,8 +454,8 @@ def terraform_apply(path, destroy_after=True, json_output=False):
finally:
if destroy_after:
execute(
"terraform destroy -var-file=configuration.tfvars "
"-input=false -auto-approve".split(),
"terraform destroy -var-file={var_file} "
"-input=false -auto-approve".format(var_file=var_file).split(),
stdout=None,
stderr=None,
cwd=path,
Expand Down