forked from tlc-pack/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoscalers.tf
111 lines (105 loc) · 3.32 KB
/
autoscalers.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
locals {
agent_subnet_ids = [for name, subnet in var.private_subnet_ids :
subnet if split("-", name)[0] == "agents"
]
}
resource "aws_iam_role" "autoscalers" {
name = "autoscalers_role"
description = "gives jenkins nodes ecr and s3 permissions"
# Terraform's "jsonencode" function converts a
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy" "autoscalers" {
name = "describeTags"
role = aws_iam_role.autoscalers.id
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SccacheAccess",
"Effect": "Allow",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::tvm-sccache-${var.environment}/*"
},
{
"Sid": "ArtifactsAccess",
"Effect": "Allow",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::jenkins-artifacts-${var.environment}/*"
},
{
"Sid": "ECRAccess1",
"Effect": "Allow",
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:CompleteLayerUpload",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:ListImages",
"ecr:PutImage",
"ecr:TagResource",
"ecr:UploadLayerPart"
],
"Resource": "*"
},
{
"Sid": "ECRAccess2",
"Effect": "Allow",
"Action": [
"ecr:DescribeRegistry",
"ecr:GetAuthorizationToken"
],
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "autoscalers" {
name = "autoscalers_instance_profile"
role = aws_iam_role.autoscalers.name
}
module "Jenkins-Autoscalers" {
for_each = var.autoscaler_types
source = "./modules/autoscaler"
autoscaler_name = each.key
subnet_ids = var.is_private ? local.agent_subnet_ids : local.frontend_subnet_ids
security_groups = [aws_security_group.ssh_inbound.id, aws_security_group.egress.id]
image_family = each.value.image_family
agent_instance_type = each.value.agent_instance_type
jenkins_pub_key = var.jenkins_pub_key
jenkins_instance_profile = aws_iam_instance_profile.autoscalers.name
executor_access_pub_keys = var.executor_access_pub_keys
min_size = each.value.min_size
max_size = each.value.max_size
on_demand_base_capacity = each.value.on_demand_base_capacity
on_demand_percentage_above_base_capacity = each.value.on_demand_percentage_above_base_capacity
}