Guest User

Untitled

a guest
Dec 12th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. resource "aws_security_group" "ecs_service" {
  2. vpc_id = "${var.vpc_id}"
  3. name_prefix = "${var.environment}-ecs-service-sg"
  4. description = "Allow egress from container"
  5.  
  6. egress {
  7. from_port = 0
  8. to_port = 0
  9. protocol = "-1"
  10. cidr_blocks = ["0.0.0.0/0"]
  11. }
  12.  
  13. ingress {
  14. from_port = 8
  15. to_port = 0
  16. protocol = "icmp"
  17. cidr_blocks = ["0.0.0.0/0"]
  18. }
  19.  
  20. tags {
  21. Name = "${var.environment}-ecs-service-sg"
  22. Environment = "${var.environment}"
  23. }
  24.  
  25. lifecycle {
  26. create_before_destroy = true
  27. }
  28. }
  29.  
  30. /* Simply specify the family to find the latest ACTIVE revision in that family */
  31. data "aws_ecs_task_definition" "web" {
  32. depends_on = ["aws_ecs_task_definition.web"]
  33. task_definition = "${aws_ecs_task_definition.web.family}"
  34. }
  35.  
  36. resource "aws_ecs_service" "web" {
  37. name = "${var.environment}-web"
  38. task_definition = "${aws_ecs_task_definition.web.family}:${max("${aws_ecs_task_definition.web.revision}", "${data.aws_ecs_task_definition.web.revision}")}"
  39. desired_count = 2
  40. launch_type = "FARGATE"
  41. cluster = "${aws_ecs_cluster.cluster.id}"
  42. depends_on = ["aws_iam_role_policy.ecs_service_role_policy"]
  43.  
  44. network_configuration {
  45. security_groups = ["${var.security_groups_ids}", "${aws_security_group.ecs_service.id}"]
  46. subnets = ["${var.subnets_ids}"]
  47. }
  48.  
  49. load_balancer {
  50. target_group_arn = "${aws_alb_target_group.alb_target_group.arn}"
  51. container_name = "web"
  52. container_port = "80"
  53. }
  54.  
  55. depends_on = ["aws_alb_target_group.alb_target_group"]
  56. }
Add Comment
Please, Sign In to add comment