diff --git a/leverage/containers/kubectl.py b/leverage/containers/kubectl.py index 9006528..6f45437 100644 --- a/leverage/containers/kubectl.py +++ b/leverage/containers/kubectl.py @@ -12,7 +12,7 @@ class KubeCtlContainer(TerraformContainer): """Container specifically tailored to run kubectl commands.""" KUBECTL_CLI_BINARY = "/usr/local/bin/kubectl" - KUBECTL_CONFIG_PATH = Path("/root/.kube") + KUBECTL_CONFIG_PATH = Path("/home/leverage/.kube") KUBECTL_CONFIG_FILE = KUBECTL_CONFIG_PATH / Path("config") def __init__(self, client): diff --git a/leverage/path.py b/leverage/path.py index 9c103e6..4e86227 100644 --- a/leverage/path.py +++ b/leverage/path.py @@ -186,7 +186,7 @@ def backend_tfvars(self): @property def guest_aws_credentials_dir(self): - return str(get_home_path() / Path(self.project)) + return str("/home/leverage/tmp" / Path(self.project)) @property def host_aws_profiles_file(self): diff --git a/tests/test_modules/test_terraform.py b/tests/test_modules/test_terraform.py index d8030bc..9e8c2a0 100644 --- a/tests/test_modules/test_terraform.py +++ b/tests/test_modules/test_terraform.py @@ -4,7 +4,6 @@ from click import get_current_context from leverage._internals import State -from leverage._utils import AwsCredsContainer from leverage.container import TerraformContainer from leverage.modules.terraform import _init from tests.test_containers import container_fixture_factory @@ -22,36 +21,23 @@ def terraform_container(muted_click_context): # assume we are on a valid location with patch.object(tf_container.paths, "check_for_layer_location", Mock()): - # assume we have valid credentials - with patch.object(AwsCredsContainer, "__enter__", Mock()): - yield tf_container - - -def test_init(terraform_container): - """ - Test happy path. - """ - live_container = Mock() - with patch("leverage._utils.LiveContainer.__enter__", return_value=live_container): - with patch("dockerpty.exec_command") as mocked_pty: - _init([]) - - assert live_container.exec_run.call_args_list[0].args[0] == "mkdir -p /root/.ssh" - assert live_container.exec_run.call_args_list[1].args[0] == "chown root:root -R /root/.ssh/" - assert ( - mocked_pty.call_args_list[0].kwargs["command"] - == f"terraform init -backend-config=/project/./config/backend.tfvars" - ) - - -def test_init_with_args(terraform_container): + yield tf_container + + +@pytest.mark.parametrize( + "args, expected_value", + [ + ([], ["-backend-config=/project/./config/backend.tfvars"]), + (["-migrate-state"], ["-migrate-state", "-backend-config=/project/./config/backend.tfvars"]), + (["-r1", "-r2"], ["-r1", "-r2", "-backend-config=/project/./config/backend.tfvars"]), + ], +) +def test_init_arguments(terraform_container, args, expected_value): """ - Test tf init with arguments. + Test that the arguments for the init command are prepared correctly. """ - with patch("dockerpty.exec_command") as mocked_pty: - _init(["-migrate-state"]) + with patch.object(terraform_container, "start_in_layer", return_value=0) as mocked: + _init(args) - assert ( - mocked_pty.call_args_list[0].kwargs["command"] - == f"terraform init -migrate-state -backend-config=/project/./config/backend.tfvars" - ) + assert mocked.call_args_list[0][0][0] == "init" + assert " ".join(mocked.call_args_list[0][0][1:]) == " ".join(expected_value)