Skip to content

fix: use can(index()) to handle null proxy_client_password_auth_type#85

Open
wavemoran wants to merge 3 commits into
cloudposse-terraform-components:mainfrom
wavemoran:fix/proxy-auth-type-validation-null
Open

fix: use can(index()) to handle null proxy_client_password_auth_type#85
wavemoran wants to merge 3 commits into
cloudposse-terraform-components:mainfrom
wavemoran:fix/proxy-auth-type-validation-null

Conversation

@wavemoran
Copy link
Copy Markdown
Contributor

@wavemoran wavemoran commented Mar 25, 2026

Summary

  • contains() throws Invalid function argument when passed a null value, even when short-circuit evaluation with == null || is expected — Terraform evaluates both sides of || before applying the condition
  • Replace contains(list, var) with can(index(list, var)) so null (or unset) values return false cleanly without erroring
  • Fixes the regression introduced in feat: add optional RDS DB Proxy support #72 for users who do not set proxy_client_password_auth_type

Problem

When proxy_client_password_auth_type is not set (default null), Terraform raises:

Error: Invalid function argument
  on variables.tf line 541, in variable "proxy_client_password_auth_type":
  condition = var.proxy_client_password_auth_type == null || contains([...], var.proxy_client_password_auth_type)
Invalid value for "value" parameter: argument must not be null.

Fix

# Before
condition = var.proxy_client_password_auth_type == null || contains([...], var.proxy_client_password_auth_type)

# After
condition = var.proxy_client_password_auth_type == null || can(index([...], var.proxy_client_password_auth_type))

Per the Terraform can function docs: can evaluates the given expression and returns true if it succeeds, or false if it returns any error — including the error index raises when the value is not found or is null. This is the recommended pattern for validation conditions.

References

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for proxy client password authentication to safely handle edge cases while preserving accepted values and null allowance.
  • Chores
    • Updated remote-state module to v2.0.0 across relevant stack configurations.
    • Switched an IAM roles module reference from a local path to the updated remote module release to standardize sourcing.

Terraform's contains() throws "Invalid function argument" when the value
is null, even when guarded by an == null check, because both sides of ||
are evaluated. Replace with can(index()) which returns false for null or
non-matching values without erroring.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mergify mergify Bot requested review from a team March 25, 2026 16:06
@mergify mergify Bot added the triage Needs triage label Mar 25, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f329fdf-edea-456a-a5e5-77dce3d2dc18

📥 Commits

Reviewing files that changed from the base of the PR and between ca0c551 and dfceebc.

📒 Files selected for processing (1)
  • src/providers.tf

📝 Walkthrough

Walkthrough

Updated Terraform variable validation for proxy_client_password_auth_type to use can(index(...)) instead of contains(...). Bumped cloudposse/stack-config/yaml//modules/remote-state version from 1.8.0 to 2.0.0 in four module blocks and replaced a local iam_roles module source with a GitHub module reference.

Changes

Cohort / File(s) Summary
Validation Logic
src/variables.tf
Replaced contains() membership check with can(index(...)) in proxy_client_password_auth_type validation; allowed values and null handling unchanged.
Remote-state module version bumps
src/remote-state.tf
Updated version for cloudposse/stack-config/yaml//modules/remote-state from 1.8.02.0.0 across module blocks (vpc, vpc_ingress, eks, dns_gbl_delegated).
Module source update
src/providers.tf
Changed module "iam_roles" source from ../account-map/modules/iam-roles to github.com/cloudposse-terraform-components/aws-account-map//src/modules/iam-roles?ref=v1.537.2.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

minor

Poem

🐰 I hopped through code with nimble cheer,
Swapped contains for can(index(...)) so errors fear,
Bumped module tags and set a new source line,
I nibbled a carrot and called it fine,
Hooray — the terraform fields now shine ✨

🚥 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 'fix: use can(index()) to handle null proxy_client_password_auth_type' accurately describes the main change in src/variables.tf, which is the core fix mentioned in the PR objectives.
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

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.

@RoseSecurity
Copy link
Copy Markdown
Contributor

We may also need to adjust the version constraints on this

@wavemoran
Copy link
Copy Markdown
Contributor Author

We may also need to adjust the version constraints on this

Are you referencing this?

There's a few hops, but looks like the issue is conflicting versions being pulled in from account-map and cloudposse/satack-config.

We can test updating the latter to 2.0.0

…er conflict

stack-config v1.8.0 requires cloudposse/utils >= 1.7.1, < 2.0.0 while
account-map pulls in stack-config v2.0.0 which requires >= 2.0.0, < 3.0.0.
These constraints are mutually exclusive, causing terraform init to fail.

Upgrading all four remote-state module references to v2.0.0 aligns the
utils constraint to >= 2.0.0, < 3.0.0 across the full dependency tree.
The remote-state module interface is identical between v1.8.0 and v2.0.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mergify mergify Bot added the needs-test Needs testing label Mar 25, 2026
@RoseSecurity
Copy link
Copy Markdown
Contributor

/terratest

1 similar comment
@RoseSecurity
Copy link
Copy Markdown
Contributor

/terratest

@goruha
Copy link
Copy Markdown
Contributor

goruha commented Apr 14, 2026

@wavemoran could you pls replace https://github.com/wavemoran/aws-aurora-postgres/blob/fix/proxy-auth-type-validation-null/src/providers.tf#L17 with github.com/cloudposse-terraform-components/aws-account-map//src/modules/iam-roles?ref=v1.537.2

Copy link
Copy Markdown
Contributor

@goruha goruha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comments

Replace relative path reference to account-map with a pinned GitHub
source so terraform init succeeds without the CI-only account-map copy
workaround.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@goruha goruha added this pull request to the merge queue Apr 22, 2026
@mergify mergify Bot removed the triage Needs triage label Apr 22, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented Apr 22, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 22, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented Apr 29, 2026

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify Bot added stale This PR has gone stale and removed stale This PR has gone stale labels Apr 29, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented Apr 29, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

@mergify
Copy link
Copy Markdown

mergify Bot commented May 6, 2026

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify Bot added stale This PR has gone stale and removed stale This PR has gone stale labels May 6, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented May 6, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

@mergify
Copy link
Copy Markdown

mergify Bot commented May 13, 2026

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify Bot added stale This PR has gone stale and removed stale This PR has gone stale labels May 13, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented May 13, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

@mergify
Copy link
Copy Markdown

mergify Bot commented May 20, 2026

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify Bot added stale This PR has gone stale and removed stale This PR has gone stale labels May 20, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented May 20, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

@mergify
Copy link
Copy Markdown

mergify Bot commented May 27, 2026

Heads up! This pull request looks stale. It will be closed soon, if there are no new commits. ⏳

@mergify mergify Bot added stale This PR has gone stale and removed stale This PR has gone stale labels May 27, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented May 27, 2026

Thanks @wavemoran for creating this pull request!

A maintainer will review your changes shortly. Please don't be discouraged if it takes a while.

While you wait, make sure to review our contributor guidelines.

Tip

Need help or want to ask for a PR review to be expedited?

Join us on Slack in the #pr-reviews channel.

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

Labels

needs-test Needs testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants