Skip to content

Commit 4c14290

Browse files
committed
[v1.0.0] initial module implementation
1 parent 017465b commit 4c14290

File tree

5 files changed

+210
-0
lines changed

5 files changed

+210
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Terraform ECS Task Definition Module
2+
3+
## Requirements
4+
5+
| Name | Version |
6+
|------|---------|
7+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
8+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.43.0 |
9+
10+
11+
## Resources
12+
13+
| Name | Type |
14+
|------|------|
15+
| [aws_ecs_task_definition.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource |
16+
17+
## Inputs
18+
19+
| Name | Description | Type | Default | Required |
20+
|------|-------------|------|---------|:--------:|
21+
| <a name="input_container_definitions"></a> [container\_definitions](#input\_container\_definitions) | A list of valid container definitions provided as a single valid JSON document. | `string` | n/a | yes |
22+
| <a name="input_name"></a> [name](#input\_name) | A unique name for your task definition. | `string` | n/a | yes |
23+
| <a name="input_placement_constraints"></a> [placement\_constraints](#input\_placement\_constraints) | (Optional) Configuration block for rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. This is a list of maps, where each map should contain "type" and "expression". | `list(any)` | `[]` | no |
24+
| <a name="input_proxy_configuration"></a> [proxy\_configuration](#input\_proxy\_configuration) | (Optional) Configuration block for the App Mesh proxy. | `list(any)` | `[]` | no |
25+
| <a name="input_requires_compatibilities"></a> [requires\_compatibilities](#input\_requires\_compatibilities) | Set of launch types required by the task. The valid values are EC2 and FARGATE. | `list` | <pre>[<br> "FARGATE"<br>]</pre> | no |
26+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) Key-value map of resource tags. | `map(string)` | `{}` | no |
27+
| <a name="input_task_cpu"></a> [task\_cpu](#input\_task\_cpu) | (Optional) Number of cpu units used by the task. If the requires\_compatibilities is FARGATE this field is required. | `number` | `null` | no |
28+
| <a name="input_task_execution_role"></a> [task\_execution\_role](#input\_task\_execution\_role) | (Optional) ARN of the task execution role that the Amazon ECS container agent and the Docker daemon can assume. | `string` | `null` | no |
29+
| <a name="input_task_memory"></a> [task\_memory](#input\_task\_memory) | (Optional) Amount (in MiB) of memory used by the task. If the requires\_compatibilities is FARGATE this field is required. | `number` | `null` | no |
30+
| <a name="input_task_role_arn"></a> [task\_role\_arn](#input\_task\_role\_arn) | (Optional) ARN of IAM role that allows your Amazon ECS container task to make calls to other AWS services. | `string` | `null` | no |
31+
| <a name="input_volumes"></a> [volumes](#input\_volumes) | (Optional) Configuration block for volumes that containers in your task may use. | <pre>list(object({<br> host_path = string<br> name = string<br> docker_volume_configuration = list(object({<br> autoprovision = bool<br> driver = string<br> driver_opts = map(string)<br> labels = map(string)<br> scope = string<br> }))<br> efs_volume_configuration = list(object({<br> file_system_id = string<br> root_directory = string<br> transit_encryption = string<br> transit_encryption_port = string<br> authorization_config = list(object({<br> access_point_id = string<br> iam = string<br> }))<br> }))<br> }))</pre> | `[]` | no |
32+
33+
## Outputs
34+
35+
| Name | Description |
36+
|------|-------------|
37+
| <a name="output_output"></a> [output](#output\_output) | Task definition attributes |

main.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
resource "aws_ecs_task_definition" "this" {
2+
cpu = var.task_cpu
3+
memory = var.task_memory
4+
family = var.name
5+
network_mode = var.network_mode
6+
task_role_arn = var.task_role_arn
7+
execution_role_arn = var.task_execution_role
8+
container_definitions = var.container_definitions
9+
requires_compatibilities = var.requires_compatibilities
10+
11+
dynamic "placement_constraints" {
12+
for_each = var.placement_constraints
13+
content {
14+
expression = try(placement_constraints.value.expression, null)
15+
type = placement_constraints.value.type
16+
}
17+
}
18+
19+
dynamic "proxy_configuration" {
20+
for_each = var.proxy_configuration
21+
content {
22+
container_name = proxy_configuration.value.container_name
23+
properties = try(proxy_configuration.value.properties, null)
24+
type = try(proxy_configuration.value.type, null)
25+
}
26+
}
27+
28+
dynamic "volume" {
29+
for_each = var.volumes
30+
content {
31+
name = volume.value.name
32+
33+
host_path = lookup(volume.value, "host_path", null)
34+
35+
dynamic "docker_volume_configuration" {
36+
for_each = lookup(volume.value, "docker_volume_configuration", [])
37+
content {
38+
autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null)
39+
driver = lookup(docker_volume_configuration.value, "driver", null)
40+
driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null)
41+
labels = lookup(docker_volume_configuration.value, "labels", null)
42+
scope = lookup(docker_volume_configuration.value, "scope", null)
43+
}
44+
}
45+
46+
dynamic "efs_volume_configuration" {
47+
for_each = lookup(volume.value, "efs_volume_configuration", [])
48+
content {
49+
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
50+
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
51+
transit_encryption = lookup(efs_volume_configuration.value, "transit_encryption", null)
52+
transit_encryption_port = lookup(efs_volume_configuration.value, "transit_encryption_port", null)
53+
dynamic "authorization_config" {
54+
for_each = lookup(efs_volume_configuration.value, "authorization_config", [])
55+
content {
56+
access_point_id = lookup(authorization_config.value, "access_point_id", null)
57+
iam = lookup(authorization_config.value, "iam", null)
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
65+
tags = var.tags
66+
}

outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "output" {
2+
description = "Task definition attributes"
3+
value = aws_ecs_task_definition.this
4+
}

variables.tf

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
variable "name" {
2+
description = "A unique name for your task definition."
3+
type = string
4+
}
5+
6+
variable "container_definitions" {
7+
description = "A list of valid container definitions provided as a single valid JSON document."
8+
type = string
9+
}
10+
11+
variable "tags" {
12+
description = "(Optional) Key-value map of resource tags."
13+
type = map(string)
14+
default = {}
15+
}
16+
17+
#------------------------------------------------------------------------------
18+
# AWS ECS Task Definition Variables
19+
#------------------------------------------------------------------------------
20+
variable "task_role_arn" {
21+
description = "(Optional) ARN of IAM role that allows your Amazon ECS container task to make calls to other AWS services."
22+
type = string
23+
default = null
24+
}
25+
26+
variable "task_execution_role" {
27+
description = "(Optional) ARN of the task execution role that the Amazon ECS container agent and the Docker daemon can assume."
28+
type = string
29+
default = null
30+
}
31+
32+
variable "placement_constraints" {
33+
description = "(Optional) Configuration block for rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain \"type\" and \"expression\"."
34+
type = list(any)
35+
default = []
36+
}
37+
38+
variable "task_cpu" {
39+
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-task-defs
40+
description = "(Optional) Number of cpu units used by the task. If the requires_compatibilities is FARGATE this field is required."
41+
type = number
42+
default = null
43+
}
44+
45+
variable "task_memory" {
46+
description = "(Optional) Amount (in MiB) of memory used by the task. If the requires_compatibilities is FARGATE this field is required."
47+
type = number
48+
default = null
49+
}
50+
51+
variable "proxy_configuration" {
52+
description = "(Optional) Configuration block for the App Mesh proxy."
53+
type = list(any)
54+
default = []
55+
}
56+
57+
variable "volumes" {
58+
description = "(Optional) Configuration block for volumes that containers in your task may use."
59+
type = list(object({
60+
host_path = string
61+
name = string
62+
docker_volume_configuration = list(object({
63+
autoprovision = bool
64+
driver = string
65+
driver_opts = map(string)
66+
labels = map(string)
67+
scope = string
68+
}))
69+
efs_volume_configuration = list(object({
70+
file_system_id = string
71+
root_directory = string
72+
transit_encryption = string
73+
transit_encryption_port = string
74+
authorization_config = list(object({
75+
access_point_id = string
76+
iam = string
77+
}))
78+
}))
79+
}))
80+
default = []
81+
}
82+
83+
variable "network_mode" {
84+
description = "(Optional) Docker networking mode to use for the containers in the task. Valid values are none, bridge, awsvpc, and host."
85+
type = string
86+
default = "awsvpc"
87+
}
88+
89+
variable "requires_compatibilities" {
90+
description = "Set of launch types required by the task. The valid values are EC2 and FARGATE."
91+
type = list(string)
92+
default = ["FARGATE"]
93+
}

versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 3.43.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)