|
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 |
3 | 55 |
|
4 | 56 | resource "aws_iam_instance_profile" "builder" {
|
5 | 57 | name = "builder"
|
@@ -47,3 +99,41 @@ resource "aws_iam_role_policy" "builder_s3" {
|
47 | 99 | ]
|
48 | 100 | })
|
49 | 101 | }
|
| 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 | +} |
0 commit comments