terraform-aws-alb
terraform-aws-alb copied to clipboard
[bug] - waiting `target_failover` for other load_balancer than `gateway` type
Description
Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the examples/* directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running terraform init && terraform apply without any further changes.
If your request is for a new feature, please use the Feature request template.
- [x ] β I have searched the open/closed issues and my issue is not listed.
β οΈ Note
Before you submit an issue, please perform the following first:
- Remove the local
.terraformdirectory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/ - Re-initialize the project root to pull down modules:
terraform init - Re-attempt your terraform plan or apply and check if the issue still persists
Versions
-
Module version [Required]:
v9.9.0 -
Terraform version:
tf -version
Terraform v1.8.5
- Provider version(s):
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing modules...
- describe_vpc in ..\describe_vpc
Downloading registry.terraform.io/terraform-aws-modules/alb/aws 9.9.0 for service_alb...
- service_alb in .terraform\modules\service_alb
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Installing hashicorp/aws v5.56.0...
- Installed hashicorp/aws v5.56.0 (signed by HashiCorp)
- Installing hashicorp/random v3.6.2...
- Installed hashicorp/random v3.6.2 (signed by HashiCorp)
Reproduction Code [Required]
The code is available in the following gist
Steps to reproduce the behavior:
Are you using workspaces? No Have you cleared the local cache (see Notice section above)?: Yes List steps in order that led up to the issue you encountered
terraform init
terraform plan -var-file terraform-tfvars
Expected behavior
The plan should work without errors because:
- I use the examples provided in the module
- I do not try to create a Gateway Load Balancer but an Application Load Balancer
Actual behavior
The plan fails with the following errors:
1st error
β Error: Attempt to get attribute from null value
β
β on .terraform\modules\service_alb\main.tf line 530, in resource "aws_lb_target_group" "this":
β 530: type = var.load_balancer_type == "network" ? "source_ip" : stickiness.value.type
β βββββββββββββββββ
β β stickiness.value is null
β
β This value is null, so it does not have any attributes.
I'm not sure why this is failing right now. The only thing I know is that with the provided example it fails so we do not have a proper example to rely on.
If I override the code as below, my plan pass this issue but fails on another one described in 3rd error block
# .terraform\modules\service_alb\main.tf line 523
dynamic "stickiness" {
for_each = var.load_balancer_type == "network" ? try([each.value.stickiness], []) : []
content {
cookie_duration = try(stickiness.value.cookie_duration, null)
cookie_name = try(stickiness.value.cookie_name, null)
enabled = try(stickiness.value.enabled, true)
type = var.load_balancer_type == "network" ? "source_ip" : stickiness.value.type
}
}
2nd error
β·
β Error: Invalid dynamic for_each value
β
β on .terraform\modules\service_alb\main.tf line 535, in resource "aws_lb_target_group" "this":
β 535: for_each = try(each.value.target_failover, [])
β βββββββββββββββββ
β β each.value.target_failover is null
β
β Cannot use a null value in for_each.
IMHO, the foreach should condition the var.load_balancer_type as gateway since it's written this in the doc
This block is only applicable for a Gateway Load Balancer (GWLB). The two attributes on_deregistration and on_unhealthy cannot be set independently. The value you set for both attributes must be the same.
# .terraform\modules\service_alb\main.tf line 534
dynamic "target_failover" {
for_each = var.load_balancer_type == "gateway" ? try(each.value.target_failover, []) : []
content {
on_deregistration = target_failover.value.on_deregistration
on_unhealthy = target_failover.value.on_unhealthy
}
}
3rd issue
When I override the .terraform\modules\service_alb\main.tf block code as described into 1st error , I fail on the following issue, even if I hard code the vpc_id
β Error: Invalid Attribute Combination
β
β Attribute "vpc_id" must be specified when "target_type" is "instance".
β target_type
β
β with module.service_alb.aws_lb_target_group.this["ex-instance"],
β on .terraform\modules\service_alb\main.tf line 487, in resource "aws_lb_target_group" "this":
β 487: resource "aws_lb_target_group" "this" {
β
Terminal Output Screenshot(s)
Additional context
OK so my listeners and target_groups variables are not perfect yet to modelize each possible options matching the module... Moreover, there were based on a previous version of the module so it's failing later due to this...
If you want to reproduce, replace them with the default variables as in the module
variable "listeners" {
description = "Map of listener configurations to create"
type = any
default = {}
}
variable "target_groups" {
description = "Map of target group configurations to create"
type = any
default = {}
}
But then it's failing with another issue:
β Error: Error in function call
β
β on .terraform\modules\service_alb\main.tf line 346, in resource "aws_lb_listener_rule" "this":
β 346: arn = try(target_group.value.arn, aws_lb_target_group.this[target_group.value.target_group_key].arn)
β βββββββββββββββββ
β β aws_lb_target_group.this is object with 1 attribute "ex-instance"
β β target_group.value is object with 2 attributes
β β target_group.value.target_group_key is "ex-lambda-with-trigger"
β
β Call to function "try" failed: no expression succeeded:
β - Unsupported attribute (at .terraform\modules\service_alb\main.tf:346,44-48)
β This object does not have an attribute named "arn".
β - Invalid index (at .terraform\modules\service_alb\main.tf:346,74-111)
β The given key does not identify an element in this collection value.
β
β At least one expression must produce a successful result.
I don't really understand why the example is failing and why I can't find any other issue showing this
This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days
This issue was automatically closed because of stale in 10 days
I'm going to lock this issue because it has been closed for 30 days β³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.