Skip to content

Commit 6f2c185

Browse files
committed
Add aws_ecs_task_ignore_definition
1 parent 3de8c37 commit 6f2c185

File tree

8 files changed

+44
-1
lines changed

8 files changed

+44
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ terraform-*
1515
operations/deployment/terraform/inventory.yaml
1616

1717
*.pem
18-
.vscode/
18+
.vscode/
19+
#operations/deployment/terraform/modules/aws/lb**
20+
**/lb**

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ The following inputs can be used as `step.with` keys
431431
| `aws_ecs_service_launch_type`| String | Configuration type. Could be `EC2`, `FARGATE` or `EXTERNAL`. Defaults to `FARGATE`. |
432432
| `aws_ecs_task_type`| String | Configuration type. Could be `EC2`, `FARGATE` or empty. Will default to `aws_ecs_service_launch_type` if none defined. (Blank if `EXTERNAL`). |
433433
| `aws_ecs_task_name`| String | Elastic Container Service task name. If task is defined with a JSON file, should be the same as the container name. |
434+
| `aws_ecs_task_ignore_definition`| Boolean | Toggle to ignore task definition changes after first deployment. Useful when using external tools to manage the task definition. Default: `false`. |
434435
| `aws_ecs_task_execution_role`| String | Elastic Container Service task execution role name from IAM. Defaults to `ecsTaskExecutionRole`. |
435436
| `aws_ecs_task_json_definition_file`| String | Name of the json file containing task definition. Overrides every other input. |
436437
| `aws_ecs_task_network_mode`| String | Network type to use in task definition. One of `none`, `bridge`, `awsvpc`, and `host`. |

action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ inputs:
808808
aws_ecs_task_name:
809809
description: 'Elastic Container Service task name'
810810
required: false
811+
aws_ecs_task_ignore_definition:
812+
description: 'Toggle to ignore task definition changes after first deployment. Useful when using external tools to manage the task definition.'
813+
required: false
811814
aws_ecs_task_execution_role:
812815
description: 'Elastic Container Service task execution role name from IAM. Defaults to "ecsTaskExecutionRole"'
813816
required: false
@@ -1438,6 +1441,7 @@ runs:
14381441
AWS_ECS_SERVICE_LAUNCH_TYPE : ${{ inputs.aws_ecs_service_launch_type }}
14391442
AWS_ECS_TASK_TYPE : ${{ inputs.aws_ecs_task_type }}
14401443
AWS_ECS_TASK_NAME: ${{ inputs.aws_ecs_task_name }}
1444+
AWS_ECS_TASK_IGNORE_DEFINITION: ${{ inputs.aws_ecs_task_ignore_definition }}
14411445
AWS_ECS_TASK_EXECUTION_ROLE: ${{ inputs.aws_ecs_task_execution_role }}
14421446
AWS_ECS_TASK_JSON_DEFINITION_FILE: ${{ inputs.aws_ecs_task_json_definition_file }}
14431447
AWS_ECS_TASK_NETWORK_MODE: ${{ inputs.aws_ecs_task_network_mode }}

operations/_scripts/generate/generate_vars_terraform.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ if [[ $(alpha_only "$AWS_ECS_ENABLE") == true ]]; then
317317
aws_ecs_service_launch_type=$(generate_var aws_ecs_service_launch_type $AWS_ECS_SERVICE_LAUNCH_TYPE)
318318
aws_ecs_task_type=$(generate_var aws_ecs_task_type $AWS_ECS_TASK_TYPE)
319319
aws_ecs_task_name=$(generate_var aws_ecs_task_name $AWS_ECS_TASK_NAME)
320+
aws_ecs_task_ignore_definition=$(generate_var aws_ecs_task_ignore_definition $AWS_ECS_TASK_IGNORE_DEFINITION)
320321
aws_ecs_task_execution_role=$(generate_var aws_ecs_task_execution_role $AWS_ECS_TASK_EXECUTION_ROLE)
321322
aws_ecs_task_json_definition_file=$(generate_var aws_ecs_task_json_definition_file $AWS_ECS_TASK_JSON_DEFINITION_FILE)
322323
aws_ecs_task_network_mode=$(generate_var aws_ecs_task_network_mode $AWS_ECS_TASK_NETWORK_MODE)
@@ -665,6 +666,7 @@ $aws_ecs_cluster_name
665666
$aws_ecs_service_launch_type
666667
$aws_ecs_task_type
667668
$aws_ecs_task_name
669+
$aws_ecs_task_ignore_definition
668670
$aws_ecs_task_execution_role
669671
$aws_ecs_task_json_definition_file
670672
$aws_ecs_task_network_mode

