Skip to content

Commit

Permalink
ISSUE-163 Removed s3-key-by-parameter on init (#164)
Browse files Browse the repository at this point in the history
* ISSUE-163 Removed s3-key-by-parameter on init

* ISSUE-163 Improved tests for --layers

* ISSUE-163 Moved dir check
  • Loading branch information
juanmatias authored Jan 30, 2023
1 parent 937956a commit 9f76b0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 5 additions & 8 deletions leverage/modules/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 "
Expand All @@ -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)

Expand Down

0 comments on commit 9f76b0e

Please sign in to comment.