generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.tf
203 lines (172 loc) · 6.67 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
provider "aws" {
region = var.region
}
module "vpc" {
source = "cloudposse/vpc/aws"
version = "2.1.0"
ipv4_primary_cidr_block = var.vpc_cidr_block
context = module.this.context
}
module "subnets" {
source = "cloudposse/dynamic-subnets/aws"
version = "2.3.0"
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false
context = module.this.context
}
module "blue_target_group_label" {
source = "cloudposse/label/null"
version = "0.24.1"
attributes = ["blue"]
context = module.this.context
}
module "green_target_group_label" {
source = "cloudposse/label/null"
version = "0.24.1"
attributes = ["green"]
context = module.this.context
}
module "alb" {
source = "cloudposse/alb/aws"
version = "0.29.6"
vpc_id = module.vpc.vpc_id
security_group_ids = [module.vpc.vpc_default_security_group_id]
subnet_ids = module.subnets.public_subnet_ids
internal = var.internal
http_enabled = var.http_enabled
access_logs_enabled = var.access_logs_enabled
alb_access_logs_s3_bucket_force_destroy = var.alb_access_logs_s3_bucket_force_destroy
cross_zone_load_balancing_enabled = var.cross_zone_load_balancing_enabled
http2_enabled = var.http2_enabled
idle_timeout = var.idle_timeout
ip_address_type = var.ip_address_type
deletion_protection_enabled = var.deletion_protection_enabled
deregistration_delay = var.deregistration_delay
health_check_path = var.health_check_path
health_check_port = var.health_check_port
health_check_timeout = var.health_check_timeout
health_check_healthy_threshold = var.health_check_healthy_threshold
health_check_unhealthy_threshold = var.health_check_unhealthy_threshold
health_check_interval = var.health_check_interval
health_check_matcher = var.health_check_matcher
target_group_port = var.target_group_port
target_group_target_type = var.target_group_target_type
target_group_name = module.blue_target_group_label.id
context = module.this.context
}
resource "aws_lb_target_group" "green" {
name = module.green_target_group_label.id
port = var.target_group_port
protocol = var.target_group_protocol
vpc_id = module.vpc.vpc_id
target_type = var.target_group_target_type
deregistration_delay = var.deregistration_delay
health_check {
protocol = var.target_group_protocol
path = var.health_check_path
port = var.health_check_port
timeout = var.health_check_timeout
healthy_threshold = var.health_check_healthy_threshold
unhealthy_threshold = var.health_check_unhealthy_threshold
interval = var.health_check_interval
matcher = var.health_check_matcher
}
tags = module.green_target_group_label.tags
}
resource "aws_ecs_cluster" "default" {
name = module.this.id
tags = module.this.tags
}
module "container_definition" {
source = "cloudposse/ecs-container-definition/aws"
version = "0.51.0"
container_name = var.container_name
container_image = var.container_image
container_memory = var.container_memory
container_memory_reservation = var.container_memory_reservation
container_cpu = var.container_cpu
essential = var.container_essential
readonly_root_filesystem = var.container_readonly_root_filesystem
environment = var.container_environment
port_mappings = var.container_port_mappings
}
module "ecs_alb_service_task" {
source = "cloudposse/ecs-alb-service-task/aws"
version = "0.54.1"
alb_security_group = module.vpc.vpc_default_security_group_id
container_definition_json = module.container_definition.json_map_encoded_list
ecs_cluster_arn = aws_ecs_cluster.default.arn
launch_type = var.ecs_launch_type
vpc_id = module.vpc.vpc_id
security_group_ids = [module.vpc.vpc_default_security_group_id]
subnet_ids = module.subnets.public_subnet_ids
ignore_changes_task_definition = var.ignore_changes_task_definition
network_mode = var.network_mode
assign_public_ip = var.assign_public_ip
propagate_tags = var.propagate_tags
deployment_minimum_healthy_percent = var.deployment_minimum_healthy_percent
deployment_maximum_percent = var.deployment_maximum_percent
deployment_controller_type = var.deployment_controller_type
desired_count = var.desired_count
task_memory = var.task_memory
task_cpu = var.task_cpu
ecs_load_balancers = [
{
container_name = var.container_name
container_port = 80
elb_name = null
target_group_arn = module.alb.default_target_group_arn
}
]
context = module.this.context
depends_on = [
module.alb
]
}
module "code_deploy_blue_green" {
source = "../.."
context = module.this.context
minimum_healthy_hosts = null
traffic_routing_config = {
type = "TimeBasedLinear"
interval = 10
percentage = 10
}
deployment_style = {
deployment_option = "WITH_TRAFFIC_CONTROL"
deployment_type = "BLUE_GREEN"
}
blue_green_deployment_config = {
deployment_ready_option = {
action_on_timeout = "STOP_DEPLOYMENT"
wait_time_in_minutes = 10
}
terminate_blue_instances_on_deployment_success = {
action = "TERMINATE"
termination_wait_time_in_minutes = 5
}
}
ecs_service = [
{
cluster_name = aws_ecs_cluster.default.name
service_name = module.ecs_alb_service_task.service_name
}
]
load_balancer_info = {
target_group_pair_info = {
prod_traffic_route = {
listener_arns = [module.alb.http_listener_arn]
}
blue_target_group = {
name = module.alb.default_target_group_arn
}
green_target_group = {
name = aws_lb_target_group.green.arn
}
}
}
}