diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index fd741e3d..6d305c87 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -197,20 +197,19 @@ jobs: run: | printf "[INFO] Initializing layer\n" - leverage tf init + leverage tf init --layers cli-test-layer,base-identities printf "[INFO] Generating plan\n" - leverage tf plan + leverage tf plan --layers cli-test-layer printf "[INFO] Applying changes\n" - leverage tf apply -auto-approve + leverage tf apply -auto-approve --layers cli-test-layer printf "[INFO] Checking if all changes were applied\n" - leverage tf plan -detailed-exitcode + leverage tf plan -detailed-exitcode --layers cli-test-layer [[ $? -eq 2 ]] && printf "[WARN] There are still remaining changes\n" [[ $? -eq 0 ]] && printf "[INFO] Apply checks out\n" printf "[INFO] Destroying all generated created resources\n" - leverage tf destroy -auto-approve - working-directory: ../theblairwitchproject/apps-devstg/global/cli-test-layer - + leverage tf destroy -auto-approve --layers cli-test-layer + working-directory: ../theblairwitchproject/apps-devstg/global diff --git a/leverage/modules/terraform.py b/leverage/modules/terraform.py index 2ba6adaf..2a0985bd 100644 --- a/leverage/modules/terraform.py +++ b/leverage/modules/terraform.py @@ -222,6 +222,11 @@ def invoke_for_all_commands(tf, layers, command, args, skip_validation=True): # change to current dir and set it in the container tf.cwd = layer + # check layers existence + if not layer.is_dir(): + logger.error(f"Directory [red]{layer}[/red] does not exist or is not a directory\n") + raise Exit(1) + # set the s3 key tf.set_backend_key(skip_validation) @@ -260,12 +265,7 @@ def validate_for_all_commands(layer, skip_validation=False): layer: a full layer directory """ - # check layers existence logger.debug(f"Checking layer {layer}...") - if not layer.is_dir(): - logger.error(f"Directory [red]{layer}[/red] does not exist or is not a directory\n") - raise Exit(1) - if not skip_validation and not _validate_layout(): logger.error("Layer configuration doesn't seem to be valid. Exiting.\n" "If you are sure your configuration is actually correct " @@ -283,9 +283,6 @@ def _init(tf, args): if not arg.startswith("-backend-config") or not arg[index - 1] == "-backend-config"] args.append(f"-backend-config={tf.backend_tfvars}") args.append(f"-backend-config=\"region={tf.terraform_backend.get('region')}\"") - # if the backend key is set send it as a backend config - if not tf.backend_key is None: - args.append(f"-backend-config=\"key={tf.backend_key}\"") exit_code = tf.start_in_layer("init", *args)