Update
This commit is contained in:
26
06-remote-exec-ssh/README.md
Normal file
26
06-remote-exec-ssh/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
%title: Terraform
|
||||
%author: Hubert
|
||||
|
||||
# Terraform : remote_exec / SSH
|
||||
|
||||
<br>
|
||||
|
||||
* remote_exec > local_exec distant (ssh)
|
||||
|
||||
<br>
|
||||
|
||||
variable "host" {}
|
||||
resource "null_resource" "ssh_target" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = var.ssh_user
|
||||
host = var.ssh_host
|
||||
private_key = file("/root/.ssh/id_rsa")
|
||||
}
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"sudo apt update -qq >/dev/null",
|
||||
"sudo apt install -qq -y nginx >/dev/null"
|
||||
]
|
||||
}
|
||||
}
|
40
06-remote-exec-ssh/main.tf
Normal file
40
06-remote-exec-ssh/main.tf
Normal file
@ -0,0 +1,40 @@
|
||||
variable "ssh_host" {}
|
||||
variable "ssh_user" {}
|
||||
variable "ssh_key" {}
|
||||
resource "null_resource" "ssh_target" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = var.ssh_user
|
||||
host = var.ssh_host
|
||||
private_key = file(var.ssh_key)
|
||||
}
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"sudo apt update -qq >/dev/null",
|
||||
"sudo apt install -qq -y nginx >/dev/null"
|
||||
]
|
||||
}
|
||||
provisioner "file" {
|
||||
source = "nginx.conf"
|
||||
destination = "/tmp/default"
|
||||
}
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"sudo cp -a /tmp/default /etc/nginx/sites-available/default",
|
||||
"sudo systemctl restart nginx"
|
||||
]
|
||||
}
|
||||
provisioner "local-exec" {
|
||||
command = "curl ${var.ssh_host}:667"
|
||||
}
|
||||
}
|
||||
output "host" {
|
||||
value = var.ssh_host
|
||||
}
|
||||
output "user" {
|
||||
value = var.ssh_user
|
||||
}
|
||||
output "key" {
|
||||
value = var.ssh_key
|
||||
}
|
||||
|
16
06-remote-exec-ssh/nginx.conf
Normal file
16
06-remote-exec-ssh/nginx.conf
Normal file
@ -0,0 +1,16 @@
|
||||
server {
|
||||
listen 6666 default_server;
|
||||
listen [::]:6666 default_server;
|
||||
|
||||
|
||||
root /var/www/html;
|
||||
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user