Initial commit

This commit is contained in:
Yaser
2026-08-13 19:42:08 +03:30
commit d59bf30ef0
173 changed files with 11702 additions and 0 deletions

120
terraform/main.tf Normal file
View File

@@ -0,0 +1,120 @@
provider "google" {
credentials = file(var.credentials)
project = var.project
region = var.region
}
provider "random" {
}
resource "random_id" "opendax" {
byte_length = 2
}
resource "google_compute_instance" "opendax" {
name = "${var.instance_name}-${random_id.opendax.hex}"
machine_type = var.machine_type
zone = var.zone
allow_stopping_for_update = true
boot_disk {
initialize_params {
image = var.image
type = "pd-ssd"
size = 120
}
}
network_interface {
network = google_compute_network.opendax.name
access_config {
nat_ip = google_compute_address.opendax.address
}
}
service_account {
scopes = ["storage-ro"]
}
tags = ["allow-webhook"]
metadata = {
sshKeys = "${var.ssh_user}:${file(var.ssh_public_key)}"
}
provisioner "local-exec" {
command = "mkdir -p /tmp/upload && rsync -rv --exclude=terraform ../ /tmp/upload/"
}
provisioner "remote-exec" {
inline = [
"mkdir -p /home/${var.ssh_user}/opendax",
]
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
}
}
provisioner "file" {
source = "/tmp/upload/"
destination = "/home/${var.ssh_user}/opendax"
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
}
}
provisioner "remote-exec" {
script = "../bin/install.sh"
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
}
}
provisioner "remote-exec" {
script = "../bin/start.sh"
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
user = var.ssh_user
private_key = file(var.ssh_private_key)
}
}
}
resource "google_compute_firewall" "opendax" {
name = "opendax-firewall-${random_id.opendax.hex}"
network = google_compute_network.opendax.name
allow {
protocol = "tcp"
ports = ["80", "8080", "1337", "443", "22"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["allow-webhook"]
}
resource "google_compute_address" "opendax" {
name = "opendax-ip-${random_id.opendax.hex}"
}
resource "google_compute_network" "opendax" {
name = "opendax-network-${random_id.opendax.hex}"
}

44
terraform/variables.tf Normal file
View File

@@ -0,0 +1,44 @@
variable "credentials" {
type = string
}
variable "ssh_user" {
type = string
description = "Name of the SSH user to use"
default = "app"
}
variable "ssh_public_key" {
type = string
description = "Location of the public RSA key used for SSH-ing onto the main VM"
}
variable "ssh_private_key" {
type = string
description = "Location of the private RSA key used for SSH-ing onto the main VM"
}
variable "project" {
type = string
}
variable "region" {
type = string
}
variable "zone" {
type = string
}
variable "machine_type" {
type = string
}
variable "instance_name" {
type = string
}
variable "image" {
type = string
}