Skip to content

Commit

Permalink
fix: env replacement only working for first value in string
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonLuttenberger committed Jul 18, 2024
1 parent 3e31d90 commit 85223ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion seedfarmer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions test/unit-test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 85223ed

Please sign in to comment.