-
Notifications
You must be signed in to change notification settings - Fork 4
/
_main.tf
58 lines (54 loc) · 1.81 KB
/
_main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.1"
}
}
}
provider "docker" {
host = "ssh://zp.dev"
}
locals {
// List of environments and related IP's
envs = {
dev = "45.131.67.82",
test = "45.131.67.83",
prod = "45.131.67.84",
}
compose = base64encode(templatefile("${path.module}/_compose.yml.tmpl", {
// Take value from environment variable VIRTUAL_HOST and change it's 'ENV' part to value from environment variable ENV
VIRTUAL_HOST = replace(var.VIRTUAL_HOST, "ENV", var.ENV),
NETWORK_NAME = var.NETWORK_NAME,
TRANSACTION = var.TRANSACTION,
TOKEN_NAME = var.TOKEN_NAME,
CONTRACT = var.CONTRACT,
RPC_HOST = var.RPC_HOST,
VERSION = var.VERSION,
NETWORK = var.NETWORK,
RELAYER = var.RELAYER,
FAUCET = var.FAUCET,
TOKEN = var.TOKEN,
}))
}
resource "null_resource" "this" {
provisioner "remote-exec" {
inline = [
"set -e",
"mkdir -p ~/wallet",
"docker compose -f ~/wallet/docker-compose-${var.NETWORK}.yml down || true",
"rm -f ~/wallet/docker-compose-${var.NETWORK}.yml",
"sudo bash -c 'echo ${local.compose} | base64 --decode > ~/wallet/docker-compose-${var.NETWORK}.yml'",
"docker network create zeropool-testnet || true",
"docker compose -f ~/wallet/docker-compose-${var.NETWORK}.yml pull",
"docker compose -f ~/wallet/docker-compose-${var.NETWORK}.yml up -d",
]
connection {
type = "ssh"
user = "root" # Replace with your SSH username
private_key = file("~/.ssh/zeropool") # Specify your private key path
host = local.envs[var.ENV] # Replace with your instance's IP or DNS
timeout = "2m" # Set a timeout to wait for the SSH connection
}
}
}