-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
105 lines (87 loc) · 2.35 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
locals{
}
resource "aws_codedeploy_app" "codedeploy_app" {
name = "ecs-${var.env_name}-deploy"
compute_platform = "ECS"
}
resource "aws_codedeploy_deployment_group" "deployment_group" {
app_name = aws_codedeploy_app.codedeploy_app.name
deployment_config_name = "CodeDeployDefault.ECSAllAtOnce"
deployment_group_name = "ecs-${var.env_name}-deploy-group"
service_role_arn = aws_iam_role.codedeploy_role.arn
auto_rollback_configuration {
enabled = true
events = ["DEPLOYMENT_FAILURE"]
}
blue_green_deployment_config {
deployment_ready_option {
action_on_timeout = "CONTINUE_DEPLOYMENT"
}
terminate_blue_instances_on_deployment_success {
action = "TERMINATE"
termination_wait_time_in_minutes = 5
}
}
deployment_style {
deployment_option = "WITH_TRAFFIC_CONTROL"
deployment_type = "BLUE_GREEN"
}
ecs_service {
cluster_name = var.ecs_cluster_name
service_name = var.ecs_service_name
}
load_balancer_info {
target_group_pair_info {
prod_traffic_route {
listener_arns = [var.alb_listener_arn]
}
target_group {
name = var.alb_tg_blue_name
}
target_group {
name = var.alb_tg_green_name
}
}
}
}
resource "aws_iam_role" "codedeploy_role" {
name = "role-codedeploy-chorus-${var.env_name}"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "codedeploy.amazonaws.com"
}
},
]
})
}
resource "aws_iam_role_policy" "cloudWatch_policy" {
name = "policy-${var.env_name}-cloudWatch_policy"
role = aws_iam_role.codedeploy_role.id
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_iam_role_policy" "ecs_policy" {
name = "policy-${var.env_name}-ecs_policy"
role = aws_iam_role.codedeploy_role.id
policy = data.aws_iam_policy_document.codedeploy_role_policy.json
}