-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.tf
101 lines (83 loc) · 2.2 KB
/
cluster.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
resource "aws_ecs_cluster" "app" {
name = "${var.app_name}-cluster"
service_connect_defaults {
namespace = aws_service_discovery_http_namespace.app.arn
}
configuration {
execute_command_configuration {
kms_key_id = aws_kms_key.app.id
logging = "DEFAULT"
}
}
setting {
name = "containerInsights"
value = "enabled"
}
}
resource "aws_ecs_cluster_capacity_providers" "app" {
cluster_name = aws_ecs_cluster.app.name
capacity_providers = ["FARGATE"]
}
resource "aws_service_discovery_http_namespace" "app" {
name = var.app_name
description = "${var.app_name} ECS services"
}
resource "aws_ecr_repository" "api" {
name = var.api_tags.Name
force_delete = true
image_scanning_configuration {
scan_on_push = true
}
tags = var.api_tags
}
resource "aws_ecr_repository" "web" {
name = var.web_tags.Name
force_delete = true
image_scanning_configuration {
scan_on_push = true
}
tags = var.web_tags
}
resource "aws_ecr_repository_policy" "web" {
policy = data.aws_iam_policy_document.repos.json
repository = aws_ecr_repository.web.name
}
resource "aws_ecr_repository_policy" "api" {
policy = data.aws_iam_policy_document.repos.json
repository = aws_ecr_repository.api.name
}
data "aws_iam_policy_document" "repos" {
statement {
principals {
type = "*"
identifiers = ["*"]
}
actions = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:DescribeRepositories",
"ecr:GetRepositoryPolicy",
"ecr:ListImages",
]
}
}
resource "aws_ecr_registry_scanning_configuration" "app" {
scan_type = "ENHANCED"
rule {
scan_frequency = "CONTINUOUS_SCAN"
repository_filter {
filter = "*${var.app_name}*"
filter_type = "WILDCARD"
}
}
}
resource "aws_vpc_endpoint" "logs" {
vpc_id = aws_vpc.app.id
service_name = "com.amazonaws.${data.aws_region.current.name}.logs"
vpc_endpoint_type = "Interface"
subnet_ids = local.web_subnet_ids
security_group_ids = [aws_security_group.endpoints.id]
private_dns_enabled = true
auto_accept = true
}