operations/deployment/terraform/aws/aws_variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,12 @@ variable "aws_ecs_task_name" {
13491349
default = ""
13501350
}
13511351

1352+
variable "aws_ecs_task_ignore_definition" {
1353+
type = bool
1354+
description = "Toggle ignoring changes to the task definition"
1355+
default = false
1356+
}
1357+
13521358
variable "aws_ecs_task_execution_role" {
13531359
type = string
13541360
description = "Elastic Container Service task execution role name."

operations/deployment/terraform/aws/bitovi_main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ module "aws_ecs" {
468468
aws_ecs_service_launch_type = var.aws_ecs_service_launch_type
469469
aws_ecs_task_type = var.aws_ecs_task_type
470470
aws_ecs_task_name = var.aws_ecs_task_name
471+
aws_ecs_task_ignore_definition = var.aws_ecs_task_ignore_definition
471472
aws_ecs_task_execution_role = var.aws_ecs_task_execution_role
472473
aws_ecs_task_json_definition_file = var.aws_ecs_task_json_definition_file
473474
aws_ecs_task_network_mode = var.aws_ecs_task_network_mode

operations/deployment/terraform/modules/aws/ecs/aws_ecs.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ resource "aws_ecs_task_definition" "ecs_task_from_json" {
7373
container_definitions = sensitive(file("../../ansible/clone_repo/app/${var.app_repo_name}/${local.aws_ecs_task_json_definition_file[count.index]}"))
7474
}
7575

76+
resource "aws_ecs_task_definition" "aws_ecs_task_ignore_definition" {
77+
count = var.aws_ecs_task_ignore_definition ? 1 : 0
78+
family = var.aws_ecs_task_name != "" ? local.aws_ecs_task_name[count.index + length(local.aws_ecs_app_image)] : "${local.aws_ecs_task_name[count.index + length(local.aws_ecs_app_image)]}${count.index+length(local.aws_ecs_app_image)}"
79+
network_mode = local.aws_ecs_task_network_mode[count.index + length(local.aws_ecs_app_image)]
80+
requires_compatibilities = ["${local.aws_ecs_task_type[count.index +length(local.aws_ecs_app_image)]}"]
81+
cpu = local.aws_ecs_task_cpu[count.index+length(local.aws_ecs_app_image)]
82+
memory = local.aws_ecs_task_mem[count.index+length(local.aws_ecs_app_image)]
83+
execution_role_arn = local.ecsTaskExecutionRole
84+
container_definitions = sensitive(jsonencode([
85+
{
86+
"name": "simple-web-server",
87+
"image": "nginx:alpine",
88+
"essential": true,
89+
"portMappings": [
90+
{
91+
"containerPort": 80,
92+
"protocol": "tcp"
93+
}
94+
]
95+
}
96+
]))
97+
lifecycle {
98+
ignore_changes = [container_definitions]
99+
}
100+
}
101+
76102
locals {
77103
tasks_arns = concat(aws_ecs_task_definition.ecs_task[*].arn,aws_ecs_task_definition.ecs_task_from_json[*].arn)
78104
tasks_count = length(local.aws_ecs_app_image) + length(local.aws_ecs_task_json_definition_file)

operations/deployment/terraform/modules/aws/ecs/aws_ecs_vars.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ variable "aws_ecs_cluster_name" {}
33
variable "aws_ecs_service_launch_type" {}
44
variable "aws_ecs_task_type" {}
55
variable "aws_ecs_task_name" {}
6+
variable "aws_ecs_task_ignore_definition" {}
67
variable "aws_ecs_task_execution_role" {}
78
variable "aws_ecs_task_json_definition_file" {}
89
variable "aws_ecs_task_network_mode" {}

0 commit comments

Comments
 (0)