|
1 | 1 | /** |
2 | 2 | * # Terraform AWS ECS Container Definition |
3 | 3 | * |
4 | | - * Introducing the AWS ECS Container Definitions Terraform Module, a highly |
5 | | - * optimized solution for creating and managing your container definitions |
6 | | - * within Amazon Web Services. This module has been expertly crafted by our |
7 | | - * team, who have years of experience working with AWS and Terraform. |
8 | | - * |
9 | | - * We have taken the time to fine-tune the settings and configurations to |
10 | | - * provide you with the best possible experience when using this module. Our |
11 | | - * team is comprised of experts in AWS and Terraform, and we are proud to share |
12 | | - * our knowledge and expertise with you. |
13 | | - * |
14 | | - * This Terraform module offers a preconfigured solution for managing your |
15 | | - * container definitions, allowing you to focus on developing your applications |
16 | | - * and not on the infrastructure setup. By using this module, you can be |
17 | | - * confident that your container definitions are created and managed in a |
18 | | - * secure, scalable, and efficient manner. |
19 | | - * |
20 | | - * So, whether you're a seasoned AWS user or just starting out, the AWS ECS |
21 | | - * Container Definitions Terraform Module is the perfect solution for managing |
22 | | - * your container definitions. Give it a try and see the difference it can make |
23 | | - * in your workflow! |
| 4 | + * This module is used to generate a container definition for use in an AWS ECS task definition. |
24 | 5 | */ |
25 | 6 | locals { |
26 | | - # TODO: Filter out null values on the container definition. |
27 | 7 | container_definition = { |
28 | 8 | name = var.name |
29 | 9 | image = var.image |
@@ -127,15 +107,11 @@ locals { |
127 | 107 | credentialsParameter : var.repository_credentials |
128 | 108 | } : null |
129 | 109 | } |
| 110 | +} |
130 | 111 |
|
131 | | - filtered_container_definition = { for k, v in local.container_definition : k => v if v != null && v != [] } |
132 | | - filtered_port_mappings = [for pm in local.container_definition.portMappings : { for k, v in pm : k => v if v != null && v != [] }] |
133 | | - |
134 | | - # Merge all filtered values into one definition |
135 | | - final_container_definition = merge( |
136 | | - local.filtered_container_definition, |
137 | | - { |
138 | | - portMappings = local.filtered_port_mappings |
139 | | - } |
140 | | - ) |
| 112 | +# AWS will complain if we send any optional values with a null value. A simple way to get around this is to use jq |
| 113 | +# to remove any null values and empty arrays from the JSON before sending it to AWS. |
| 114 | +data "jq_query" "main" { |
| 115 | + query = "del(.. | nulls) | del(.. | select(. == []))" |
| 116 | + data = jsonencode(local.container_definition) |
141 | 117 | } |
0 commit comments