Skip to content

Commit ec4c4a6

Browse files
authored
Fix: Add Thorough Automated Testing and Bump Minimum Terraform Version to 0.13.0 (#139)
* Ensure examples/complete is creating an aws_ecs_task_definition and test the task definition in the automated testing. * Fix examples/multiple_definitions * Bump minimum Terraform required version to 0.13.0 * Add context.tf to examples/complete to ensure aws_ecs_task_definition has tags.
1 parent 549d7a0 commit ec4c4a6

File tree

18 files changed

+248
-21
lines changed

18 files changed

+248
-21
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
<!-- markdownlint-disable -->
23
# terraform-aws-ecs-container-definition
34

@@ -31,7 +32,6 @@
3132

3233
Terraform module to generate well-formed JSON documents that are passed to the `aws_ecs_task_definition` Terraform resource as [container definitions](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definitions).
3334

34-
3535
---
3636

3737
This project is part of our comprehensive ["SweetOps"](https://cpco.io/sweetops) approach towards DevOps.
@@ -62,7 +62,6 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
6262

6363

6464

65-
6665
## Security & Compliance [<img src="https://cloudposse.com/wp-content/uploads/2020/11/bridgecrew.svg" width="250" align="right" />](https://bridgecrew.io/)
6766

6867
Security scanning is graciously provided by Bridgecrew. Bridgecrew is the leading fully hosted, cloud-native solution providing continuous Terraform security and compliance.
@@ -133,7 +132,7 @@ Available targets:
133132

134133
| Name | Version |
135134
|------|---------|
136-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.26 |
135+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
137136
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.2 |
138137

139138
## Providers
@@ -216,6 +215,7 @@ Like this project? Please give it a ★ on [our GitHub](https://github.com/cloud
216215
Are you using this project or any of our other projects? Consider [leaving a testimonial][testimonial]. =)
217216

218217

218+
219219
## Related Projects
220220

221221
Check out these related projects.
@@ -230,8 +230,6 @@ Check out these related projects.
230230
- [terraform-aws-ecs-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms) - Terraform module to create CloudWatch Alarms on ECS Service level metrics
231231
- [terraform-aws-ecs-alb-service-task](https://github.com/cloudposse/terraform-aws-ecs-alb-service-task) - Terraform module which implements an ECS service which exposes a web service via ALB
232232

233-
234-
235233
## Help
236234

237235
**Got a question?** We got answers.
@@ -361,8 +359,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
361359
### Contributors
362360

363361
<!-- markdownlint-disable -->
364-
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Sarkis Varozian][sarkis_avatar]][sarkis_homepage]<br/>[Sarkis Varozian][sarkis_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] |
365-
|---|---|---|---|
362+
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Sarkis Varozian][sarkis_avatar]][sarkis_homepage]<br/>[Sarkis Varozian][sarkis_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![Igor Rodionov][goruha_avatar]][goruha_homepage]<br/>[Igor Rodionov][goruha_homepage] | [![Yonatan Koren][korenyoni_avatar]][korenyoni_homepage]<br/>[Yonatan Koren][korenyoni_homepage] |
363+
|---|---|---|---|---|
366364
<!-- markdownlint-restore -->
367365

368366
[osterman_homepage]: https://github.com/osterman
@@ -373,6 +371,8 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
373371
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
374372
[goruha_homepage]: https://github.com/goruha
375373
[goruha_avatar]: https://img.cloudposse.com/150x150/https://github.com/goruha.png
374+
[korenyoni_homepage]: https://github.com/korenyoni
375+
[korenyoni_avatar]: https://img.cloudposse.com/150x150/https://github.com/korenyoni.png
376376

377377
[![README Footer][readme_footer_img]][readme_footer_link]
378378
[![Beacon][beacon]][website]

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ contributors:
7070
github: aknysh
7171
- name: Igor Rodionov
7272
github: goruha
73+
- name: Yonatan Koren
74+
github: korenyoni

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
| Name | Version |
55
|------|---------|
6-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.26 |
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
77
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.2 |
88

