diff --git a/deploy/aws/.gitignore b/deploy/aws-ec2/.gitignore similarity index 100% rename from deploy/aws/.gitignore rename to deploy/aws-ec2/.gitignore diff --git a/deploy/aws/README.md b/deploy/aws-ec2/README.md similarity index 100% rename from deploy/aws/README.md rename to deploy/aws-ec2/README.md diff --git a/deploy/aws/main.tf b/deploy/aws-ec2/main.tf similarity index 100% rename from deploy/aws/main.tf rename to deploy/aws-ec2/main.tf diff --git a/deploy/aws/outputs.tf b/deploy/aws-ec2/outputs.tf similarity index 100% rename from deploy/aws/outputs.tf rename to deploy/aws-ec2/outputs.tf diff --git a/deploy/aws/templates/startup.sh b/deploy/aws-ec2/templates/startup.sh similarity index 100% rename from deploy/aws/templates/startup.sh rename to deploy/aws-ec2/templates/startup.sh diff --git a/deploy/aws/vars.tf b/deploy/aws-ec2/vars.tf similarity index 100% rename from deploy/aws/vars.tf rename to deploy/aws-ec2/vars.tf diff --git a/deploy/aws/versions.tf b/deploy/aws-ec2/versions.tf similarity index 100% rename from deploy/aws/versions.tf rename to deploy/aws-ec2/versions.tf diff --git a/deploy/aws-lightsail/.gitignore b/deploy/aws-lightsail/.gitignore new file mode 100644 index 000000000..8befe7ad5 --- /dev/null +++ b/deploy/aws-lightsail/.gitignore @@ -0,0 +1,20 @@ +**/.terraform/* + +*.tfstate +*.tfstate.* +.terraform.lock.hcl + +crash.log +crash.*.log + +*.tfvars + +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +*tfplan* + +.terraformrc +terraform.rc diff --git a/deploy/aws-lightsail/README.md b/deploy/aws-lightsail/README.md new file mode 100644 index 000000000..88277c25f --- /dev/null +++ b/deploy/aws-lightsail/README.md @@ -0,0 +1,50 @@ +# terraform-aws-epicyon + +This Terraform plan contains deploying Epicyon on an AWS Lightsail instance + +## Requirements + +| Name | Version | +| ---- | ------- | +| terraform | >=v1.0.7 | +| aws | ~> 4.0 | + +## Providers + +|Name | Version | +| --- | ------- | +| aws | ~> 4.0 | + + +## Resources + +| Name | Type | +|------|------| +| [aws_lightsail_static_ip.epicyon_static_ip](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_static_ip) | resource | +| [aws_lightsail_static_ip_attachment.for_epicyon](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_static_ip_attachment) | resource | +| [aws_lightsail_key_pair.ssh_key_pair](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_key_pair) | resource | +| [aws_lightsail_instance.epicyon](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_instance) | resource | +| [aws_lightsail_domain.epicyon_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_domain) | resource | +| [aws_lightsail_domain_entry.epicyon](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_domain_entry) | resource | +| [null_resource.null_resource_epicyon](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| name | Name of instance. | `string` | `""` | yes | +| blueprint\_id | The ID for a virtual private server image | `string` | `"ubuntu_20_04"` | yes | +| bundle\_id | The bundle of specification information | `string` | `"nano_2_0"` | yes | +| availability\_zone | The Availability Zone in which to create your instance | `string` | `""` | yes | +| create\_static\_ip | Create and attach a statis IP to the instance | `` | `` | no | +| key_pair_name | Key pair name of the Key Pair to use for the instance | `string` | `""` | yes | +| domain | A public domain for Epicyon | `string` | `""` | yes | +| email | Email used to order a certificate from Let's Encrypt | `string` | `""` | yes | + +## Output + +| Name | Description | +| ---- | ----------- | +| domain_name | The URL to epicyon | +| ipv4_address | The public IP address of the epicyon instance | + diff --git a/deploy/aws-lightsail/main.tf b/deploy/aws-lightsail/main.tf new file mode 100644 index 000000000..6d822c159 --- /dev/null +++ b/deploy/aws-lightsail/main.tf @@ -0,0 +1,60 @@ +resource "aws_lightsail_static_ip" "epicyon_static_ip" { + name = "epicyon" +} +resource "aws_lightsail_static_ip_attachment" "for_epicyon" { + static_ip_name = aws_lightsail_static_ip.epicyon_static_ip.id + instance_name = aws_lightsail_instance.epicyon.id +} + +resource "aws_lightsail_key_pair" "ssh_key_pair" { + name = "epicyon_key" + public_key = var.publickey +} + +resource "aws_lightsail_instance" "epicyon" { + name = var.instance_name + availability_zone = "us-east-1a" + blueprint_id = "ubuntu_20_04" + bundle_id = "nano_2_0" + key_pair_name = var.key + +} + +resource "aws_lightsail_domain" "epicyon_domain" { + domain_name = var.domain +} + +resource "aws_lightsail_domain_entry" "epicyon" { + depends_on = [aws_lightsail_static_ip.epicyon_static_ip] + domain_name = aws_lightsail_domain.epicyon_domain.domain_name + name = var.epicyon_sub_domain + type = "A" + target = aws_lightsail_static_ip.epicyon_static_ip.ip_address +} + +resource "null_resource" "null_resource_epicyon" { + depends_on = [aws_lightsail_domain_entry.epicyon] + triggers = { + id = timestamp() + } + connection { + agent = false + type = "ssh" + host = aws_lightsail_static_ip.epicyon_static_ip.ip_address + private_key = file(var.private_key) + user = aws_lightsail_instance.epicyon.username + } + provisioner "file" { + source = "./templates/startup.sh" + destination = "~/startup.sh" + } + provisioner "remote-exec" { + inline = [ + "chmod +x ~/startup.sh", + "export domain=${var.epicyon_sub_domain}", + "export email=${var.email}", + "bash ~/startup.sh" + ] + } +} + diff --git a/deploy/aws-lightsail/outputs.tf b/deploy/aws-lightsail/outputs.tf new file mode 100644 index 000000000..7077d2e7a --- /dev/null +++ b/deploy/aws-lightsail/outputs.tf @@ -0,0 +1,8 @@ +output "aws_lightsail_domain" { + description = "The name of the record" + value = format("https://%s", var.epicyon_sub_domain) +} +output "ipv4_address" { + description = "The instance ip" + value = aws_lightsail_instance.epicyon.public_ip_address +} diff --git a/deploy/aws-lightsail/provider.tf b/deploy/aws-lightsail/provider.tf new file mode 100644 index 000000000..40e31d08f --- /dev/null +++ b/deploy/aws-lightsail/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.0" + } + } +} + +provider "aws" { + access_key = var.aws_access_key + secret_key = var.aws_secret_key + region = var.aws_region +} \ No newline at end of file diff --git a/deploy/aws-lightsail/templates/startup.sh b/deploy/aws-lightsail/templates/startup.sh new file mode 100644 index 000000000..8352dcc24 --- /dev/null +++ b/deploy/aws-lightsail/templates/startup.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash +sleep 1m +sudo apt update -y +sudo apt install -y tor python3-socks imagemagick python3-setuptools python3-cryptography python3-dateutil python3-idna python3-requests python3-flake8 python3-django-timezone-field python3-pyqrcode python3-png python3-bandit libimage-exiftool-perl certbot nginx wget +cd /opt || exit +sudo git clone https://gitlab.com/bashrc2/epicyon +cd /opt/epicyon || exit +sudo adduser --system --home=/opt/epicyon --group epicyon +sudo mkdir /var/www/$domain +sudo mkdir -p /opt/epicyon/accounts/newsmirror +sudo ln -s /opt/epicyon/accounts/newsmirror /var/www/$domain/newsmirror + +sudo tee /tmp/epicyon.service >/dev/null </dev/null <