-
Notifications
You must be signed in to change notification settings - Fork 0
/
tunnel.tf
36 lines (33 loc) · 980 Bytes
/
tunnel.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
// Generates a 35-character secret.
resource "random_id" "this" {
byte_length = 35
}
// Creates a new cloudflare-managed tunnel for the VM.
resource "cloudflare_tunnel" "this" {
account_id = var.cloudflare_account_id
name = var.tunnel_name
secret = random_id.this.b64_std
config_src = "cloudflare"
}
// Creates the CNAME record that routes <>-vpn.${var.cloudflare_zone} to the tunnel.
resource "cloudflare_record" "this" {
zone_id = var.cloudflare_zone_id
name = var.tunnel_name
value = "${cloudflare_tunnel.this.cname}"
type = "CNAME"
proxied = true
}
// Creates the configuration for the tunnel.
resource "cloudflare_tunnel_config" "this" {
tunnel_id = cloudflare_tunnel.this.id
account_id = var.cloudflare_account_id
config {
ingress_rule {
hostname = "${cloudflare_record.this.hostname}"
service = "http://${var.service_name}:${var.service_port}"
}
ingress_rule {
service = "http_status:404"
}
}
}