fix(lambda): prevent strcontains null error on zip deploys#54
Conversation
Terraform/OpenTofu's `&&` does not short-circuit, so strcontains() was evaluated against var.image_uri even when it is null (zip deploys with a cicd_ssm_param_name set), failing the plan with "argument must not be null". Feed strcontains() a safe "" via an inner ternary, which does short-circuit. Add a credential-free `terraform test` unit suite under test/unit/image_uri that reproduces the regression and covers the image_uri resolution paths.
|
Warning Review limit reached
More reviews will be available in 18 minutes and 48 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR fixes a null-safety bug in image URI resolution by preventing null values from being passed to ChangesImage URI Resolution Fix
Possibly Related PRs
Suggested Labels
Suggested Reviewers
Poem
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Important Do not edit the Please update the Could you fix it @johncblandii? 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main.tf`:
- Line 35: The local.image_uri expression can call
one(data.aws_ssm_parameter.cicd_ssm_param[*].value) even when the SSM data
source was not created because local.enabled is false; change the ternary
condition to include local.enabled (i.e., only format when local.enabled is true
AND var.cicd_ssm_param_name != null AND var.image_uri contains "%s") so the true
branch cannot evaluate one([]). Update the mirror in test/unit/image_uri/main.tf
to use the same local.enabled gating and add a fixture test where enabled =
false but cicd_ssm_param_name and a templated var.image_uri are set to ensure no
plan-time error occurs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7a43b67a-bbb6-4b69-9205-41beccdfc41e
📒 Files selected for processing (4)
src/main.tftest/README.mdtest/unit/image_uri/image_uri_unit_test.tftest.hcltest/unit/image_uri/main.tf
…iptions Also gate the image_uri format branch on local.enabled: the cicd SSM data source is created with `count = local.enabled && ...`, so when disabled the ternary could select format(var.image_uri, one([])) and fail at plan time. Add descriptions to the unit-test fixture variables/output (required by the bats input/output-description checks) and add an enabled=false regression case.
Align the remote-state module with account-map, which already uses v2. v2 only changes the transitive cloudposse/utils provider constraint to >= 2.0.0, < 3.0.0 (utils v2 embeds a newer Atmos that no longer crashes on modern atmos.yaml features); the remote-state submodule's inputs/outputs are unchanged. Resolves the cloudposse/utils provider version conflict during terraform init.
|
/terratest |
|
There are no real tests for this component. So we set terratest statuses to successful execution without running any tests |
|
These changes were released in v1.538.1. |
Summary
image_uri == null) whilecicd_ssm_param_namewas set.terraform testunit suite that reproduces the regression and guards theimage_uriresolution logic going forward.Changes
src/main.tf: make thelocal.image_uriresolution null-safe. Terraform/OpenTofu's&&does not short-circuit, sostrcontains(var.image_uri, "%s")was evaluated even whenvar.image_uriwas null, failing withInvalid value for "str" parameter: argument must not be null. The string fed tostrcontains()now goes through an inner ternary (var.image_uri == null ? "" : var.image_uri), which does short-circuit. (Note:coalesce(var.image_uri, "")is not a valid fix here —coalescealso rejects empty strings and would error whenimage_uriis null.)test/unit/image_uri/: new nativeterraform testfixture mirroring thelocal.image_urilogic, runnable without AWS credentials. The component itself can only be planned via the atmos/Terratest harness (it depends onaccount-mapand remote-state modules), so this isolates the pure logic that broke.test/README.md: document the integration (atmos test run) and new unit test workflows.Testing
test/unit/image_uri/image_uri_unit_test.tftest.hcl, 4 cases)Invalid value for "str" parameter)Success! 4 passed, 0 failedterraform fmt -check -recursivecleanRun the unit tests with:
```bash
terraform -chdir=test/unit/image_uri init
terraform -chdir=test/unit/image_uri test
```
Notes
Covered scenarios: zip deploy with SSM param set (the regression), templated
image_uriformatted with the SSM value, staticimage_uripassthrough, andimage_uripassthrough when no SSM param is configured.The unit fixture mirrors the
src/main.tfexpression rather than executing it directly (the component can'tinitstandalone in plain CI). Cross-reference comments in both files note they must stay in sync.Summary by CodeRabbit
Bug Fixes
Tests
Documentation