-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathplaywright.tf
More file actions
198 lines (179 loc) · 5.33 KB
/
playwright.tf
File metadata and controls
198 lines (179 loc) · 5.33 KB
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
resource "aws_iam_role" "playwright_worker_task_execution_role" {
name = "${var.crossfeed_playwright}-task-execution-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
Effect = "Allow"
}
]
})
}
resource "aws_iam_role" "playwright_worker_task_role" {
name = "${var.crossfeed_playwright}-worker-task-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Principal = {
Service = "ecs-tasks.amazonaws.com"
}
Effect = "Allow"
}
]
})
}
resource "aws_iam_role_policy" "playwright_ecs_task_policy" {
name = "${var.crossfeed_playwright}-ecs-task-policy"
role = aws_iam_role.playwright_worker_task_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = ["s3:ListBucket", "s3:GetObject", "s3:PutObject"]
Effect = "Allow"
Resource = [
"arn:aws:s3:::${var.automated_test_reports_bucket_name}", # ListBucket on the bucket itself
"arn:aws:s3:::${var.automated_test_reports_bucket_name}/*" # GetObject and PutObject on all objects within the bucket
]
}
]
})
}
resource "aws_iam_role_policy_attachment" "playwright_ecs_execution_policy" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
role = aws_iam_role.playwright_worker_task_execution_role.id
}
resource "aws_ecs_task_definition" "playwright_worker" {
family = var.playwright_worker_ecs_task_definition_family
container_definitions = <<EOF
[
{
"name": "main",
"image": "public.ecr.aws/sphmedia/sphmedia/microsoft-playwright:v1.50.1-jammy",
"essential": true,
"mountPoints": [],
"portMappings": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${var.worker_ecs_log_group_name}",
"awslogs-region": "${var.aws_region}",
"awslogs-stream-prefix": "playwright"
}
},
"environment": [
{
"name": "BROWSER_TYPE",
"value": "chromium"
},
{
"name": "TEST_URL",
"value": "${var.frontend_domain}"
}
],
"command": [
"sh",
"-c",
"echo 'Installing Playwright...'; npx playwright install --with-deps"
]
}
]
EOF
requires_compatibilities = ["FARGATE"]
# "awsvpc" is required for Fargate tasks to enable the use of ENIs for networking.
network_mode = "awsvpc"
execution_role_arn = aws_iam_role.playwright_worker_task_execution_role.arn # Execution role for ECS tasks
task_role_arn = aws_iam_role.playwright_worker_task_role.arn # Task role for the application
cpu = 256 # .25 vCPU
memory = 512 # 512 MB
tags = {
Project = var.project
Stage = var.stage
Owner = "Crossfeed managed resource"
}
}
resource "aws_ecs_cluster" "playwright_ecs_cluster" {
name = "${var.crossfeed_playwright}-ecs-cluster"
setting {
name = "containerInsights"
value = "enabled"
}
tags = {
Project = var.project
Stage = var.stage
Owner = "Crossfeed managed resource"
}
}
resource "aws_ecs_cluster_capacity_providers" "playwright_ecs_cluster_capacity_providers" {
cluster_name = aws_ecs_cluster.playwright_ecs_cluster.name
capacity_providers = ["FARGATE"]
}
resource "aws_s3_bucket" "automated_test_reports_bucket" {
bucket = var.automated_test_reports_bucket_name
tags = {
Project = var.project
Stage = var.stage
Owner = "Crossfeed managed resource"
}
}
resource "aws_s3_bucket_policy" "automated_test_reports_bucket" {
bucket = var.automated_test_reports_bucket_name
policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "RequireSSLRequests",
"Action" : "s3:*",
"Effect" : "Deny",
"Principal" : "*",
"Resource" : [
aws_s3_bucket.automated_test_reports_bucket.arn,
"${aws_s3_bucket.automated_test_reports_bucket.arn}/*"
],
"Condition" : {
"Bool" : {
"aws:SecureTransport" : "false"
}
}
}
]
})
}
resource "aws_s3_bucket_acl" "automated_test_reports_bucket" {
count = var.is_dmz ? 1 : 0
bucket = aws_s3_bucket.automated_test_reports_bucket.id
acl = "private"
}
resource "aws_s3_bucket_ownership_controls" "automated_test_reports_bucket" {
count = var.is_dmz ? 1 : 0
bucket = aws_s3_bucket.automated_test_reports_bucket.id
rule {
object_ownership = "ObjectWriter"
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "automated_test_reports_bucket" {
bucket = aws_s3_bucket.automated_test_reports_bucket.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_versioning" "automated_test_reports_bucket" {
bucket = aws_s3_bucket.automated_test_reports_bucket.id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_logging" "automated_test_reports_bucket" {
bucket = aws_s3_bucket.automated_test_reports_bucket.id
target_bucket = aws_s3_bucket.logging_bucket.id
target_prefix = "automated_test_reports_bucket/"
}