binbashar / leverage

Binbash Leverage CLI intended to orchestrate Leverage Reference Architecture for AWS (www.binbash.co/leverage)
https://pypi.org/project/leverage/
Apache License 2.0
17 stars 2 forks source link

Bug | failure when running `apply` with parameters with space #159

Closed juanmatias closed 2 months ago

juanmatias commented 1 year ago

Describe the Bug

The Leverage CLI will fail due to a lack of variable values when apply is passed with a parameter with space. E.g.

leverage tf apply -target kubernetes_manifest.irfq

instead of

leverage tf apply -target=kubernetes_manifest.irfq

In this loop: https://github.com/binbashar/leverage/blob/937956a8622c31eb4bf4932d97a4ce4dc7283cb9/leverage/modules/terraform.py#L310

it is checked a value with no parameter is passed. When this happens there is the chance of user running apply on an already created plan, e.g.:

leverage tf apply thesecretplan

In this case, all the default parameters have to be removed from the command since Terraform does not allow passing -var or -var-file when applying a saved plan.

Because the way the loop has made, when passing a parameter without the "=" sign, it understands as if it were a plan.

So a list of parameters and flags has to be made in order to be able to check all the possibilities, e.g.:

etc

Expected Behavior

It should accept both ways of setting command line parameters.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to a RefArch layer
  2. Run leverage tf apply -target kubernetes_manifest.irfq (change the resource name with one that exists in your layer)
  3. Hit Enter
  4. See error

Screenshots

$:~/.../apps-qa/us-east-1/k8s-eks/k8s-workloads$ leverage tf apply -target kubernetes_manifest.irfq
[15:27:40]   INFO       MFA: Found 1 profile/s
[15:27:40]   INFO       MFA: Attempting to get temporary credentials for profile arta-apps-qa-devops
MFA: Please type in your OTP: 999999
[15:28:09]   INFO       MFA: Credentials written succesfully!
Acquiring state lock. This may take a few moments...
var.accounts
  Accounts Email & Id

  Enter a value: 

It asks you for a value when it should not do this.

Environment (please complete the following information):

Anything that will help us triage the bug will help. Here are some ideas:

Additional Context

n/a

IMPORTANT

Add test cases for this scenario.

exequielrafaela commented 10 months ago

@Franr looking forward to your feedback for this task. Thanks!

angelofenoglio commented 2 months ago

Handled in https://github.com/binbashar/leverage/pull/274