-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.tf
100 lines (90 loc) · 2.42 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_kms_key" "cluster" {
description = "KMS Key Fargate cluster"
deletion_window_in_days = 7
policy = jsonencode({
Id = "Allow CloudWatch & SSM"
Statement = [
{
Sid = "Enable IAM User Permissions",
Effect = "Allow",
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
},
Action = "kms:*",
Resource = "*"
},
{
Sid = "Enable IAM User Permissions"
Action = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
Effect = "Allow"
Principal = {
Service = "logs.${local.current_region}.amazonaws.com"
}
Resource = "*"
Condition = {
ArnLike = {
"kms:EncryptionContext:aws:logs:arn" : "arn:aws:logs:${local.current_region}:${data.aws_caller_identity.current.account_id}:*"
}
}
},
{
Sid = "Enable IAM User Permissions"
Action = [
"kms:Encrypt*",
"kms:Decrypt*",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:Describe*"
]
Effect = "Allow"
Principal = {
Service = "ssm.amazonaws.com"
}
Resource = "*"
}
]
Version = "2012-10-17"
}
)
}
resource "aws_kms_alias" "cluster" {
name = "alias/${local.resources_prefix}-fargate"
target_key_id = aws_kms_key.cluster.arn
}
resource "aws_cloudwatch_log_group" "cluster" {
name = "${local.resources_prefix}-cluster-logs"
retention_in_days = 7
kms_key_id = aws_kms_key.cluster.arn
}
resource "aws_ecs_cluster" "main" {
name = "${local.resources_prefix}-cluster"
configuration {
execute_command_configuration {
# kms_key_id = aws_kms_key.cluster.arn
logging = "OVERRIDE"
log_configuration {
cloud_watch_encryption_enabled = true
cloud_watch_log_group_name = aws_cloudwatch_log_group.cluster.name
}
}
}
setting {
name = "containerInsights"
value = "disabled"
}
}
resource "aws_ecs_cluster_capacity_providers" "main" {
cluster_name = aws_ecs_cluster.main.name
capacity_providers = ["FARGATE"]
default_capacity_provider_strategy {
base = 1
weight = 100
capacity_provider = "FARGATE"
}
}