Skip to content

Commit

Permalink
feat: provision ubuntu 24 playground ec2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni committed Sep 24, 2024
1 parent 42df29f commit 7dd7a35
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions terraform/playground/instance.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ resource "aws_eip" "playground" {
}
}

resource "aws_eip" "playground24" {
vpc = true
tags = {
Name = "playground24"
}
}

data "dns_a_record_set" "monitoring" {
host = "monitoring.infra.rust-lang.org"
}
Expand Down Expand Up @@ -103,10 +110,23 @@ resource "aws_eip_association" "playground" {
allocation_id = aws_eip.playground.id
}

resource "aws_eip_association" "playground24" {
network_interface_id = aws_network_interface.playground.id
allocation_id = aws_eip.playground24.id
}

data "aws_route53_zone" "rust_lang_org" {
name = "rust-lang.org"
}

resource "aws_route53_record" "playground2" {
zone_id = data.aws_route53_zone.rust_lang_org.id
name = "play-2.infra.rust-lang.org"
type = "A"
records = [aws_eip.playground24.public_ip]
ttl = 60
}

resource "aws_route53_record" "playground" {
zone_id = data.aws_route53_zone.rust_lang_org.id
name = "play-1.infra.rust-lang.org"
Expand Down Expand Up @@ -170,6 +190,21 @@ data "aws_ami" "ubuntu" {
}
}

data "aws_ami" "ubuntu24" {
most_recent = true
owners = ["099720109477"] # Canonical

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

resource "aws_iam_instance_profile" "playground" {
name = "playground"
role = aws_iam_role.playground.name
Expand Down Expand Up @@ -205,6 +240,36 @@ resource "aws_instance" "playground" {
}
}

resource "aws_instance" "playground24" {
ami = data.aws_ami.ubuntu24.id
instance_type = "c5a.large"
key_name = data.terraform_remote_state.shared.outputs.master_ec2_key_pair
iam_instance_profile = aws_iam_instance_profile.playground.name
ebs_optimized = true
disable_api_termination = true
monitoring = false

root_block_device {
volume_type = "gp3"
volume_size = 100
delete_on_termination = true
}

network_interface {
network_interface_id = aws_network_interface.playground.id
device_index = 0
}

tags = {
Name = "play-24"
}

lifecycle {
# Don't recreate the instance automatically when the AMI changes.
ignore_changes = [ami]
}
}

resource "aws_cloudwatch_metric_alarm" "reboot" {
alarm_name = "playground-status-check"
alarm_description = "Alarms when playground instance is down"
Expand Down

0 comments on commit 7dd7a35

Please sign in to comment.