github.com/tetrafolium/tflint@v0.8.0/tflint/test-fixtures/v0.11.0_module/.terraform/modules/75f06b5c36dd1be566ec9e32e6aca4b5/ecs.tf (about)

     1  resource "aws_iam_policy_attachment" "ecs_service" {
     2    name       = "${var.app_name}-ecs-service"
     3    roles      = ["${aws_iam_role.ecs_service.name}"]
     4    policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
     5  }
     6  
     7  resource "aws_iam_role" "ecs_service" {
     8    name = "${var.app_name}-ec2-service"
     9  
    10    assume_role_policy = <<EOF
    11  {
    12      "Version": "2008-10-17",
    13      "Statement": [
    14        {
    15          "Action": "sts:AssumeRole",
    16          "Principal": {
    17            "Service": "ecs.amazonaws.com"
    18          },
    19          "Effect": "Allow",
    20          "Sid": ""
    21        }
    22      ]
    23  }
    24  EOF
    25  }
    26  
    27  resource "aws_ecs_cluster" "main" {
    28    name = "${var.app_name}"
    29  }
    30  
    31  resource "aws_ecs_task_definition" "main" {
    32    family = "${var.app_name}"
    33  
    34    container_definitions = <<DEFINITIONS
    35  [
    36    {
    37      "cpu": ${var.cpu_unit},
    38      "essential": true,
    39      "image": "${var.image}",
    40      "memory": ${var.memory},
    41      "name": "${var.app_name}",
    42      "portMappings": [
    43        {
    44          "containerPort": ${var.container_port}
    45        }
    46      ]
    47    }
    48  ]
    49  DEFINITIONS
    50  }
    51  
    52  resource "aws_ecs_service" "main" {
    53    name            = "${var.app_name}"
    54    cluster         = "${aws_ecs_cluster.main.id}"
    55    task_definition = "${aws_ecs_task_definition.main.arn}"
    56    desired_count   = "${var.service_count}"
    57    iam_role        = "${aws_iam_role.ecs_service.arn}"
    58  
    59    load_balancer {
    60      target_group_arn = "${aws_alb_target_group.main.id}"
    61      container_name   = "${var.app_name}"
    62      container_port   = "${var.container_port}"
    63    }
    64  }