This commit is contained in:
+29
-17
@@ -39,26 +39,38 @@ resource "null_resource" "staging_lxc" {
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "sleep 10"
|
||||
command = "sleep 30"
|
||||
}
|
||||
|
||||
# SSH Key Setup
|
||||
provisioner "local-exec" {
|
||||
command = <<-EOT
|
||||
pct enter 200 -- bash -c '
|
||||
apt-get update -qq &&
|
||||
apt-get install -y hugo nginx git rsync curl &&
|
||||
systemctl enable --now nginx &&
|
||||
useradd -m -s /bin/bash deploy 2>/dev/null || true &&
|
||||
mkdir -p /home/deploy/.ssh &&
|
||||
chmod 700 /home/deploy/.ssh &&
|
||||
echo "${var.ssh_public_key}" >> /home/deploy/.ssh/authorized_keys &&
|
||||
chmod 600 /home/deploy/.ssh/authorized_keys &&
|
||||
chown -R deploy:deploy /home/deploy/.ssh &&
|
||||
mkdir -p /var/www/html &&
|
||||
chown -R deploy:deploy /var/www/html &&
|
||||
echo "✅ Staging VM Setup complete!"
|
||||
'
|
||||
EOT
|
||||
command = "mkdir -p ~/.ssh && echo '${var.ssh_private_key}' | base64 -d > ~/.ssh/staging_key && chmod 600 ~/.ssh/staging_key"
|
||||
}
|
||||
|
||||
# Setup via SSH
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"apt-get update -qq",
|
||||
"apt-get install -y hugo nginx git rsync curl",
|
||||
"systemctl enable --now nginx",
|
||||
"useradd -m -s /bin/bash deploy 2>/dev/null || true",
|
||||
"mkdir -p /home/deploy/.ssh",
|
||||
"chmod 700 /home/deploy/.ssh",
|
||||
"echo '${var.ssh_public_key}' >> /home/deploy/.ssh/authorized_keys",
|
||||
"chmod 600 /home/deploy/.ssh/authorized_keys",
|
||||
"chown -R deploy:deploy /home/deploy/.ssh",
|
||||
"mkdir -p /var/www/html",
|
||||
"chown -R deploy:deploy /var/www/html",
|
||||
"echo '✅ Staging VM Setup complete!'"
|
||||
]
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = "root"
|
||||
private_key = var.ssh_private_key
|
||||
host = var.staging_ip
|
||||
timeout = "5m"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user