Skip to content

Commit

Permalink
Fix CFN response keys: add snake_case aliases + branch_name for SC pr…
Browse files Browse the repository at this point in the history
…oduct GetAtt

exact key matches. The SC product template uses snake_case keys
(repository_url, pull_request_url, branch_name) but Lambda was returning
PascalCase (RepositoryUrl, PullRequestUrl) with no branch_name.

Now returns both casings for full compatibility:
  - PascalCase: RepositoryUrl, PullRequestUrl, RepositoryName
  - snake_case: repository_url, pull_request_url, repository_name, branch_name

Also fixes SC test script product name (eks-terragrunt-eks-repo-creator).
  • Loading branch information
Your Name committed Feb 20, 2026
1 parent 34b3d66 commit 6df5e12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions scripts/test_service_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
ACCOUNT_ID = "229685449397"

# Service Catalog product details
SC_PRODUCT_NAME = "eks-terragrunt-repo-creator"
SC_PRODUCT_NAME = "eks-terragrunt-eks-repo-creator"
SC_ARTIFACT_NAME = "v2.0"

# GitHub / EKS defaults used as provisioning parameters
Expand Down Expand Up @@ -580,7 +580,7 @@ def main() -> None:
console.print(Rule("[bold cyan]EKS Terragrunt Repo Generator – Service Catalog Test[/bold cyan]"))
console.print(f"[dim]Timestamp : {datetime.now(timezone.utc).isoformat()}[/dim]")
console.print(f"[dim]Test repo : [bold]{repo_name}[/bold][/dim]")
console.print(f"[dim]Product : {SC_PRODUCT_NAME} v{SC_ARTIFACT_NAME}[/dim]")
console.print(f"[dim]Product : {SC_PRODUCT_NAME} {SC_ARTIFACT_NAME}[/dim]")
console.print(f"[dim]Region : {REGION}[/dim]")
console.print(f"[dim]Cleanup : {'yes (terminate after test)' if cleanup else 'no (--no-cleanup)'}[/dim]\n")

Expand Down
11 changes: 10 additions & 1 deletion template_automation/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,14 @@ def lambda_handler(event: dict, context) -> dict:
raise

# Build response data
# Include both PascalCase (for direct Lambda callers) and snake_case
# (for CloudFormation !GetAtt which uses the exact key names from Data)
response_data = {
"RepositoryUrl": project["web_url"],
"RepositoryName": cfn_input.project_name
"repository_url": project["web_url"],
"RepositoryName": cfn_input.project_name,
"repository_name": cfn_input.project_name,
"branch_name": config_branch,
}

# Use pull_request_url for GitHub and merge_request_url for GitLab
Expand All @@ -756,15 +761,19 @@ def lambda_handler(event: dict, context) -> dict:
pr_url = mr['_links']['html']['href']
logger.info(f"[{request_id}] Pull request URL from _links: {pr_url}")
response_data["PullRequestUrl"] = pr_url
response_data["pull_request_url"] = pr_url
elif mr and 'html_url' in mr:
# Some GitHub API versions return html_url directly
response_data["PullRequestUrl"] = mr['html_url']
response_data["pull_request_url"] = mr['html_url']
logger.info(f"[{request_id}] Pull request URL from html_url: {mr['html_url']}")
else:
logger.warning(f"[{request_id}] Could not extract PR URL from response: {json.dumps(mr, default=str)}")
response_data["PullRequestUrl"] = "N/A"
response_data["pull_request_url"] = "N/A"
else:
response_data["MergeRequestUrl"] = mr.get("web_url", "N/A")
response_data["merge_request_url"] = mr.get("web_url", "N/A")

logger.info(f"[{request_id}] Operation completed successfully")
logger.info(f"[{request_id}] Response data: {json.dumps(response_data, indent=2)}")
Expand Down

0 comments on commit 6df5e12

Please sign in to comment.