|
| 1 | +resource "random_id" "bucket_suffix" { |
| 2 | + byte_length = 4 |
| 3 | +} |
| 4 | + |
| 5 | +resource "random_string" "suffix" { |
| 6 | + length = 4 |
| 7 | + special = false |
| 8 | + upper = false |
| 9 | +} |
| 10 | + |
1 | 11 | module "access_logs_bucket" { |
2 | 12 | source = "boldlink/s3/aws" |
3 | 13 | version = "2.3.1" |
@@ -194,3 +204,64 @@ module "ecs_service_nlb" { |
194 | 204 | lb_ingress_rules = var.nlb_ingress_rules |
195 | 205 | depends_on = [module.access_logs_bucket] |
196 | 206 | } |
| 207 | + |
| 208 | +module "ecs_service_fargate_spot" { |
| 209 | + #checkov:skip=CKV_AWS_290: "Ensure IAM policies does not allow write access without constraints" |
| 210 | + #checkov:skip=CKV_AWS_355: "Ensure no IAM policies documents allow "*" as a statement's resource for restrictable actions" |
| 211 | + source = "../../" |
| 212 | + requires_compatibilities = var.requires_compatibilities |
| 213 | + network_mode = var.network_mode |
| 214 | + name = "${var.name}-fargate-spot-service" |
| 215 | + family = "${var.name}-fargate-spot-task-definition" |
| 216 | + enable_execute_command = var.enable_execute_command |
| 217 | + |
| 218 | + # Use capacity provider strategy instead of launch_type for FARGATE_SPOT |
| 219 | + capacity_provider_strategy = [ |
| 220 | + { |
| 221 | + capacity_provider = "FARGATE_SPOT" |
| 222 | + weight = 4 |
| 223 | + base = 0 |
| 224 | + }, |
| 225 | + { |
| 226 | + capacity_provider = "FARGATE" |
| 227 | + weight = 1 |
| 228 | + base = 1 |
| 229 | + } |
| 230 | + ] |
| 231 | + |
| 232 | + network_configuration = { |
| 233 | + subnets = local.private_subnets |
| 234 | + assign_public_ip = true |
| 235 | + } |
| 236 | + |
| 237 | + cluster = local.cluster |
| 238 | + vpc_id = local.vpc_id |
| 239 | + task_assume_role_policy = data.aws_iam_policy_document.ecs_assume_role_policy.json |
| 240 | + task_role_policy = data.aws_iam_policy_document.task_role_policy_doc.json |
| 241 | + task_execution_assume_role_policy = data.aws_iam_policy_document.ecs_assume_role_policy.json |
| 242 | + task_execution_role_policy = local.task_execution_role_policy_doc |
| 243 | + container_definitions = local.fargate_spot_container_definitions |
| 244 | + kms_key_id = data.aws_kms_alias.supporting_kms.target_key_arn |
| 245 | + force_new_deployment = var.force_new_deployment |
| 246 | + desired_count = 3 |
| 247 | + tasks_minimum_healthy_percent = 50 |
| 248 | + tasks_maximum_percent = 200 |
| 249 | + propagate_tags = "SERVICE" |
| 250 | + tags = merge(local.tags, { |
| 251 | + CostOptimization = "fargate-spot" |
| 252 | + Service = "fargate-spot-demo" |
| 253 | + }) |
| 254 | + |
| 255 | + # Service security group rules for direct access (no load balancer) |
| 256 | + service_ingress_rules = [ |
| 257 | + { |
| 258 | + from_port = var.containerport |
| 259 | + to_port = var.containerport |
| 260 | + protocol = "tcp" |
| 261 | + description = "HTTP access to fargate spot service" |
| 262 | + cidr_blocks = [local.vpc_cidr] |
| 263 | + } |
| 264 | + ] |
| 265 | + |
| 266 | + retention_in_days = var.retention_in_days |
| 267 | +} |
0 commit comments