Skip to content

fix: Correct variable optional argument defaults and container definition conditional logic #332

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

Merged

Conversation

bryantbiggs
Copy link
Member

Description

  • Rely on the variable optional argument settings by using nullable = false in wrapped sub-modules so that default values are surfaced properly and to avoid scenarios where null does not make sense (create = null - no). This also simplifies the number of redundant defaults set in the higher modules, instead relying on the lower modules to provide them unless overridden by users. Not all variables that have defaults have been set to nullable = false because there are scenarios where users should still be allowed to null out the value. For example cpu and memory settings can be set to null if a users so chooses, so we do not specify nullable = false in those scenarios
  • The logic for linuxParameters was corrected to:
    1. Ensure the correct behavior when setting enable_execute_command to either true or false
    2. Allow users to specify initProcessEnabled to the value of their choosing when enable_execute_command = false
  • Added a note and ToDo to the container_definition_json output value. In hindsight, missed the part about multiple definitions being passed to the Task Definition API, which means that output would need to be wrapped in an array. However, that also means you could only ever pass one container definition from the output into the Task Definition, which is not usually the case; ergo, it doesn't make sense to have this output when we have container_definition that can be composed within an array of other container definitions and then wrapped in an jsonencode()

Motivation and Context

Breaking Changes

  • No

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
    • Deployed both the fargate and complete examples as they are defined on master, then switched to this branch to verify changes
  • I have executed pre-commit run -a on my pull request

content = module.ecs_container_definition.container_definition_json
filename = "${path.module}/definition.json"
# Need the output pretty-printed and sorted for comparison
resource "null_resource" "container_definition_json" {
Copy link
Member Author

Choose a reason for hiding this comment

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

the local_file doesn't output in pretty-printed JSON so switched to this hack to ensure its formatted and sorted to be able to compare diffs

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need definition.json other than for debugging? Consider making it conditional, so users can turn it off if needed.

@bryantbiggs
Copy link
Member Author

another round of bugfixes due to the lack of hashicorp/terraform-provider-aws#17988

@@ -584,30 +584,24 @@ variable "services" {
family = optional(string)
ipc_mode = optional(string)
memory = optional(number, 2048)
network_mode = optional(string, "awsvpc")
network_mode = optional(string)
Copy link
Member

Choose a reason for hiding this comment

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

I like that there are fewer default values in "optional()". It is easier to read, and hopefully it also works more predictably. 👍

content = module.ecs_container_definition.container_definition_json
filename = "${path.module}/definition.json"
# Need the output pretty-printed and sorted for comparison
resource "null_resource" "container_definition_json" {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need definition.json other than for debugging? Consider making it conditional, so users can turn it off if needed.

@bryantbiggs
Copy link
Member Author

added the variable to enable/disable writing the container definition to file in 2354bb2

and yes, its used just for debugging and checking diffs - not consumed by end users at all

@bryantbiggs bryantbiggs merged commit 054ad89 into terraform-aws-modules:master Aug 7, 2025
12 checks passed
@bryantbiggs bryantbiggs deleted the fix/container-def branch August 7, 2025 13:52
antonbabenko pushed a commit that referenced this pull request Aug 7, 2025
## [6.1.4](v6.1.3...v6.1.4) (2025-08-07)

### Bug Fixes

* Correct variable optional argument defaults and container definition conditional logic ([#332](#332)) ([054ad89](054ad89))
@antonbabenko
Copy link
Member

This PR is included in version 6.1.4 🎉

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.

The module container-defitinion does not work when using aws_ecs_task_definition as target
2 participants