-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
67 lines (61 loc) · 1.74 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
59
60
61
62
63
64
65
66
67
provider "linode" {
token = var.linode_token
}
resource "random_string" "tunnel_label" {
length = 6
special = false
upper = false
min_lower = 3
min_numeric = 3
}
resource "linode_instance" "tunnel" {
region = var.region
type = "g6-nanode-1"
label = "tunnel-${random_string.tunnel_label.result}"
image = "linode/ubuntu18.04"
authorized_keys = ["${chomp(file(var.ssh_key))}"]
}
resource "null_resource" "tunnel_connection" {
depends_on = [linode_instance.tunnel]
provisioner "local-exec" {
command = "chmod +x scripts/connect.sh; ./scripts/connect.sh"
environment = {
HOST = linode_instance.tunnel.ip_address
USER = var.ssh_user
}
}
}
resource "null_resource" "test_tunnel" {
depends_on = [null_resource.tunnel_connection]
provisioner "local-exec" {
environment = {
all_proxy = "socks://127.0.0.1:8888/"
}
command = "sleep 10; curl -s --socks5-hostname $all_proxy -L http://ipinfo.io/json"
}
}
resource "null_resource" "set_osx_proxy" {
depends_on = [null_resource.test_tunnel]
count = var.set_osx_proxy == true ? 1 : 0
provisioner "local-exec" {
command = "chmod +x scripts/proxy_status.sh; ./scripts/proxy_status.sh"
environment = {
HOST = linode_instance.tunnel.ip_address
USER = var.ssh_user
}
}
provisioner "local-exec" {
when = destroy
command = "networksetup -setsocksfirewallproxystate wi-fi off; rm nohup.out"
}
}
resource "null_resource" "open_browser" {
depends_on = [null_resource.test_tunnel]
count = var.open_browser == true ? 1 : 0
provisioner "local-exec" {
environment = {
all_proxy = "socks://127.0.0.1:8888/"
}
command = var.browser_command
}
}