"Attempt to get attribute from null value" errorΒ #390
Open
Description
Description
I am attempting to create a wrapper module around this alb
module, and as part of this am defining a listeners
var which includes a number of object
definitions:
variable "listeners" {
description = "Listeners to attach to ALB. A http-https-redirect-listener will be created automatically if 'enable_http_https_redirect = true'"
default = {}
type = map(object({
port = number
protocol = optional(string, "HTTP")
# Default behaviours
fixed_response = optional(object({
content_type = optional(string, "text/plain")
message_body = optional(string)
status_code = optional(string)
}))
forward = optional(object({
target_groups = list(object({
name = optional(string, null)
weight = optional(number)
}))
stickiness = object({
duration = optional(number)
enabled = optional(bool, false)
})
}))
redirect = optional(object({
host = optional(string, "#{host}")
path = optional(string, "#{path}")
port = optional(string, "#{port}")
protocol = optional(string, "#{protocol}")
query = optional(string, "#{query}")
status_code = optional(string, "HTTP_301")
}))
# Listener rules
rules = map(object({
type = optional(string)
fixed_response = optional(object({
content_type = optional(string)
message_body = optional(string)
status_code = optional(string)
}))
forward = optional(object({
target_groups = list(object({
name = string
weight = optional(number)
}))
stickiness = object({
duration = number
enabled = optional(bool, false)
})
}))
redirect = optional(object({
host = optional(string, "#{host}")
path = optional(string, "#{path}")
port = optional(string, "#{port}")
protocol = optional(string, "#{protocol}")
query = optional(string, "#{query}")
status_code = optional(string, "HTTP_301")
}))
}))
}))
validation {
condition = alltrue([
for listener in var.listeners : contains([80, 443], listener.port)
])
error_message = "listener 'port' value should be '80' or '443'"
}
validation {
condition = alltrue([
for listener in var.listeners : contains(["HTTP", "HTTPS"], listener.protocol)
])
error_message = "listener 'protocol' value should be 'HTTP' or 'HTTPS'"
}
}
However the plan is failing with:
β·
β Error: Attempt to get attribute from null value
β
β on .terraform/modules/alb/main.tf line 203, in resource "aws_lb_listener" "this":
β 203: status_code = default_action.value.status_code
β βββββββββββββββββ
β β default_action.value is null
β
β This value is null, so it does not have any attributes.
- β 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
.terraform
directory (! 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]: latest
-
Terraform version:
1.5.7
- Provider version(s):
5.79.0
Reproduction Code [Required]
https://gist.github.com/fatmcgav/82606b5ceef39b92d08398a0b08ec0a4
Steps to reproduce the behavior:
Expected behavior
ALB should be created
Actual behavior
Terraform plan failed
Terminal Output Screenshot(s)
Additional context
Changes in #389 fix the issue
Metadata
Assignees
Labels
No labels