From b177ed92c43e16f9d5ddaf43d10fae8118d623da Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 09:48:07 -0800 Subject: [PATCH 1/6] Add alias --- modules/aws_ec2_standalone/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/aws_ec2_standalone/main.tf b/modules/aws_ec2_standalone/main.tf index 0cd4334..9b6462f 100644 --- a/modules/aws_ec2_standalone/main.tf +++ b/modules/aws_ec2_standalone/main.tf @@ -9,6 +9,7 @@ terraform { provider "aws" { region = var.aws_region + alias = var.instance_name } data "aws_ami" "this" { From 1cf7c49eee1acfbe901f561ad28795d7d6283a6a Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 09:54:21 -0800 Subject: [PATCH 2/6] static --- modules/aws_ec2_standalone/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/aws_ec2_standalone/main.tf b/modules/aws_ec2_standalone/main.tf index 9b6462f..000ac50 100644 --- a/modules/aws_ec2_standalone/main.tf +++ b/modules/aws_ec2_standalone/main.tf @@ -9,7 +9,7 @@ terraform { provider "aws" { region = var.aws_region - alias = var.instance_name + alias = "provider-aws-ec2-standalone" } data "aws_ami" "this" { From 42cc9f2b73ed14d0ddd84403bf6aafa570bb1e5f Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 10:05:34 -0800 Subject: [PATCH 3/6] CodeExecutor dockerfile --- modules/aws_ec2_standalone/main.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/aws_ec2_standalone/main.tf b/modules/aws_ec2_standalone/main.tf index 000ac50..17ab38f 100644 --- a/modules/aws_ec2_standalone/main.tf +++ b/modules/aws_ec2_standalone/main.tf @@ -97,6 +97,10 @@ resource "aws_instance" "this" { echo FROM tryretool/backend:${var.version_number} > Dockerfile echo CMD ./docker_scripts/start_api.sh >> Dockerfile + # Rewrite CodeExecutor.Dockerfile + echo FROM tryretool/code-executor-service:${var.version_number} > CodeExecutor.Dockerfile + echo CMD bash start.sh >> CodeExecutor.Dockerfile + # Initialize Docker and Retool Installation ./install.sh From c4f5ac8da01c742f31e6e10d353b15f67e3101f3 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 15:43:33 -0800 Subject: [PATCH 4/6] image name variables --- modules/aws_ec2_standalone/main.tf | 4 ++-- modules/aws_ec2_standalone/variables.tf | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/aws_ec2_standalone/main.tf b/modules/aws_ec2_standalone/main.tf index 17ab38f..c664846 100644 --- a/modules/aws_ec2_standalone/main.tf +++ b/modules/aws_ec2_standalone/main.tf @@ -94,11 +94,11 @@ resource "aws_instance" "this" { cd retool-onpremise # Rewrite Dockerfile - echo FROM tryretool/backend:${var.version_number} > Dockerfile + echo FROM ${var.backend_image_name}:${var.version_number} > Dockerfile echo CMD ./docker_scripts/start_api.sh >> Dockerfile # Rewrite CodeExecutor.Dockerfile - echo FROM tryretool/code-executor-service:${var.version_number} > CodeExecutor.Dockerfile + echo FROM ${var.code_executor_image_name}:${var.version_number} > CodeExecutor.Dockerfile echo CMD bash start.sh >> CodeExecutor.Dockerfile # Initialize Docker and Retool Installation diff --git a/modules/aws_ec2_standalone/variables.tf b/modules/aws_ec2_standalone/variables.tf index 93045bb..1f4aa62 100644 --- a/modules/aws_ec2_standalone/variables.tf +++ b/modules/aws_ec2_standalone/variables.tf @@ -16,6 +16,18 @@ variable "instance_name" { description = "EC2 instance name. Defaults to `retool`." } +variable "backend_image_name" { + type = string + default = "tryretool/backend" + description = "Docker Hub image name for the main backend image" +} + +variable "code_executor_image_name" { + type = string + default = "tryretool/code-executor-service" + description = "Docker Hub image name for the code executor image" +} + variable "version_number" { type = string default = "2.106.2" From 65b7ff5ec3fc44340880c7ace5e22b1d9515bb84 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 16:01:15 -0800 Subject: [PATCH 5/6] Add CE VN --- modules/aws_ec2_standalone/variables.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/aws_ec2_standalone/variables.tf b/modules/aws_ec2_standalone/variables.tf index 1f4aa62..6f84109 100644 --- a/modules/aws_ec2_standalone/variables.tf +++ b/modules/aws_ec2_standalone/variables.tf @@ -34,6 +34,12 @@ variable "version_number" { description = "Retool version number. Defaults to `2.106.2`." } +variable "code_executor_version_number" { + type = string + default = "2.106.2" + description = "Retool code executor version number. Defaults to `2.106.2`." +} + variable "vpc_id" { type = string default = null From cf96d90927659e00cb24d65984855914b4ce9502 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 4 Nov 2024 20:20:10 -0800 Subject: [PATCH 6/6] Allow EIP --- modules/aws_ec2_standalone/main.tf | 6 ++++++ modules/aws_ec2_standalone/variables.tf | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/modules/aws_ec2_standalone/main.tf b/modules/aws_ec2_standalone/main.tf index c664846..f88553d 100644 --- a/modules/aws_ec2_standalone/main.tf +++ b/modules/aws_ec2_standalone/main.tf @@ -108,3 +108,9 @@ resource "aws_instance" "this" { docker-compose up -d EOF } + +resource "aws_eip" "ec2_attached_elastic_ip" { + count = var.attach_eip ? 1 : 0 + instance = aws_instance.this.id + vpc = true +} \ No newline at end of file diff --git a/modules/aws_ec2_standalone/variables.tf b/modules/aws_ec2_standalone/variables.tf index 6f84109..1b4672a 100644 --- a/modules/aws_ec2_standalone/variables.tf +++ b/modules/aws_ec2_standalone/variables.tf @@ -166,3 +166,8 @@ variable "egress_rules" { description = "Egress rules for EC2 security group" } +variable "attach_eip" { + type = bool + default = true + description = "Whether to attach an Elastic IP to the EC2 instance." +} \ No newline at end of file