99
## Providers

examples/complete/context.tf

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#
2+
# ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
3+
# All other instances of this file should be a copy of that one
4+
#
5+
#
6+
# Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
7+
# and then place it in your Terraform module to automatically get
8+
# Cloud Posse's standard configuration inputs suitable for passing
9+
# to Cloud Posse modules.
10+
#
11+
# Modules should access the whole context as `module.this.context`
12+
# to get the input variables with nulls for defaults,
13+
# for example `context = module.this.context`,
14+
# and access individual variables as `module.this.<var>`,
15+
# with final values filled in.
16+
#
17+
# For example, when using defaults, `module.this.context.delimiter`
18+
# will be null, and `module.this.delimiter` will be `-` (hyphen).
19+
#
20+
21+
module "this" {
22+
source = "cloudposse/label/null"
23+
version = "0.24.1" # requires Terraform >= 0.13.0
24+
25+
enabled = var.enabled
26+
namespace = var.namespace
27+
environment = var.environment
28+
stage = var.stage
29+
name = var.name
30+
delimiter = var.delimiter
31+
attributes = var.attributes
32+
tags = var.tags
33+
additional_tag_map = var.additional_tag_map
34+
label_order = var.label_order
35+
regex_replace_chars = var.regex_replace_chars
36+
id_length_limit = var.id_length_limit
37+
label_key_case = var.label_key_case
38+
label_value_case = var.label_value_case
39+
40+
context = var.context
41+
}
42+
43+
# Copy contents of cloudposse/terraform-null-label/variables.tf here
44+
45+
variable "context" {
46+
type = any
47+
default = {
48+
enabled = true
49+
namespace = null
50+
environment = null
51+
stage = null
52+
name = null
53+
delimiter = null
54+
attributes = []
55+
tags = {}
56+
additional_tag_map = {}
57+
regex_replace_chars = null
58+
label_order = []
59+
id_length_limit = null
60+
label_key_case = null
61+
label_value_case = null
62+
}
63+
description = <<-EOT
64+
Single object for setting entire context at once.
65+
See description of individual variables for details.
66+
Leave string and numeric variables as `null` to use default value.
67+
Individual variable settings (non-null) override settings in context object,
68+
except for attributes, tags, and additional_tag_map, which are merged.
69+
EOT
70+
71+
validation {
72+
condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
73+
error_message = "Allowed values: `lower`, `title`, `upper`."
74+
}
75+
76+
validation {
77+
condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
78+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
79+
}
80+
}
81+
82+
variable "enabled" {
83+
type = bool
84+
default = null
85+
description = "Set to false to prevent the module from creating any resources"
86+
}
87+
88+
variable "namespace" {
89+
type = string
90+
default = null
91+
description = "Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp'"
92+
}
93+
94+
variable "environment" {
95+
type = string
96+
default = null
97+
description = "Environment, e.g. 'uw2', 'us-west-2', OR 'prod', 'staging', 'dev', 'UAT'"
98+
}
99+
100+
variable "stage" {
101+
type = string
102+
default = null
103+
description = "Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release'"
104+
}
105+
106+
variable "name" {
107+
type = string
108+
default = null
109+
description = "Solution name, e.g. 'app' or 'jenkins'"
110+
}
111+
112+
variable "delimiter" {
113+
type = string
114+
default = null
115+
description = <<-EOT
116+
Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
117+
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
118+
EOT
119+
}
120+
121+
variable "attributes" {
122+
type = list(string)
123+
default = []
124+
description = "Additional attributes (e.g. `1`)"
125+
}
126+
127+
variable "tags" {
128+
type = map(string)
129+
default = {}
130+
description = "Additional tags (e.g. `map('BusinessUnit','XYZ')`"
131+
}
132+
133+
variable "additional_tag_map" {
134+
type = map(string)
135+
default = {}
136+
description = "Additional tags for appending to tags_as_list_of_maps. Not added to `tags`."
137+
}
138+
139+
variable "label_order" {
140+
type = list(string)
141+
default = null
142+
description = <<-EOT
143+
The naming order of the id output and Name tag.
144+
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
145+
You can omit any of the 5 elements, but at least one must be present.
146+
EOT
147+
}
148+
149+
variable "regex_replace_chars" {
150+
type = string
151+
default = null
152+
description = <<-EOT
153+
Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`.
154+
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
155+
EOT
156+
}
157+
158+
variable "id_length_limit" {
159+
type = number
160+
default = null
161+
description = <<-EOT
162+
Limit `id` to this many characters (minimum 6).
163+
Set to `0` for unlimited length.
164+
Set to `null` for default, which is `0`.
165+
Does not affect `id_full`.
166+
EOT
167+
validation {
168+
condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
169+
error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
170+
}
171+
}
172+
173+
variable "label_key_case" {
174+
type = string
175+
default = null
176+
description = <<-EOT
177+
The letter case of label keys (`tag` names) (i.e. `name`, `namespace`, `environment`, `stage`, `attributes`) to use in `tags`.
178+
Possible values: `lower`, `title`, `upper`.
179+
Default value: `title`.
180+
EOT
181+
182+
validation {
183+
condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
184+
error_message = "Allowed values: `lower`, `title`, `upper`."
185+
}
186+
}
187+
188+
variable "label_value_case" {
189+
type = string
190+
default = null
191+
description = <<-EOT
192+
The letter case of output label values (also used in `tags` and `id`).
193+
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
194+
Default value: `lower`.
195+
EOT
196+
197+
validation {
198+
condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
199+
error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
200+
}
201+
}
202+
#### End of copy of cloudposse/terraform-null-label/variables.tf

examples/complete/fixtures.us-east-2.tfvars

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
region = "us-east-2"
22

3+
namespace = "eg"
4+
5+
stage = "test"
6+
7+
name = "container-definition"
8+
39
container_name = "app"
410
container_image = "cloudposse/geodesic"
511
container_memory = 256
@@ -8,7 +14,7 @@ container_cpu = 256
814
essential = true
915
readonly_root_filesystem = false
1016

11-
environment = [
17+
container_environment = [
1218
{
1319
name = "string_var"
1420
value = "I am a string"

examples/complete/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module "container" {
1111
container_cpu = var.container_cpu
1212
essential = var.essential
1313
readonly_root_filesystem = var.readonly_root_filesystem
14-
environment = var.environment
14+
environment = var.container_environment
1515
port_mappings = var.port_mappings
1616
log_configuration = var.log_configuration
1717
privileged = var.privileged
@@ -20,3 +20,10 @@ module "container" {
2020
pseudo_terminal = var.pseudo_terminal
2121
interactive = var.interactive
2222
}
23+
24+
resource "aws_ecs_task_definition" "task" {
25+
family = module.this.id
26+
container_definitions = module.container.json_map_encoded_list
27+
28+
tags = module.this.tags
29+
}

examples/complete/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ output "json_map_object" {
1212
description = "JSON map encoded container definition"
1313
value = module.container.json_map_object
1414
}
15+
16+
output "task_definition_container_definition" {
17+
description = "The aws_ecs_task_definition container definition"
18+
value = jsondecode(aws_ecs_task_definition.task.container_definitions)[0]
19+
}

examples/complete/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ variable "working_directory" {
8585
default = null
8686
}
8787

88-
variable "environment" {
88+
variable "container_environment" {
8989
type = list(object({
9090
name = string
9191
value = string

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.12.26"
2+
required_version = ">= 0.13.0"
33

44
required_providers {
55
local = {

examples/env_vars_files/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.12.26"
2+
required_version = ">= 0.13.0"
33

44
required_providers {
55
local = {

0 commit comments

Comments
 (0)