Skip to content

Commit e83cf54

Browse files
authored
Merge pull request #243 from rylev/builder-autoscale
Add an autoscaling group for the docs-rs-builder
2 parents 6f47313 + 743d0e8 commit e83cf54

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

terragrunt/accounts/docs-rs-staging/docs-rs/terragrunt.hcl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ inputs = {
2525
private_subnet_ids = dependency.vpc.outputs.private_subnets
2626
domain = "docs-rs-staging.rust-lang.net"
2727
bastion_security_group_id = dependency.vpc.outputs.bastion_security_group_id
28+
min_num_builder_instances = 1
29+
max_num_builder_instances = 1
2830
}

terragrunt/modules/docs-rs/builder.tf

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,57 @@
1-
// The instance profile the builder will assume when communicating with
2-
// other AWS services.
1+
// The autoscaling group for the builder
2+
3+
resource "aws_autoscaling_group" "builder" {
4+
name = "docs-rs-builder"
5+
vpc_zone_identifier = var.cluster_config.subnet_ids
6+
max_size = var.max_num_builder_instances
7+
min_size = var.min_num_builder_instances
8+
# Let the instances get warm
9+
default_instance_warmup = 60
10+
11+
launch_template {
12+
id = aws_launch_template.builder.id
13+
version = "$Latest"
14+
}
15+
}
16+
17+
resource "aws_launch_template" "builder" {
18+
name_prefix = "builder"
19+
image_id = data.aws_ami.builder.id
20+
instance_type = "t2.large"
21+
22+
network_interfaces {
23+
associate_public_ip_address = true
24+
security_groups = [aws_security_group.builder.id]
25+
}
26+
27+
iam_instance_profile {
28+
arn = aws_iam_instance_profile.builder.arn
29+
}
30+
31+
block_device_mappings {
32+
device_name = "/dev/sda1"
33+
34+
ebs {
35+
volume_size = 64
36+
delete_on_termination = true
37+
}
38+
}
39+
40+
tag_specifications {
41+
resource_type = "instance"
42+
43+
tags = {
44+
Name = "docs-rs-builder"
45+
}
46+
}
47+
}
48+
49+
data "aws_ami" "builder" {
50+
most_recent = true
51+
name_regex = "^docs-rs-builder-*"
52+
}
53+
54+
// The instance profile the builder will assume when communicating with s3
355

456
resource "aws_iam_instance_profile" "builder" {
557
name = "builder"
@@ -47,3 +99,41 @@ resource "aws_iam_role_policy" "builder_s3" {
4799
]
48100
})
49101
}
102+
103+
// Security group allowing all egress and ssh ingress from the bastion instance
104+
resource "aws_security_group" "builder" {
105+
vpc_id = var.cluster_config.vpc_id
106+
name = "docs-rs-builder"
107+
description = "Access rules for the docs-rs builder."
108+
109+
// SSH access from the bastion instance
110+
ingress {
111+
from_port = 22
112+
to_port = 22
113+
protocol = "tcp"
114+
description = "SSH access from bastion"
115+
security_groups = [aws_security_group.web.id]
116+
}
117+
118+
// Allow outgoing connections
119+
120+
egress {
121+
from_port = 0
122+
to_port = 0
123+
protocol = -1
124+
cidr_blocks = ["0.0.0.0/0"]
125+
description = "Allow all IPv4 egress traffic."
126+
}
127+
128+
egress {
129+
from_port = 0
130+
to_port = 0
131+
protocol = -1
132+
ipv6_cidr_blocks = ["::/0"]
133+
description = "Allow all IPv6 egress traffic."
134+
}
135+
136+
tags = {
137+
Name = "docs-rs-builder"
138+
}
139+
}

terragrunt/modules/docs-rs/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ variable "cluster_config" {
2929
})
3030
description = "The configuration for the cluster this is running in"
3131
}
32+
33+
variable "min_num_builder_instances" {
34+
type = number
35+
description = "The minimum number of builder instances there should be"
36+
}
37+
38+
variable "max_num_builder_instances" {
39+
type = number
40+
description = "The maximum number of builder instances there should be"
41+
}

0 commit comments

Comments
 (0)