Skip to content

Improve s3_key assignment based on conditions#47

Merged
goruha merged 2 commits into
mainfrom
filename-mode-fix
Feb 5, 2026
Merged

Improve s3_key assignment based on conditions#47
goruha merged 2 commits into
mainfrom
filename-mode-fix

Conversation

@goruha
Copy link
Copy Markdown
Contributor

@goruha goruha commented Feb 4, 2026

what

  • Improve s3_key assignment based on conditions

why

  • Ensure s3_key set null if s3_bucket_name is null
import:
  - catalog/lambda/defaults

components:
  terraform:
    lambda/hello-world-py:
      metadata:
        component: lambda
        inherits:
          - lambda/defaults
      vars:
        name: hello-world-py
        function_name: main
        description: Hello Lambda from Python!
        handler: lambda.lambda_handler # in go this is the compiled binary, python it's filename.function
        memory_size: 256
        # https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
        runtime: python3.9
        package_type: Zip # `Zip` or `Image`
        policy_json: null

        # Filename example
        filename: lambdas/hello-world-python/output.zip # generated by zip variable.
        zip:
          enabled: true
          input_dir: hello-world-python
          output: hello-world-python/output.zip

        # S3 Source Example
        # s3_bucket_name: lambda-source # lambda main.tf calculates the rest of the bucket_name
        # s3_key: hello-world-go.zip

this stack configuration lead to error

│ Error: Missing required argument
│ 
│   with module.lambda.aws_lambda_function.this[0],
│   on .terraform/modules/lambda/main.tf line 40, in resource "aws_lambda_function" "this":
│   40:   s3_key                         = var.s3_key
│ 
│ "s3_key": all of `s3_bucket,s3_key` must be specified

Summary by CodeRabbit

  • Improvements
    • Improved deployment configuration handling so storage key assignment is skipped when no storage bucket is configured, preventing invalid configuration and preserving prior behavior when a bucket is present.

Refactor s3_key assignment logic for clarity and correctness.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

A Terraform locals block in src/main.tf was changed so s3_key is only evaluated when local.s3_bucket_name is non-null. If the bucket is absent, s3_key is set to null; otherwise previous selection logic (explicit var.s3_key, image_uri check, or formatted key) is preserved. A clarifying comment was added.

Changes

Cohort / File(s) Summary
S3 Key Conditional Logic
src/main.tf
Rewrote local.s3_key to short-circuit to null when local.s3_bucket_name is null; preserved prior selection order (var.s3_keynull if image_uri set → formatted cicd_s3_key_format); added explanatory comment.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐇 I checked the bucket, sniffed the key,
If nothing’s there, I let it be,
No stray paths carved where objects hide,
Null-safe hops keep builds in stride,
A tiny thump — deploys run free.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly relates to the main change: improving s3_key assignment logic based on conditions (specifically the s3_bucket_name presence).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch filename-mode-fix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mergify mergify Bot requested review from a team February 4, 2026 23:26
@mergify mergify Bot added the triage Needs triage label Feb 4, 2026
@goruha goruha added the patch A minor, backward compatible change label Feb 5, 2026
@goruha
Copy link
Copy Markdown
Contributor Author

goruha commented Feb 5, 2026

/terratest

@mergify mergify Bot added the needs-test Needs testing label Feb 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2026

There are no real tests for this component. So we set terratest statuses to successful execution without running any tests

@mergify mergify Bot removed the triage Needs triage label Feb 5, 2026
@goruha goruha added this pull request to the merge queue Feb 5, 2026
Merged via the queue into main with commit b6de051 Feb 5, 2026
19 checks passed
@goruha goruha deleted the filename-mode-fix branch February 5, 2026 11:48
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2026

These changes were released in v1.537.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-test Needs testing patch A minor, backward compatible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants