Skip to content

Commit 8e053ee

Browse files
psantusbryantbiggs
andcommitted
feat: Add support for restartPolicy (#231)
* feat: Add support for restartPolicy (#230) * fix precommit error * fix: Correct defaults and remove redundant validation --------- Co-authored-by: Bryant Biggs <[email protected]>
1 parent eb81a33 commit 8e053ee

File tree

27 files changed

+67
-35
lines changed

27 files changed

+67
-35
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.96.1
3+
rev: v1.96.2
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_wrapper_module_for_each

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module "ecs" {
160160
| Name | Version |
161161
|------|---------|
162162
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
163-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
163+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
164164

165165
## Providers
166166

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Note that this example may create resources which will incur monetary charges on
2727
| Name | Version |
2828
|------|---------|
2929
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
30-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
30+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
3131

3232
## Providers
3333

3434
| Name | Version |
3535
|------|---------|
36-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
3737

3838
## Modules
3939

examples/complete/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module "ecs" {
102102
}
103103
}
104104
memory_reservation = 100
105+
106+
restart_policy = {
107+
enabled = true
108+
ignoredExitCodes = [1]
109+
restartAttemptPeriod = 60
110+
}
105111
}
106112
}
107113

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

examples/ec2-autoscaling/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Note that this example may create resources which will incur monetary charges on
2727
| Name | Version |
2828
|------|---------|
2929
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
30-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
30+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
3131

3232
## Providers
3333

3434
| Name | Version |
3535
|------|---------|
36-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
3737

3838
## Modules
3939

examples/ec2-autoscaling/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

examples/fargate/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ Note that this example may create resources which will incur monetary charges on
2727
| Name | Version |
2828
|------|---------|
2929
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
30-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
30+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
3131

3232
## Providers
3333

3434
| Name | Version |
3535
|------|---------|
36-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
3737

3838
## Modules
3939

examples/fargate/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ module "ecs_service" {
121121
}
122122
}
123123

124+
restart_policy = {
125+
enabled = true
126+
ignoredExitCodes = [1]
127+
restartAttemptPeriod = 60
128+
}
129+
124130
# Not required for fluent-bit, just an example
125131
volumes_from = [{
126132
sourceContainer = "fluent-bit"

examples/fargate/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ module "service" {
100100
iam_role_statements = lookup(each.value, "iam_role_statements", {})
101101

102102
# ECS infrastructure IAM role
103-
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, true)
104-
infrastructure_iam_role_arn = try(each.value.infrastructure_iam_role_arn, null)
105-
infrastructure_iam_role_name = try(each.value.infrastructure_iam_role_name, null)
106-
infrastructure_iam_role_use_name_prefix = try(each.value.infrastructure_iam_role_use_name_prefix, true)
107-
infrastructure_iam_role_path = try(each.value.infrastructure_iam_role_path, null)
108-
infrastructure_iam_role_description = try(each.value.infrastructure_iam_role_description, null)
103+
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, true)
104+
infrastructure_iam_role_arn = try(each.value.infrastructure_iam_role_arn, null)
105+
infrastructure_iam_role_name = try(each.value.infrastructure_iam_role_name, null)
106+
infrastructure_iam_role_use_name_prefix = try(each.value.infrastructure_iam_role_use_name_prefix, true)
107+
infrastructure_iam_role_path = try(each.value.infrastructure_iam_role_path, null)
108+
infrastructure_iam_role_description = try(each.value.infrastructure_iam_role_description, null)
109109
infrastructure_iam_role_permissions_boundary = try(each.value.infrastructure_iam_role_permissions_boundary, null)
110-
infrastructure_iam_role_tags = try(each.value.infrastructure_iam_role_tags, {})
110+
infrastructure_iam_role_tags = try(each.value.infrastructure_iam_role_tags, {})
111111

112112
# Task definition
113113
create_task_definition = try(each.value.create_task_definition, true)

modules/cluster/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ module "ecs_cluster" {
137137
| Name | Version |
138138
|------|---------|
139139
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
140-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
140+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
141141

142142
## Providers
143143

144144
| Name | Version |
145145
|------|---------|
146-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
146+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
147147

148148
## Modules
149149

modules/cluster/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

modules/container-definition/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ module "example_ecs_container_definition" {
116116
| Name | Version |
117117
|------|---------|
118118
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
119-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
119+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
120120

121121
## Providers
122122

123123
| Name | Version |
124124
|------|---------|
125-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
125+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
126126

127127
## Modules
128128

@@ -178,6 +178,7 @@ No modules.
178178
| <a name="input_readonly_root_filesystem"></a> [readonly\_root\_filesystem](#input\_readonly\_root\_filesystem) | When this parameter is true, the container is given read-only access to its root file system | `bool` | `true` | no |
179179
| <a name="input_repository_credentials"></a> [repository\_credentials](#input\_repository\_credentials) | Container repository credentials; required when using a private repo. This map currently supports a single key; "credentialsParameter", which should be the ARN of a Secrets Manager's secret holding the credentials | `map(string)` | `{}` | no |
180180
| <a name="input_resource_requirements"></a> [resource\_requirements](#input\_resource\_requirements) | The type and amount of a resource to assign to a container. The only supported resource is a GPU | <pre>list(object({<br/> type = string<br/> value = string<br/> }))</pre> | `[]` | no |
181+
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | Container restart policy; helps overcome transient failures faster and maintain task availability | <pre>object({<br/> enabled = optional(bool)<br/> ignoredExitCodes = optional(list(number))<br/> restartAttemptPeriod = optional(number)<br/> })</pre> | `null` | no |
181182
| <a name="input_secrets"></a> [secrets](#input\_secrets) | The secrets to pass to the container. For more information, see [Specifying Sensitive Data](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html) in the Amazon Elastic Container Service Developer Guide | <pre>list(object({<br/> name = string<br/> valueFrom = string<br/> }))</pre> | `[]` | no |
182183
| <a name="input_service"></a> [service](#input\_service) | The name of the service that the container definition is associated with | `string` | `""` | no |
183184
| <a name="input_start_timeout"></a> [start\_timeout](#input\_start\_timeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `30` | no |

modules/container-definition/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ locals {
5454
portMappings = var.port_mappings
5555
privileged = local.is_not_windows ? var.privileged : null
5656
pseudoTerminal = var.pseudo_terminal
57+
restartPolicy = var.restart_policy
5758
readonlyRootFilesystem = local.is_not_windows ? var.readonly_root_filesystem : null
5859
repositoryCredentials = length(var.repository_credentials) > 0 ? var.repository_credentials : null
5960
resourceRequirements = length(var.resource_requirements) > 0 ? var.resource_requirements : null

modules/container-definition/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ variable "resource_requirements" {
215215
default = []
216216
}
217217

218+
variable "restart_policy" {
219+
description = "Container restart policy; helps overcome transient failures faster and maintain task availability"
220+
type = object({
221+
enabled = optional(bool)
222+
ignoredExitCodes = optional(list(number))
223+
restartAttemptPeriod = optional(number)
224+
})
225+
default = null
226+
}
227+
218228
variable "secrets" {
219229
description = "The secrets to pass to the container. For more information, see [Specifying Sensitive Data](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html) in the Amazon Elastic Container Service Developer Guide"
220230
type = list(object({

modules/container-definition/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

modules/service/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ module "ecs_service" {
7070
}
7171
}
7272
memory_reservation = 100
73+
74+
restart_policy = {
75+
enabled = true
76+
ignoredExitCodes = [1]
77+
restartAttemptPeriod = 60
78+
}
7379
}
7480
}
7581
@@ -167,13 +173,13 @@ module "ecs_service" {
167173
| Name | Version |
168174
|------|---------|
169175
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
170-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
176+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.63 |
171177

172178
## Providers
173179

174180
| Name | Version |
175181
|------|---------|
176-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
182+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.63 |
177183

178184
## Modules
179185

@@ -237,7 +243,7 @@ module "ecs_service" {
237243
| <a name="input_cpu"></a> [cpu](#input\_cpu) | Number of cpu units used by the task. If the `requires_compatibilities` is `FARGATE` this field is required | `number` | `1024` | no |
238244
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
239245
| <a name="input_create_iam_role"></a> [create\_iam\_role](#input\_create\_iam\_role) | Determines whether the ECS service IAM role should be created | `bool` | `true` | no |
240-
| <a name="input_create_infrastructure_iam_role"></a> [create\_infrastructure\_iam\_role](#input\_create\_infrastructure\_iam\_role) | Determines whether the ECS infrastructure IAM role should be created | `bool` | `false` | no |
246+
| <a name="input_create_infrastructure_iam_role"></a> [create\_infrastructure\_iam\_role](#input\_create\_infrastructure\_iam\_role) | Determines whether the ECS infrastructure IAM role should be created | `bool` | `true` | no |
241247
| <a name="input_create_security_group"></a> [create\_security\_group](#input\_create\_security\_group) | Determines if a security group is created | `bool` | `true` | no |
242248
| <a name="input_create_service"></a> [create\_service](#input\_create\_service) | Determines whether service resource will be created (set to `false` in case you want to create task definition only) | `bool` | `true` | no |
243249
| <a name="input_create_task_definition"></a> [create\_task\_definition](#input\_create\_task\_definition) | Determines whether to create a task definition or use existing/provided | `bool` | `true` | no |

modules/service/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ module "container_definition" {
670670
readonly_root_filesystem = try(each.value.readonly_root_filesystem, var.container_definition_defaults.readonly_root_filesystem, true)
671671
repository_credentials = try(each.value.repository_credentials, var.container_definition_defaults.repository_credentials, {})
672672
resource_requirements = try(each.value.resource_requirements, var.container_definition_defaults.resource_requirements, [])
673+
restart_policy = try(each.value.restart_policy, var.container_definition_defaults.restart_policy, { enabled = false })
673674
secrets = try(each.value.secrets, var.container_definition_defaults.secrets, [])
674675
start_timeout = try(each.value.start_timeout, var.container_definition_defaults.start_timeout, 30)
675676
stop_timeout = try(each.value.stop_timeout, var.container_definition_defaults.stop_timeout, 120)

modules/service/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

wrappers/cluster/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

wrappers/container-definition/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module "wrapper" {
4242
readonly_root_filesystem = try(each.value.readonly_root_filesystem, var.defaults.readonly_root_filesystem, true)
4343
repository_credentials = try(each.value.repository_credentials, var.defaults.repository_credentials, {})
4444
resource_requirements = try(each.value.resource_requirements, var.defaults.resource_requirements, [])
45+
restart_policy = try(each.value.restart_policy, var.defaults.restart_policy, null)
4546
secrets = try(each.value.secrets, var.defaults.secrets, [])
4647
service = try(each.value.service, var.defaults.service, "")
4748
start_timeout = try(each.value.start_timeout, var.defaults.start_timeout, 30)

wrappers/container-definition/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

wrappers/service/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module "wrapper" {
3535
cpu = try(each.value.cpu, var.defaults.cpu, 1024)
3636
create = try(each.value.create, var.defaults.create, true)
3737
create_iam_role = try(each.value.create_iam_role, var.defaults.create_iam_role, true)
38-
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, var.defaults.create_infrastructure_iam_role, false)
38+
create_infrastructure_iam_role = try(each.value.create_infrastructure_iam_role, var.defaults.create_infrastructure_iam_role, true)
3939
create_security_group = try(each.value.create_security_group, var.defaults.create_security_group, true)
4040
create_service = try(each.value.create_service, var.defaults.create_service, true)
4141
create_task_definition = try(each.value.create_task_definition, var.defaults.create_task_definition, true)
@@ -118,7 +118,6 @@ module "wrapper" {
118118
task_exec_iam_statements = try(each.value.task_exec_iam_statements, var.defaults.task_exec_iam_statements, {})
119119
task_exec_secret_arns = try(each.value.task_exec_secret_arns, var.defaults.task_exec_secret_arns, ["arn:aws:secretsmanager:*:*:secret:*"])
120120
task_exec_ssm_param_arns = try(each.value.task_exec_ssm_param_arns, var.defaults.task_exec_ssm_param_arns, ["arn:aws:ssm:*:*:parameter/*"])
121-
task_tags = try(each.value.task_tags, var.defaults.task_tags, {})
122121
tasks_iam_role_arn = try(each.value.tasks_iam_role_arn, var.defaults.tasks_iam_role_arn, null)
123122
tasks_iam_role_description = try(each.value.tasks_iam_role_description, var.defaults.tasks_iam_role_description, null)
124123
tasks_iam_role_name = try(each.value.tasks_iam_role_name, var.defaults.tasks_iam_role_name, null)
@@ -128,6 +127,7 @@ module "wrapper" {
128127
tasks_iam_role_statements = try(each.value.tasks_iam_role_statements, var.defaults.tasks_iam_role_statements, {})
129128
tasks_iam_role_tags = try(each.value.tasks_iam_role_tags, var.defaults.tasks_iam_role_tags, {})
130129
tasks_iam_role_use_name_prefix = try(each.value.tasks_iam_role_use_name_prefix, var.defaults.tasks_iam_role_use_name_prefix, true)
130+
task_tags = try(each.value.task_tags, var.defaults.task_tags, {})
131131
timeouts = try(each.value.timeouts, var.defaults.timeouts, {})
132132
triggers = try(each.value.triggers, var.defaults.triggers, {})
133133
volume = try(each.value.volume, var.defaults.volume, {})

wrappers/service/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

wrappers/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.59"
7+
version = ">= 5.63"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)