Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace try() with can(coalesce()) to better handle null values #389

Closed

Conversation

fatmcgav
Copy link

@fatmcgav fatmcgav commented Dec 3, 2024

Description

The default behaviour of try will return a null value if present. So update the logic to use can(coalesce()) which will ignore a null value.

Motivation and Context

Using the following listeners value, I was getting the below error:

listeners = {
      + http_https_redirect_listener = {
          + port     = 80
          + protocol = "HTTP"
          + redirect = {
              + port        = "443"
              + protocol    = "HTTPS"
              + status_code = "HTTP_301"
            }
        }
      + https                        = {
          + fixed_response = {
              + content_type = "text/plain"
              + message_body = ""
              + status_code  = "404"
            }
          + forward        = null
          + port           = 443
          + protocol       = "HTTPS"
          + rules          = {}
        }
    }

Error:

│ Error: Invalid Attribute Combination
│
│ Either "default_action[1].target_group_arn" or "default_action[1].forward" must be specified when "default_action[1].type" is "forward".
│ default_action[1].type
│
│   with module.alb.module.alb.aws_lb_listener.this["https"],
│   on .terraform/modules/alb.alb/main.tf line 88, in resource "aws_lb_listener" "this":
│   88: resource "aws_lb_listener" "this" {
│

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

…alues

The default behaviour of `try` will return a `null` value if present.
So update the logic to use `can(coalesce())` which will ignore a `null` value.
@bryantbiggs
Copy link
Member

lets start with a reproduction of the issue first

@fatmcgav
Copy link
Author

fatmcgav commented Dec 3, 2024

@bryantbiggs I've stuck a simple reproducer here, albeit with a slightly different error being returned by Terraform.

The changes in this PR fix the issue though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants