mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 13:37:28 +00:00
Added GCP and EC2_AMI
This commit is contained in:
parent
ae7e7431b8
commit
b179e92bb5
11 changed files with 339 additions and 1 deletions
92
terraform/AMI_EC2/ec2.tf
Normal file
92
terraform/AMI_EC2/ec2.tf
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
# Define provider
|
||||||
|
provider "aws" {
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate a TLS private key for EC2 access
|
||||||
|
resource "tls_private_key" "tooljet_key" {
|
||||||
|
algorithm = "RSA"
|
||||||
|
rsa_bits = 2048
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define the key pair for EC2 access
|
||||||
|
resource "aws_key_pair" "tooljet_key" {
|
||||||
|
key_name = "tooljet-key"
|
||||||
|
public_key = tls_private_key.tooljet_key.public_key_openssh # file("~/.ssh/tooljet.pub")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a VPC
|
||||||
|
resource "aws_vpc" "tooljet_vpc" {
|
||||||
|
cidr_block = "10.0.0.0/16"
|
||||||
|
enable_dns_support = true
|
||||||
|
enable_dns_hostnames = true
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetVPC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create an Internet Gateway for the VPC
|
||||||
|
resource "aws_internet_gateway" "tooljet_igw" {
|
||||||
|
vpc_id = aws_vpc.tooljet_vpc.id
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetInternetGateway"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a public subnet
|
||||||
|
resource "aws_subnet" "tooljet_public_subnet" {
|
||||||
|
vpc_id = aws_vpc.tooljet_vpc.id
|
||||||
|
cidr_block = "10.0.1.0/24"
|
||||||
|
availability_zone = var.availability_zone
|
||||||
|
map_public_ip_on_launch = true
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetPublicSubnet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a route table for the public subnet
|
||||||
|
resource "aws_route_table" "tooljet_public_route_table" {
|
||||||
|
vpc_id = aws_vpc.tooljet_vpc.id
|
||||||
|
|
||||||
|
route {
|
||||||
|
cidr_block = "0.0.0.0/0"
|
||||||
|
gateway_id = aws_internet_gateway.tooljet_igw.id
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetPublicRouteTable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Associate the public route table with the public subnet
|
||||||
|
resource "aws_route_table_association" "tooljet_public_subnet_assoc" {
|
||||||
|
subnet_id = aws_subnet.tooljet_public_subnet.id
|
||||||
|
route_table_id = aws_route_table.tooljet_public_route_table.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define the EC2 instance using ToolJet AMI
|
||||||
|
resource "aws_instance" "tooljet_instance" {
|
||||||
|
ami = var.tooljet_ami_id
|
||||||
|
instance_type = var.instance_type
|
||||||
|
key_name = aws_key_pair.tooljet_key.key_name
|
||||||
|
subnet_id = aws_subnet.tooljet_public_subnet.id
|
||||||
|
vpc_security_group_ids = [aws_security_group.tooljet_sg.id]
|
||||||
|
associate_public_ip_address = true
|
||||||
|
availability_zone = var.availability_zone
|
||||||
|
|
||||||
|
# Root EBS volume configuration
|
||||||
|
root_block_device {
|
||||||
|
volume_size = 20
|
||||||
|
volume_type = "gp3"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetAppServer"
|
||||||
|
}
|
||||||
|
|
||||||
|
depends_on = [aws_security_group.tooljet_sg]
|
||||||
|
}
|
||||||
|
|
||||||
21
terraform/AMI_EC2/output.tf
Normal file
21
terraform/AMI_EC2/output.tf
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Outputs
|
||||||
|
output "tooljet_private_key" {
|
||||||
|
value = tls_private_key.tooljet_key.private_key_pem
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
output "instance_ip" {
|
||||||
|
value = aws_instance.tooljet_instance.public_ip
|
||||||
|
}
|
||||||
|
|
||||||
|
output "instance_id" {
|
||||||
|
value = aws_instance.tooljet_instance.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ami_id" {
|
||||||
|
value = var.tooljet_ami_id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ami_description" {
|
||||||
|
value = "Using ToolJet AMI ID: ${var.tooljet_ami_id}"
|
||||||
|
}
|
||||||
27
terraform/AMI_EC2/sg.tf
Normal file
27
terraform/AMI_EC2/sg.tf
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Define the security group
|
||||||
|
resource "aws_security_group" "tooljet_sg" {
|
||||||
|
vpc_id = aws_vpc.tooljet_vpc.id
|
||||||
|
name = "tooljet-sg"
|
||||||
|
description = "Allow SSH, HTTP, HTTPS and ToolJet ports"
|
||||||
|
|
||||||
|
dynamic "ingress" {
|
||||||
|
for_each = var.ingress_ports
|
||||||
|
content {
|
||||||
|
from_port = ingress.value
|
||||||
|
to_port = ingress.value
|
||||||
|
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"]
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Name = "TooljetSecurityGroup"
|
||||||
|
}
|
||||||
|
}
|
||||||
8
terraform/AMI_EC2/terraform.tfvars
Normal file
8
terraform/AMI_EC2/terraform.tfvars
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
region = ""
|
||||||
|
availability_zone = ""
|
||||||
|
instance_type = ""
|
||||||
|
tooljet_ami_id = ""
|
||||||
|
ingress_ports = [22, 80, 443, 3000]
|
||||||
|
|
||||||
|
# terraform output -raw tooljet_private_key_pem > tooljet-key.pem
|
||||||
|
# chmod 600 tooljet-key.pem
|
||||||
29
terraform/AMI_EC2/variables.tf
Normal file
29
terraform/AMI_EC2/variables.tf
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
variable "region" {
|
||||||
|
description = "AWS region"
|
||||||
|
type = string
|
||||||
|
default = "us-west-2"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "availability_zone" {
|
||||||
|
description = "Availability zone for the subnet and instance"
|
||||||
|
type = string
|
||||||
|
default = "us-west-2a"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_type" {
|
||||||
|
description = "EC2 instance type"
|
||||||
|
type = string
|
||||||
|
default = "t3.medium" # Recommended for ToolJet
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "tooljet_ami_id" {
|
||||||
|
description = "ToolJet AMI ID - contact ToolJet team for the specific AMI ID in your region"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ingress_ports" {
|
||||||
|
default = [22, 80, 443, 3000]
|
||||||
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ resource "aws_instance" "tooljet_instance" {
|
||||||
depends_on = [aws_security_group.tooljet_sg]
|
depends_on = [aws_security_group.tooljet_sg]
|
||||||
# Root EBS volume configuration
|
# Root EBS volume configuration
|
||||||
root_block_device {
|
root_block_device {
|
||||||
volume_size = 16
|
volume_size = 20
|
||||||
volume_type = "gp3"
|
volume_type = "gp3"
|
||||||
}
|
}
|
||||||
# Load the shell script using file() function
|
# Load the shell script using file() function
|
||||||
|
|
|
||||||
12
terraform/GCP/install_tooljet.sh
Normal file
12
terraform/GCP/install_tooljet.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
sudo apt upgrade -y
|
||||||
|
sudo apt update -y
|
||||||
|
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
|
||||||
|
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||||
|
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
|
sudo apt update -y
|
||||||
|
|
||||||
|
sudo apt install -y docker-ce
|
||||||
|
sudo systemctl start docker
|
||||||
|
sudo systemctl enable docker
|
||||||
85
terraform/GCP/instance.tf
Normal file
85
terraform/GCP/instance.tf
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
# Define provider
|
||||||
|
provider "google" {
|
||||||
|
project = var.project_id
|
||||||
|
region = var.region
|
||||||
|
zone = var.zone
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate a TLS private key for SSH access
|
||||||
|
resource "tls_private_key" "tooljet_key" {
|
||||||
|
algorithm = "RSA"
|
||||||
|
rsa_bits = 2048
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create VPC network
|
||||||
|
resource "google_compute_network" "tooljet_vpc" {
|
||||||
|
name = "tooljet-vpc"
|
||||||
|
auto_create_subnetworks = false
|
||||||
|
description = "VPC network for Tooljet application"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create subnet
|
||||||
|
resource "google_compute_subnetwork" "tooljet_subnet" {
|
||||||
|
name = "tooljet-subnet"
|
||||||
|
ip_cidr_range = "10.0.1.0/24"
|
||||||
|
region = var.region
|
||||||
|
network = google_compute_network.tooljet_vpc.id
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create firewall rules
|
||||||
|
resource "google_compute_firewall" "tooljet_firewall" {
|
||||||
|
name = "tooljet-firewall"
|
||||||
|
network = google_compute_network.tooljet_vpc.name
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = var.firewall_ports
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
target_tags = ["tooljet-server"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the latest Ubuntu image
|
||||||
|
data "google_compute_image" "ubuntu" {
|
||||||
|
family = "ubuntu-2404-lts-amd64"
|
||||||
|
project = "ubuntu-os-cloud"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create the compute instance
|
||||||
|
resource "google_compute_instance" "tooljet_instance" {
|
||||||
|
name = "tooljet-instance"
|
||||||
|
machine_type = var.machine_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
|
tags = ["tooljet-server"]
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image = data.google_compute_image.ubuntu.self_link
|
||||||
|
size = 20
|
||||||
|
type = "pd-standard"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = google_compute_network.tooljet_vpc.id
|
||||||
|
subnetwork = google_compute_subnetwork.tooljet_subnet.id
|
||||||
|
|
||||||
|
access_config {
|
||||||
|
// Ephemeral public IP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
ssh-keys = "${var.ssh_username}:${tls_private_key.tooljet_key.public_key_openssh}"
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata_startup_script = file("${path.module}/install_tooljet.sh")
|
||||||
|
|
||||||
|
service_account {
|
||||||
|
scopes = ["cloud-platform"]
|
||||||
|
}
|
||||||
|
|
||||||
|
depends_on = [google_compute_firewall.tooljet_firewall]
|
||||||
|
}
|
||||||
25
terraform/GCP/outputs.tf
Normal file
25
terraform/GCP/outputs.tf
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
output "tooljet_private_key" {
|
||||||
|
description = "The private SSH key for accessing the instance"
|
||||||
|
value = tls_private_key.tooljet_key.private_key_pem
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
output "instance_ip" {
|
||||||
|
description = "The external IP address of the instance"
|
||||||
|
value = google_compute_instance.tooljet_instance.network_interface[0].access_config[0].nat_ip
|
||||||
|
}
|
||||||
|
|
||||||
|
output "instance_id" {
|
||||||
|
description = "The ID of the compute instance"
|
||||||
|
value = google_compute_instance.tooljet_instance.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "instance_name" {
|
||||||
|
description = "The name of the compute instance"
|
||||||
|
value = google_compute_instance.tooljet_instance.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ssh_command" {
|
||||||
|
description = "SSH command to connect to the instance"
|
||||||
|
value = "ssh -i private_key.pem ${var.ssh_username}@${google_compute_instance.tooljet_instance.network_interface[0].access_config[0].nat_ip}"
|
||||||
|
}
|
||||||
5
terraform/GCP/terraform.tfvars
Normal file
5
terraform/GCP/terraform.tfvars
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
project_id = "<your-project-id>"
|
||||||
|
region = "us-central1"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
machine_type = "e2-medium"
|
||||||
|
ssh_username = "ubuntu"
|
||||||
34
terraform/GCP/variables.tf
Normal file
34
terraform/GCP/variables.tf
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
variable "project_id" {
|
||||||
|
description = "The GCP project ID"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
description = "The GCP region"
|
||||||
|
type = string
|
||||||
|
default = "us-central1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "zone" {
|
||||||
|
description = "The GCP zone"
|
||||||
|
type = string
|
||||||
|
default = "us-central1-a"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "machine_type" {
|
||||||
|
description = "The machine type for the compute instance"
|
||||||
|
type = string
|
||||||
|
default = "e2-medium"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "firewall_ports" {
|
||||||
|
description = "List of ports for firewall ingress"
|
||||||
|
type = list(string)
|
||||||
|
default = ["22", "80", "443", "3000"]
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_username" {
|
||||||
|
description = "Username for SSH access"
|
||||||
|
type = string
|
||||||
|
default = "ubuntu"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue