Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions modules/v2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,20 @@ resource "google_cloud_run_v2_service" "main" {
args = containers.value.container_args
working_dir = containers.value.working_dir
depends_on = containers.value.depends_on_container

dynamic "ports" {
for_each = lookup(containers.value, "ports", {}) != {} ? [containers.value.ports] : []
for_each = try(
(
containers.value.ports != null &&
containers.value.ports.container_port != null &&
containers.value.ports.container_port > 0 &&
containers.value.ports.container_port < 65536
) ? [containers.value.ports] : [],
[]
)
content {
name = ports.value["name"]
container_port = ports.value["container_port"]
name = try(ports.value.name, null)
container_port = ports.value.container_port
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/v2/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ variable "containers" {
mount_path = string
})), [])
ports = optional(object({
name = optional(string, "http1")
container_port = optional(number, 8080)
name = optional(string)
container_port = optional(number)
}), {})
Comment on lines -58 to 60
Copy link
Member

Choose a reason for hiding this comment

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

@q2w PTAL due to default change

Copy link

@krissrex krissrex Aug 25, 2025

Choose a reason for hiding this comment

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

Could an alternative be to explicitly specify ports = {} for the other containers?

I believe ports = {} then just defaults back to "http1" and 8080, if the default values are kept in variables.tf.

I do not believe optional with a fallback value can be used in any solution of this issue. Any default/fallback values must be set by you re-implementing a fallback inside the main.tf, because this optional does not give you a mechanism to know if the user supplied any value or not; meaning it will always be http1 or a user-specified non-empty value, never empty.

resources = optional(object({
limits = optional(object({
Expand Down