-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
188 lines (167 loc) · 5.56 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
data "aws_ssm_parameter" "environment" {
for_each = toset(local.secret_variables)
name = "/atlantis/${each.key}"
}
data "aws_vpc" "selected" {
id = var.vpc_id
}
data "aws_ecs_cluster" "default" {
cluster_name = var.ecs_cluster_name
}
data "aws_iam_policy_document" "ecs_task_assume_policy" {
statement {
actions = local.ecs_task_assume_policy_actions
principals {
type = local.ecs_task_assume_policy_principal_type
identifiers = local.ecs_task_assume_policy_principal_identifiers
}
}
}
data "aws_route53_zone" "zone" {
name = local.base_domain
}
module "ecs_deployment" {
source = "infraspecdev/ecs-deployment/aws"
version = "4.0.4"
cluster_name = data.aws_ecs_cluster.default.cluster_name
vpc_id = var.vpc_id
task_definition = {
family = local.ecs_task_definition_family
network_mode = local.task_definition_network_mode
execution_role_arn = aws_iam_role.task_role.arn
container_definitions = [{
name = local.ecs_container_definations_name
image = var.atlantis_docker_image
container_port = local.container_port
environment = local.env_variables
secrets = local.secrets
memoryReservation = local.container_memory_reservation
portMappings = [
{
containerPort = local.container_port
hostPort = local.container_port
}
]
}]
cpu = try(var.ecs_launch_type_cpu, null)
memory = try(var.ecs_launch_type_memory, null)
volume = {}
}
service = {
name = local.ecs_service_name
desired_count = var.ecs_service_desired_count != null ? var.ecs_service_desired_count : local.default_desired_count
load_balancer = [{
container_name = local.ecs_container_definations_name
container_port = local.container_port
target_group = local.target_group_name
}]
network_configuration = {
subnets = var.private_subnet_ids
security_groups = [aws_security_group.ecs.id]
}
}
load_balancer = {
name = local.alb_system_name
internal = local.load_balancer_internal
subnets_ids = var.public_subnet_ids
security_groups_ids = [aws_security_group.alb.id]
target_groups = {
(local.target_group_name) = {
name = format("%s-%s-ip", local.alb_system_name, terraform.workspace)
port = local.container_port
protocol = local.target_group_protocol
target_type = local.alb_ip_target_type
}
}
listeners = {
https-listener = {
protocol = local.listener_protocol
port = local.listener_port
certificate = local.acm_certificate_name
default_action = [
{
type = local.default_action_type
target_group = local.target_group_name
fixed_response = {
content_type = local.fixed_response_content_type
message_body = local.fixed_response_message_body
status_code = local.fixed_response_status_code
}
}
]
}
}
listener_rules = {
https-listener-rules = {
listener = local.listener_name
priority = local.listener_priority
condition = [
{
host_header = {
values = [var.atlantis_url]
}
}
]
action = [
{
type = local.authenticate_oidc_type
authenticate_oidc = {
authorization_endpoint = local.authenticate_oidc_authorization_endpoint
token_endpoint = local.authenticate_oidc_token_endpoint
user_info_endpoint = local.authenticate_oidc_user_info_endpoint
issuer = local.authenticate_oidc_issuer
session_cookie_name = format("TOKEN-OIDC-%s", data.aws_ssm_parameter.environment["ATLANTIS_GOOGLE_CLIENT_ID"].value)
scope = local.authenticate_oidc_scope
on_unauthenticated_request = local.authenticate_oidc_on_unauthenticated_request
client_id = data.aws_ssm_parameter.environment["ATLANTIS_GOOGLE_CLIENT_ID"].value
client_secret = data.aws_ssm_parameter.environment["ATLANTIS_GOOGLE_CLIENT_SECRET"].value
}
},
{
target_group = local.target_group_name
type = local.forward_action_type
}
]
},
http-listener-rules = {
listener = local.listener_name
priority = local.http_listener_priority
condition = [
{
path_pattern = {
values = local.path_pattern_values
}
},
{
http_request_method = {
values = local.http_request_method_values
}
},
{
host_header = {
values = [var.atlantis_url]
}
}
]
action = [
{
target_group = local.target_group_name
type = local.forward_action_type
}
]
}
}
}
create_capacity_provider = local.create_capacity_provider
create_acm = true
acm_certificates = {
(local.acm_certificate_name) = {
domain_name = var.atlantis_url
validation_option = {
domain_name = var.atlantis_url
validation_domain = var.atlantis_url
}
record_zone_id = data.aws_route53_zone.zone.zone_id
}
}
}