You can write out an ingress
block with references to the attributes of your variable:
variable "ssh_ingress" {
type = object({
from_port = number
to_port = number
protocol = string
description = string
})
default = {
from_port = 22
protocol = "tcp"
to_port = 22
description = "SSH for administration."
}
}
resource "aws_security_group" "main" {
ingress {
from_port = var.ssh_ingress.from_port
protocol = var.ssh_ingress.protocol
to_port = var.ssh_ingress.to_port
description = var.ssh_ingress.description
}
}
The ingress
block itself is a static structure rather than a value. You can populate its arguments with dynamic values, but you can't generate the arguments themselves dynamically. Terraform verifies that all of the expected arguments are present before considering the configuration to be valid.
However, Terraform considers the value null
in a block like this to be equivalent to omitting the argument, so if the caller of your module were to set description = null
, for example, then the AWS provider will see that in exactly the same way as having omitted the description
argument altogether.