-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
82 lines (67 loc) · 1.73 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
variable "ssh_user" {
type = string
default = "demo-user"
}
variable "demo_dir" {
type = string
default = "ish-ar.io-demo"
}
data "template_file" "bootstrap" {
template = file("templates/bootstrap.sh.tpl")
vars = {
public_key = tls_private_key.demo-instance.public_key_openssh
ssh_user = var.ssh_user
demo_dir = var.demo_dir
}
}
resource "tls_private_key" "demo-instance" {
algorithm = "RSA"
}
resource "local_file" "pem_key" {
content = tls_private_key.demo-instance.private_key_pem
filename = "${var.ssh_user}.pem"
file_permission = 0600
}
resource "google_compute_instance" "demo-instance" {
name = "ish-ar-demo-bcc"
machine_type = "n1-standard-1"
zone = "europe-west2-c"
tags = [
"ish-ar-io-demo",
"bcc-profiler"
]
boot_disk {
initialize_params {
image = "centos-cloud/centos-8"
}
}
scratch_disk {
interface = "SCSI"
}
network_interface {
network = "default"
access_config {}
}
metadata_startup_script = data.template_file.bootstrap.rendered
provisioner "file" {
source = "app/app.py"
destination = "/home/${var.ssh_user}/${var.demo_dir}/app.py"
connection {
type = "ssh"
host = google_compute_instance.demo-instance.network_interface.0.access_config.0.nat_ip
user = var.ssh_user
private_key = file("${var.ssh_user}.pem")
}
}
}
resource "google_compute_firewall" "demo-instance" {
name = "ssh-firewall"
network = "default"
allow {
protocol = "tcp"
ports = ["22"]
}
}
output "connection" {
value = "ssh -i ${var.ssh_user}.pem ${var.ssh_user}@${google_compute_instance.demo-instance.network_interface.0.access_config.0.nat_ip}"
}