From 85223eddc16bf87a243576ee64f6677713c7adca Mon Sep 17 00:00:00 2001 From: Leon Luttenberger Date: Thu, 18 Jul 2024 09:04:08 +0200 Subject: [PATCH] fix: env replacement only working for first value in string --- seedfarmer/utils.py | 2 +- test/unit-test/test_models.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/seedfarmer/utils.py b/seedfarmer/utils.py index 836f4475..59542a17 100644 --- a/seedfarmer/utils.py +++ b/seedfarmer/utils.py @@ -203,7 +203,7 @@ def replace_str(value: str) -> str: matches = re.findall(pattern, value) for match in matches: try: - return value.replace("${" + match + "}", os.environ[match.strip()]) + value = value.replace("${" + match + "}", os.environ[match.strip()]) except KeyError: raise seedfarmer.errors.InvalidManifestError( f"The environment variable ({match.strip()}) is not available" diff --git a/test/unit-test/test_models.py b/test/unit-test/test_models.py index 545a130e..cc3b8d28 100644 --- a/test/unit-test/test_models.py +++ b/test/unit-test/test_models.py @@ -556,3 +556,26 @@ def test_deployresponses(): codebuild_build_id="codebuild:12345", codebuild_log_path="/somepath", ) + + +@pytest.mark.models +@pytest.mark.models_module_manifest +def test_module_manifest_with_env_var_resolution_in_path(): + module_yaml = yaml.safe_load( + """ +name: test-module-1 +path: "git::${GIT_URL}//modules/module-name/?ref=${GIT_BRANCH}" +targetAccount: primary +targetRegion: us-west-2 +parameters: + - name: param1 + value: value1 +""" + ) + + with mock.patch.dict(os.environ, { + "GIT_URL": "https://github.com/awslabs/module-repo.git", + "GIT_BRANCH": "main", + }, clear=True): + module = ModuleManifest(**module_yaml) + assert module.path == "git::https://github.com/awslabs/module-repo.git//modules/module-name/?ref=main"