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 | Wrong S3 Key when initializing with `--layers` #163

Closed juanmatias closed 1 year ago

juanmatias commented 1 year ago

Describe the Bug

When initializing multiple layers using --layers option, the given key is wrong.

E.g. using --layers layer1,layer2 will check both layers, but the S3 Key in memory will remain the last one, so layer1 will be initialized with the key for layer2.

Expected Behavior

When using --layers layer1,layer2 each layer should have its own correct S3 Key.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to le-tf-infra-aws/apps-devstg/us-east-1/k8s-eks-demoapps
  2. Run leverage tf init --layers network,cluster
  3. Check leverage tf output --layers network has wrong outputs

Screenshots

n/a

Environment (please complete the following information):

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

Additional Context

This change should fix the issue:

diff --git a/leverage/modules/terraform.py b/leverage/modules/terraform.py
index 2ba6ada..1b9be14 100644
--- a/leverage/modules/terraform.py
+++ b/leverage/modules/terraform.py
@@ -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)

since this method: https://github.com/binbashar/leverage/blob/937956a8622c31eb4bf4932d97a4ce4dc7283cb9/leverage/container.py#L630

when calculating a non existing key will save it to the file.

So, in any case it is not needed to pass the -backend-config="key=keyname" since it always will be in the config.tf file.