ephemeral-jamulus/main.tf

124 lines
3.1 KiB
Terraform
Raw Normal View History

2021-11-06 03:07:00 +01:00
provider "aws" {
2023-01-05 14:36:42 +01:00
region = "eu-west-2"
2021-11-06 03:07:00 +01:00
}
terraform {
backend "s3" {
bucket = "net.vereto.terraform.states"
key = "jamulus/tf-base.state"
region = "eu-central-1"
}
}
2023-08-08 15:36:06 +02:00
data "aws_region" "current" {}
resource "tls_private_key" "jamulus" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "generated_key" {
key_name = "jamulus-${data.aws_region.current.name}"
public_key = "${tls_private_key.jamulus.public_key_openssh}"
}
2021-11-06 03:07:00 +01:00
resource "aws_instance" "jamulus" {
ami = "${data.aws_ami.image.id}"
2025-04-22 20:01:28 +00:00
instance_type = "c6i.xlarge"
2023-08-08 15:36:06 +02:00
key_name = "${aws_key_pair.generated_key.key_name}"
2023-01-05 14:36:42 +01:00
security_groups = [aws_security_group.ssh.name, aws_security_group.jamulus.name, aws_security_group.node-exporter.name] # Add your own IP to this group
2021-11-06 03:07:00 +01:00
provisioner "local-exec" {
2023-08-08 15:36:06 +02:00
command = <<-EOT
echo '${tls_private_key.jamulus.private_key_openssh}' > ${aws_key_pair.generated_key.key_name} &&
chmod 600 ${aws_key_pair.generated_key.key_name} &&
sleep 30
EOT
}
provisioner "local-exec" {
command = <<-EOT
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u ubuntu \
-i '${self.public_ip},' \
--private-key "${path.module}/${aws_key_pair.generated_key.key_name}" \
jamulus-install.yml --extra-vars 'ec2_id=${self.id}'
EOT
2021-11-06 03:07:00 +01:00
}
tags = {
2025-04-18 20:45:04 +00:00
Name = "jam.vereto.net"
2021-11-06 03:07:00 +01:00
}
}
data "aws_ami" "image" {
most_recent = true
2023-01-23 20:32:03 +01:00
owners = ["self"]
2021-11-06 03:07:00 +01:00
filter {
name = "name"
2023-01-23 20:32:03 +01:00
values = ["vlp-*"]
2021-11-06 03:07:00 +01:00
}
}
2021-11-06 15:18:53 +01:00
data "http" "myip" {
url = "http://ipv4.icanhazip.com"
2021-11-06 03:07:00 +01:00
}
resource "aws_security_group" "ssh" {
name = "jamulus-ssh-access"
description = "Allow SSH inbound traffic"
}
resource "aws_security_group_rule" "allow_all" {
type = "egress"
to_port = 0
protocol = "-1"
from_port = 0
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.ssh.id
}
resource "aws_security_group_rule" "ssh" {
type = "ingress"
to_port = 22
from_port = 22
protocol = "tcp"
2023-01-05 14:36:42 +01:00
cidr_blocks = ["0.0.0.0/0"]
2021-11-06 03:07:00 +01:00
security_group_id = aws_security_group.ssh.id
}
resource "aws_security_group" "jamulus" {
name = "jamulus-port-access"
description = "Allow jamulus inbound traffic"
}
resource "aws_security_group_rule" "jamulus" {
type = "ingress"
to_port = 22124
from_port = 22124
protocol = "udp"
2023-01-05 14:36:42 +01:00
cidr_blocks = ["0.0.0.0/0"]
2021-11-06 03:07:00 +01:00
security_group_id = aws_security_group.jamulus.id
}
resource "aws_security_group" "node-exporter" {
2022-12-07 20:01:31 +00:00
name = "jam-node-exporter-port-access"
description = "Allow jamulus inbound traffic"
}
resource "aws_security_group_rule" "node-exporter" {
type = "ingress"
to_port = 9100
from_port = 9100
protocol = "tcp"
2023-06-15 12:06:19 +00:00
cidr_blocks = ["49.12.40.148/32"]
security_group_id = aws_security_group.node-exporter.id
}
output "jamulus_ip" {
2021-11-06 03:07:00 +01:00
value = "${aws_instance.jamulus.public_ip}"
}
output "broadcast_ip" {
value = "${aws_instance.broadcast.*.public_ip}"
2023-01-05 14:36:42 +01:00
}