init: add initial code
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
resource "terraform_data" "docker_compose_deploy" {
|
||||||
|
triggers_replace = [
|
||||||
|
filemd5(var.docker_compose_path),
|
||||||
|
var.infisical_project_token,
|
||||||
|
var.environment,
|
||||||
|
var.vm_ssh_key,
|
||||||
|
var.vm_ip,
|
||||||
|
dirname(var.destination_path),
|
||||||
|
var.ssh_user
|
||||||
|
]
|
||||||
|
|
||||||
|
connection {
|
||||||
|
type = "ssh"
|
||||||
|
user = self.triggers_replace[6]
|
||||||
|
private_key = self.triggers_replace[3]
|
||||||
|
host = self.triggers_replace[4]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
provisioner "file" {
|
||||||
|
source = var.docker_compose_path
|
||||||
|
destination = var.destination_path
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "remote-exec" {
|
||||||
|
inline = [
|
||||||
|
"cd ${dirname(var.destination_path)}",
|
||||||
|
"export INFISICAL_TOKEN=\"${self.triggers_replace[1]}\"",
|
||||||
|
"export INFISICAL_API_URL=\"https://secrets.itlab-ffeks.dnu.edu.ua\"",
|
||||||
|
"export INFISICAL_DISABLE_UPDATE_CHECK=true",
|
||||||
|
"infisical run --env=\"${self.triggers_replace[2]}\" -- docker compose up -d"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "remote-exec" {
|
||||||
|
when = destroy
|
||||||
|
inline = [
|
||||||
|
"cd ${self.triggers_replace[5]}",
|
||||||
|
"export INFISICAL_TOKEN=\"${self.triggers_replace[1]}\"",
|
||||||
|
"export INFISICAL_API_URL=\"https://secrets.itlab-ffeks.dnu.edu.ua\"",
|
||||||
|
"export INFISICAL_DISABLE_UPDATE_CHECK=true",
|
||||||
|
"infisical run --env=\"${self.triggers_replace[2]}\" -- docker compose down || true"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
variable "docker_compose_path" {
|
||||||
|
type = string
|
||||||
|
description = "Path to the local docker-compose.yml file"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "destination_path" {
|
||||||
|
type = string
|
||||||
|
description = "Destination path on the VM where the compose file will be uploaded"
|
||||||
|
default = "/home/debian/docker-compose.yml"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_ip" {
|
||||||
|
type = string
|
||||||
|
description = "Target VM IP address (without CIDR)"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_ssh_key" {
|
||||||
|
type = string
|
||||||
|
description = "SSH private key for VM authentication"
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "infisical_project_token" {
|
||||||
|
type = string
|
||||||
|
description = "Infisical Service Token for project-specific secrets"
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "environment" {
|
||||||
|
type = string
|
||||||
|
description = "The target environment (e.g. staging, prod)"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_user" {
|
||||||
|
type = string
|
||||||
|
description = "SSH user for VM authentication"
|
||||||
|
default = "debian"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user