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:
Go to le-tf-infra-aws/apps-devstg/us-east-1/k8s-eks-demoapps
Run leverage tf init --layers network,cluster
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:
Leverage CLI: 1.9.1
Leverage Toolbox: *
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)
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, solayer1
will be initialized with the key forlayer2
.Expected Behavior
When using
--layers layer1,layer2
each layer should have its own correct S3 Key.Steps to Reproduce
Steps to reproduce the behavior:
le-tf-infra-aws/apps-devstg/us-east-1/k8s-eks-demoapps
leverage tf init --layers network,cluster
leverage tf output --layers network
has wrong outputsScreenshots
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:
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 theconfig.tf
file.