1
1
resource "aws_ecs_cluster" "default" {
2
- name = " ${ var . ecs_cluster_name } "
2
+ name = var. ecs_cluster_name
3
3
}
4
4
5
5
resource "aws_cloudwatch_log_group" "ecs_log_group" {
6
- name = " /ecs/wp-ecs-tf"
6
+ name = " /ecs/wp-ecs-tf"
7
7
retention_in_days = 7
8
8
9
9
tags = {
@@ -12,14 +12,8 @@ resource "aws_cloudwatch_log_group" "ecs_log_group" {
12
12
}
13
13
}
14
14
15
- data "aws_iam_role" "existing_ecs_task_execution_role" {
16
- name = " ecsTaskExecutionRole"
17
- }
18
-
19
15
resource "aws_iam_role" "ecs_task_execution_role" {
20
- count = length (data. aws_iam_role . existing_ecs_task_execution_role . arn ) == 0 ? 1 : 0
21
-
22
- name = " ecsTaskExecutionRole"
16
+ name = " ecsTaskExecutionRole-tf"
23
17
24
18
assume_role_policy = jsonencode ({
25
19
Version = " 2012-10-17"
@@ -36,21 +30,19 @@ resource "aws_iam_role" "ecs_task_execution_role" {
36
30
}
37
31
38
32
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy" {
39
- count = length (data. aws_iam_role . existing_ecs_task_execution_role . arn ) == 0 ? 1 : 0
40
-
41
- role = aws_iam_role. ecs_task_execution_role [count . index ]. name
33
+ role = aws_iam_role. ecs_task_execution_role . name
42
34
policy_arn = " arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
43
35
}
44
36
45
37
resource "aws_ecs_task_definition" "wordpress" {
46
- family = " wp-ecs-task-tf"
47
- container_definitions = data. template_file . wp-container . rendered
38
+ family = " wp-ecs-task-tf"
39
+ container_definitions = data. template_file . wp-container . rendered
48
40
requires_compatibilities = [" FARGATE" ]
49
- network_mode = " awsvpc"
50
- cpu = 512
51
- memory = 1024
41
+ network_mode = " awsvpc"
42
+ cpu = 512
43
+ memory = 1024
52
44
53
- execution_role_arn = length (data . aws_iam_role . existing_ecs_task_execution_role . arn ) == 0 ? aws_iam_role . ecs_task_execution_role [ 0 ] . arn : data . aws_iam_role . existing_ecs_task_execution_role . arn
45
+ execution_role_arn = aws_iam_role. ecs_task_execution_role . arn
54
46
55
47
runtime_platform {
56
48
operating_system_family = " LINUX"
@@ -59,21 +51,21 @@ resource "aws_ecs_task_definition" "wordpress" {
59
51
}
60
52
61
53
resource "aws_ecs_service" "wp-ecs-svc" {
62
- name = " wp-ecs-svc-tf"
63
- cluster = " ${ aws_ecs_cluster . default . id } "
64
- task_definition = " ${ aws_ecs_task_definition . wordpress . arn } "
65
- desired_count = 1
66
- launch_type = " FARGATE"
67
-
68
- load_balancer {
69
- target_group_arn = " ${ aws_lb_target_group . default . arn } "
70
- container_name = " wordpress"
71
- container_port = 80
72
- }
54
+ name = " wp-ecs-svc-tf"
55
+ cluster = aws_ecs_cluster. default . id
56
+ task_definition = aws_ecs_task_definition. wordpress . arn
57
+ desired_count = 1
58
+ launch_type = " FARGATE"
73
59
74
- network_configuration {
75
- subnets = [" ${ aws_subnet . wp-public-a-tf . id } " , " ${ aws_subnet . wp-public-b-tf . id } " , " ${ aws_subnet . wp-public-c-tf . id } " ]
76
- security_groups = [" ${ aws_security_group . wp-alb-tf . id } " ]
77
- assign_public_ip = true
78
- }
60
+ load_balancer {
61
+ target_group_arn = aws_lb_target_group. default . arn
62
+ container_name = " wordpress"
63
+ container_port = 80
64
+ }
65
+
66
+ network_configuration {
67
+ subnets = [aws_subnet . wp-public-a-tf . id , aws_subnet . wp-public-b-tf . id , aws_subnet . wp-public-c-tf . id ]
68
+ security_groups = [aws_security_group . wp-alb-tf . id ]
69
+ assign_public_ip = true
70
+ }
79
71
}
0 commit comments