# SSH Key Pair resource "tls_private_key" "ec2_key" { algorithm = "ED25519" } resource "aws_key_pair" "ec2_key" { key_name = "${var.project_name}-key" public_key = tls_private_key.ec2_key.public_key_openssh tags = { Name = "${var.project_name}-key" } } resource "local_file" "private_key" { content = tls_private_key.ec2_key.private_key_openssh filename = "${path.module}/../ssh-keys/${var.project_name}-key.pem" file_permission = "0600" } # EC2 Instance data "aws_ami" "ubuntu" { 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_instance" "gitea" { ami = data.aws_ami.ubuntu.id instance_type = "t3.medium" subnet_id = module.vpc.public_subnets[0] key_name = aws_key_pair.ec2_key.key_name vpc_security_group_ids = [module.security_group.id] iam_instance_profile = aws_iam_instance_profile.ec2_profile.name associate_public_ip_address = true root_block_device { volume_size = 30 volume_type = "gp3" delete_on_termination = true encrypted = true } tags = { Name = "${var.project_name}-gitea" } }