From d9158ac942e639487b05c152259a22cf9022d937 Mon Sep 17 00:00:00 2001 From: Iain Learmonth Date: Mon, 28 Nov 2022 19:03:24 +0000 Subject: [PATCH] feat(automate): make temporary working dir optional --- app/cli/automate.py | 13 ++++++++++--- app/terraform/proxy/cloudfront.py | 8 +++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/cli/automate.py b/app/cli/automate.py index 55ea611..466d6d1 100644 --- a/app/cli/automate.py +++ b/app/cli/automate.py @@ -1,5 +1,6 @@ import datetime import logging +import os import shutil import tempfile from traceback import TracebackException @@ -108,8 +109,12 @@ def run_job(job_cls: Type[BaseAutomation], *, automation.state = AutomationState.RUNNING db.session.commit() try: - job: BaseAutomation = job_cls() - tempdir_path = tempfile.mkdtemp() + if 'TERRAFORM_DIRECTORY' in app.config: + working_dir = os.path.join(app.config['TERRAFORM_DIRECTORY'], + job_cls.short_name or job_cls.__class__.__name__.lower()) + else: + working_dir = tempfile.mkdtemp() + job: BaseAutomation = job_cls(working_dir) success, logs = job.automate() # We want to catch any and all exceptions that would cause problems here, because # the error handling process isn't really handling the error, but rather causing it @@ -123,7 +128,9 @@ def run_job(job_cls: Type[BaseAutomation], *, automation.state = AutomationState.IDLE automation.next_run = datetime.datetime.utcnow() + datetime.timedelta( minutes=getattr(job, "frequency", 7)) - shutil.rmtree(tempdir_path) + if not 'TERRAFORM_DIRECTORY' in app.config: + # We used a temporary working directory + shutil.rmtree(working_dir) else: automation.state = AutomationState.ERROR automation.enabled = False diff --git a/app/terraform/proxy/cloudfront.py b/app/terraform/proxy/cloudfront.py index f5396cf..38ae9df 100644 --- a/app/terraform/proxy/cloudfront.py +++ b/app/terraform/proxy/cloudfront.py @@ -19,9 +19,7 @@ class ProxyCloudfrontAutomation(ProxyAutomation): "rfc2136_nameserver", "rfc2136_tsig_key", "rfc2136_tsig_secret", - "smart_zone", - "maxmind_account_id", - "maxmind_license_key" + "smart_zone" ] template = """ @@ -30,10 +28,10 @@ class ProxyCloudfrontAutomation(ProxyAutomation): required_providers { acme = { source = "vancluever/acme" - version = "~> 2.8.0" + version = "~> 2.11.0" } aws = { - version = "~> 4.4.0" + version = "~> 4.41.0" } dns = { version = "~> 3.2.3"