diff --git a/src/main/python/ddadevops/application/terraform_service.py b/src/main/python/ddadevops/application/terraform_service.py index 37687f1..240356b 100644 --- a/src/main/python/ddadevops/application/terraform_service.py +++ b/src/main/python/ddadevops/application/terraform_service.py @@ -37,8 +37,10 @@ class TerraformService: self.file_api.cp("*.tfvars", devops.build_path(), check=False) self.file_api.cp_recursive("scripts", devops.build_path(), check=False) - def start_tf_backend_git_daemon(self): - self.tf_backend_git_api.start() + def start_tf_backend_git_daemon(self, devops: Devops): + terraform = devops.specialized_builds[BuildType.TERRAFORM] + credentials = terraform.env_credentials() + self.tf_backend_git_api.start(credentials) def uses_backend_git(self, devops: Devops) -> bool: terraform = devops.specialized_builds[BuildType.TERRAFORM] diff --git a/src/main/python/ddadevops/domain/terraform.py b/src/main/python/ddadevops/domain/terraform.py index c70c7f5..631fb66 100644 --- a/src/main/python/ddadevops/domain/terraform.py +++ b/src/main/python/ddadevops/domain/terraform.py @@ -91,6 +91,17 @@ class TerraformDomain(Validateable): def uses_backend_git(self) -> bool: return ProviderType.TERRAFORM_BACKEND_GIT in self.providers.keys() + + # ToDo: Add ssh method case and make this default + # ToDo: How do we get to the credentials? + def env_credentials(self) -> Dict[str, str]: + tf_backend_git = self.providers[ProviderType.TERRAFORM_BACKEND_GIT] + if tf_backend_git.git_backend_token != "": + return { + "GITHUB_TOKEN" : tf_backend_git.git_backend_token, + "GIT_USERNAME" : tf_backend_git.git_backend_username, + } + return {"" : ""} def backend_config(self) -> Dict[str, Any]: result = {} diff --git a/src/main/python/ddadevops/infrastructure/infrastructure.py b/src/main/python/ddadevops/infrastructure/infrastructure.py index 2dbf62e..3389503 100644 --- a/src/main/python/ddadevops/infrastructure/infrastructure.py +++ b/src/main/python/ddadevops/infrastructure/infrastructure.py @@ -1,4 +1,5 @@ from subprocess import Popen, PIPE, run, CalledProcessError +from typing import Dict from pathlib import Path from sys import stdout from os import chmod, environ @@ -218,8 +219,11 @@ class TerraformApi: class TerraformBackendGitApi: def __init__(self): self.execution_api = ExecutionApi() - def start(self): - self.execution_api.execute("terraform-backend-git &") + def start(self, credentials: Dict[str, str]): + env = "" + for key in credentials: + env = env + f'{key}' + "=" + f'{credentials[key]}' + " " + self.execution_api.execute(f'{env}' + " " + "terraform-backend-git &") def stop(self): self.execution_api.execute("terraform-backend-git stop")