|
1 | 1 | import json |
| 2 | +import os |
2 | 3 | from pathlib import Path |
3 | 4 | from datetime import datetime |
4 | | -from datetime import timedelta |
5 | | -import os |
6 | 5 |
|
7 | 6 | import hcl2 |
8 | 7 | from click.exceptions import Exit |
@@ -421,15 +420,24 @@ def __init__(self, client): |
421 | 420 | "AWS_CACHE_DIR": f"{self.guest_aws_credentials_dir}/cache", |
422 | 421 | "SSO_CACHE_DIR": f"{self.guest_aws_credentials_dir}/sso/cache", |
423 | 422 | "SCRIPT_LOG_LEVEL": get_script_log_level(), |
424 | | - "MFA_SCRIPT_LOG_LEVEL": get_script_log_level(), # Legacy |
425 | | - "SSH_AUTH_SOCK": '' if SSH_AUTH_SOCK is None else '/ssh-agent' |
| 423 | + "MFA_SCRIPT_LOG_LEVEL": get_script_log_level(), # Legacy |
| 424 | + "SSH_AUTH_SOCK": '' if SSH_AUTH_SOCK is None else '/ssh-agent', |
426 | 425 | } |
427 | 426 | self.entrypoint = self.TF_BINARY |
428 | 427 | self.mounts = [ |
429 | 428 | Mount(source=self.root_dir.as_posix(), target=self.guest_base_path, type="bind"), |
430 | 429 | Mount(source=self.host_aws_credentials_dir.as_posix(), target=self.guest_aws_credentials_dir, type="bind"), |
431 | | - Mount(source=(self.home / ".gitconfig").as_posix(), target="/etc/gitconfig", type="bind") |
| 430 | + Mount(source=(self.home / ".gitconfig").as_posix(), target="/etc/gitconfig", type="bind"), |
432 | 431 | ] |
| 432 | + # if you have set the tf plugin cache locally |
| 433 | + if tf_cache_dir := os.getenv("TF_PLUGIN_CACHE_DIR"): |
| 434 | + # then mount it too into the container |
| 435 | + self.environment["TF_PLUGIN_CACHE_DIR"] = tf_cache_dir |
| 436 | + # given that terraform use symlinks to point from the .terraform folder into the plugin folder |
| 437 | + # we need to use the same directory inside the container |
| 438 | + # otherwise symlinks will be broken once outside the container |
| 439 | + # which will break terraform usage outside Leverage |
| 440 | + self.mounts.append(Mount(source=tf_cache_dir, target=tf_cache_dir, type="bind")) |
433 | 441 | if SSH_AUTH_SOCK is not None: |
434 | 442 | self.mounts.append(Mount(source=SSH_AUTH_SOCK, target="/ssh-agent", type="bind")) |
435 | 443 |
|
@@ -533,7 +541,6 @@ def _prepare_container(self): |
533 | 541 | "AWS_CONFIG_FILE": self.environment.get("AWS_CONFIG_FILE").replace("tmp", ".aws"), |
534 | 542 | }) |
535 | 543 |
|
536 | | - |
537 | 544 | logger.debug(f"[bold cyan]Running with entrypoint:[/bold cyan] {self.entrypoint}") |
538 | 545 |
|
539 | 546 | def check_for_layer_location(self): |
|
0 commit comments