@@ -869,11 +869,11 @@ module "container_definition" {
869
869
870
870
locals {
871
871
create_task_definition = var. create && var. create_task_definition
872
- task_definition = local. create_task_definition ? aws_ecs_task_definition. this [0 ]. arn : var. task_definition_arn
872
+ task_definition = local. create_task_definition ? try ( aws_ecs_task_definition. this [0 ]. arn , aws_ecs_task_definition . ignore_task_definition_changes [ 0 ] . arn ) : var. task_definition_arn
873
873
}
874
874
875
875
resource "aws_ecs_task_definition" "this" {
876
- count = local. create_task_definition ? 1 : 0
876
+ count = local. create_task_definition && ! var . ignore_task_definition_changes ? 1 : 0
877
877
878
878
region = var. region
879
879
@@ -1006,6 +1006,141 @@ resource "aws_ecs_task_definition" "this" {
1006
1006
}
1007
1007
}
1008
1008
1009
+ resource "aws_ecs_task_definition" "ignore_task_definition_changes" {
1010
+ count = local. create_task_definition && var. ignore_task_definition_changes ? 1 : 0
1011
+
1012
+ region = var. region
1013
+
1014
+ # Convert map of maps to array of maps before JSON encoding
1015
+ container_definitions = jsonencode ([for k , v in module . container_definition : v . container_definition ])
1016
+ cpu = var. cpu
1017
+ enable_fault_injection = var. enable_fault_injection
1018
+
1019
+ dynamic "ephemeral_storage" {
1020
+ for_each = var. ephemeral_storage != null ? [var . ephemeral_storage ] : []
1021
+
1022
+ content {
1023
+ size_in_gib = ephemeral_storage. value . size_in_gib
1024
+ }
1025
+ }
1026
+
1027
+ execution_role_arn = try (aws_iam_role. task_exec [0 ]. arn , var. task_exec_iam_role_arn )
1028
+ family = coalesce (var. family , var. name )
1029
+
1030
+ ipc_mode = var. ipc_mode
1031
+ memory = var. memory
1032
+ network_mode = var. network_mode
1033
+ pid_mode = var. pid_mode
1034
+
1035
+ dynamic "placement_constraints" {
1036
+ for_each = var. task_definition_placement_constraints != null ? var. task_definition_placement_constraints : {}
1037
+
1038
+ content {
1039
+ expression = placement_constraints. value . expression
1040
+ type = placement_constraints. value . type
1041
+ }
1042
+ }
1043
+
1044
+ dynamic "proxy_configuration" {
1045
+ for_each = var. proxy_configuration != null ? [var . proxy_configuration ] : []
1046
+
1047
+ content {
1048
+ container_name = proxy_configuration. value . container_name
1049
+ properties = proxy_configuration. value . properties
1050
+ type = proxy_configuration. value . type
1051
+ }
1052
+ }
1053
+
1054
+ requires_compatibilities = var. requires_compatibilities
1055
+
1056
+ dynamic "runtime_platform" {
1057
+ for_each = var. runtime_platform != null ? [var . runtime_platform ] : []
1058
+
1059
+ content {
1060
+ cpu_architecture = runtime_platform. value . cpu_architecture
1061
+ operating_system_family = runtime_platform. value . operating_system_family
1062
+ }
1063
+ }
1064
+
1065
+ skip_destroy = var. skip_destroy
1066
+ task_role_arn = try (aws_iam_role. tasks [0 ]. arn , var. tasks_iam_role_arn )
1067
+ track_latest = var. track_latest
1068
+
1069
+ dynamic "volume" {
1070
+ for_each = var. volume != null ? var. volume : {}
1071
+
1072
+ content {
1073
+ configure_at_launch = volume. value . configure_at_launch
1074
+
1075
+ dynamic "docker_volume_configuration" {
1076
+ for_each = volume. value . docker_volume_configuration != null ? [volume . value . docker_volume_configuration ] : []
1077
+
1078
+ content {
1079
+ autoprovision = docker_volume_configuration. value . autoprovision
1080
+ driver = docker_volume_configuration. value . driver
1081
+ driver_opts = docker_volume_configuration. value . driver_opts
1082
+ labels = docker_volume_configuration. value . labels
1083
+ scope = docker_volume_configuration. value . scope
1084
+ }
1085
+ }
1086
+
1087
+ dynamic "efs_volume_configuration" {
1088
+ for_each = volume. value . efs_volume_configuration != null ? [volume . value . efs_volume_configuration ] : []
1089
+
1090
+ content {
1091
+ dynamic "authorization_config" {
1092
+ for_each = efs_volume_configuration. value . authorization_config != null ? [efs_volume_configuration . value . authorization_config ] : []
1093
+
1094
+ content {
1095
+ access_point_id = authorization_config. value . access_point_id
1096
+ iam = authorization_config. value . iam
1097
+ }
1098
+ }
1099
+
1100
+ file_system_id = efs_volume_configuration. value . file_system_id
1101
+ root_directory = efs_volume_configuration. value . root_directory
1102
+ transit_encryption = efs_volume_configuration. value . transit_encryption
1103
+ transit_encryption_port = efs_volume_configuration. value . transit_encryption_port
1104
+ }
1105
+ }
1106
+
1107
+ dynamic "fsx_windows_file_server_volume_configuration" {
1108
+ for_each = volume. value . fsx_windows_file_server_volume_configuration != null ? [volume . value . fsx_windows_file_server_volume_configuration ] : []
1109
+
1110
+ content {
1111
+ dynamic "authorization_config" {
1112
+ for_each = fsx_windows_file_server_volume_configuration. value . authorization_config != null ? [fsx_windows_file_server_volume_configuration . value . authorization_config ] : []
1113
+
1114
+ content {
1115
+ credentials_parameter = authorization_config. value . credentials_parameter
1116
+ domain = authorization_config. value . domain
1117
+ }
1118
+ }
1119
+
1120
+ file_system_id = fsx_windows_file_server_volume_configuration. value . file_system_id
1121
+ root_directory = fsx_windows_file_server_volume_configuration. value . root_directory
1122
+ }
1123
+ }
1124
+
1125
+ host_path = volume. value . host_path
1126
+ name = coalesce (volume. value . name , volume. key )
1127
+ }
1128
+ }
1129
+
1130
+ tags = merge (var. tags , var. task_tags )
1131
+
1132
+ depends_on = [
1133
+ aws_iam_role_policy_attachment . tasks ,
1134
+ aws_iam_role_policy_attachment . task_exec ,
1135
+ aws_iam_role_policy_attachment . task_exec_additional ,
1136
+ ]
1137
+
1138
+ lifecycle {
1139
+ create_before_destroy = true
1140
+ ignore_changes = [container_definitions ]
1141
+ }
1142
+ }
1143
+
1009
1144
# ###############################################################################
1010
1145
# Task Execution - IAM Role
1011
1146
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html
0 commit comments