diff --git a/doc/selfhosting.md b/doc/selfhosting.md index eae60b3..2c2ff35 100644 --- a/doc/selfhosting.md +++ b/doc/selfhosting.md @@ -135,7 +135,6 @@ Add to `.env` the following contents: AMI_NAME=riju-20210711223158 AWS_REGION=us-west-1 S3_BUCKET=yourname-riju -SSH_KEY_NAME=something ``` ### AMI\_NAME diff --git a/tf/ami.tf b/tf/ami.tf index ec5f90c..89dd194 100644 --- a/tf/ami.tf +++ b/tf/ami.tf @@ -8,26 +8,3 @@ data "aws_ami" "server" { values = [data.external.env.result.AMI_NAME] } } - -data "aws_ami" "ubuntu" { - count = local.ssh_key_available ? 1 : 0 - - owners = ["099720109477"] - - filter { - name = "name" - values = ["ubuntu/images/hvm-ssd/ubuntu-*-21.04-amd64-server-*"] - } - - filter { - name = "root-device-type" - values = ["ebs"] - } - - filter { - name = "virtualization-type" - values = ["hvm"] - } - - most_recent = true -} diff --git a/tf/backup.tf b/tf/backup.tf deleted file mode 100644 index e887d26..0000000 --- a/tf/backup.tf +++ /dev/null @@ -1,34 +0,0 @@ -resource "aws_backup_vault" "riju" { - name = "riju" -} - -resource "aws_backup_plan" "riju" { - name = "riju" - - rule { - rule_name = "riju" - target_vault_name = aws_backup_vault.riju.name - schedule = "cron(0 5 ? * * *)" - - lifecycle { - delete_after = 3 - } - - recovery_point_tags = { - BillingCategory = "Riju" - BillingSubcategory = "Riju:Backup:DevServer" - } - } -} - -resource "aws_backup_selection" "riju" { - count = local.ssh_key_available ? 1 : 0 - - iam_role_arn = aws_iam_role.backup.arn - name = "riju" - plan_id = aws_backup_plan.riju.id - - resources = [ - aws_instance.dev_server[count.index].arn, - ] -} diff --git a/tf/ec2.tf b/tf/ec2.tf deleted file mode 100644 index be9edef..0000000 --- a/tf/ec2.tf +++ /dev/null @@ -1,102 +0,0 @@ -resource "aws_security_group" "dev_server" { - count = local.ssh_key_available ? 1 : 0 - - name = "riju-dev-server" - description = "Security group for Riju dev server" - - ingress { - description = "SSH" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - ingress { - description = "HTTP" - from_port = 6119 - to_port = 6119 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - } - - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - } -} - -resource "aws_instance" "dev_server" { - count = local.ssh_key_available ? 1 : 0 - - ami = data.aws_ami.ubuntu[count.index].id - instance_type = "t3.2xlarge" - ebs_optimized = true - - security_groups = [aws_security_group.dev_server[count.index].name] - - iam_instance_profile = aws_iam_instance_profile.dev_server.name - key_name = data.external.env.result.SSH_KEY_NAME - - root_block_device { - volume_size = 8 - volume_type = "gp3" - - tags = merge(local.tags, { - Name = "Riju dev server root" - BillingSubcategory = "Riju:EBS:DevServer" - }) - } - - tags = { - Name = "Riju dev server" - BillingSubcategory = "Riju:EC2:DevServer" - } - - lifecycle { - ignore_changes = [ - ami, - instance_state, - security_groups, # legacy - ] - } -} - -resource "aws_ebs_volume" "dev_server_data" { - count = local.ssh_key_available ? 1 : 0 - - size = 256 - type = "sc1" - - availability_zone = aws_instance.dev_server[count.index].availability_zone - - tags = { - Name = "Riju dev server data" - BillingSubcategory = "Riju:EBS:DevServer" - } -} - -resource "aws_volume_attachment" "dev_server_data" { - count = local.ssh_key_available ? 1 : 0 - - device_name = "/dev/sdh" - volume_id = aws_ebs_volume.dev_server_data[count.index].id - instance_id = aws_instance.dev_server[count.index].id -} - -resource "aws_eip" "dev_server" { - count = local.ssh_key_available ? 1 : 0 - - tags = { - Name = "Riju dev server" - BillingSubcategory = "Riju:EIP" - } -} - -resource "aws_eip_association" "dev_server" { - count = local.ssh_key_available ? 1 : 0 - instance_id = aws_instance.dev_server[count.index].id - allocation_id = aws_eip.dev_server[count.index].id -} diff --git a/tf/main.tf b/tf/main.tf index 79070e3..3bdc9fe 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -24,8 +24,7 @@ locals { BillingCategory = "Riju" } - ami_available = lookup(data.external.env.result, "AMI_NAME", "") != "" ? true : false - ssh_key_available = lookup(data.external.env.result, "SSH_KEY_NAME", "") != "" ? true : false + ami_available = lookup(data.external.env.result, "AMI_NAME", "") != "" ? true : false } provider "aws" {