forked from jpancoast-kenzan/spinnaker-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instances.tf
118 lines (96 loc) · 3.01 KB
/
instances.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
resource "google_compute_instance" "bastion" {
name = "bastion"
machine_type = "${var.bastion_machine_type}"
zone = "${var.region}-${var.zone}"
tags = ["bastion"]
disk {
image = "${var.ubuntu_image}"
}
connection {
user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key_location)}"
agent = false
}
network_interface {
network = "${google_compute_network.spinnaker-network.name}"
access_config {
nat_ip
}
}
provisioner "remote-exec" {
inline = [
"mkdir -p /tmp/terraform/"
]
}
provisioner "file" {
source = "../files/bastion/"
destination = "/tmp/terraform"
}
provisioner "file" {
source = "${var.ssh_private_key_location}"
destination = "/home/${var.ssh_user}/.ssh/id_rsa"
}
provisioner "remote-exec" {
inline = [
"chmod 0600 /home/${var.ssh_user}/.ssh/id_rsa",
"chmod a+x /tmp/terraform/provision.sh",
"/tmp/terraform/provision.sh ${var.ssh_user}"
]
}
}
resource "google_compute_instance" "spinnaker-and-jenkins" {
name = "spinnaker-and-jenkins"
machine_type = "${var.spinnaker_machine_type}"
zone = "${var.region}-${var.zone}"
tags = ["spinnaker-and-jenkins"]
disk {
image = "marketplace-spinnaker-release/${var.spinnaker_image}"
}
metadata_startup_script = "/opt/spinnaker/install/first_google_boot.sh"
service_account {
scopes = ["compute-rw","storage-rw"]
}
network_interface {
network = "${google_compute_network.spinnaker-network.name}"
access_config {
nat_ip
}
}
connection {
user = "${var.ssh_user}"
bastion_host = "${google_compute_instance.bastion.network_interface.0.access_config.0.nat_ip}"
bastion_user = "${var.ssh_user}"
private_key = "${file(var.ssh_private_key_location)}"
host = "${google_compute_instance.spinnaker-and-jenkins.network_interface.0.address}"
agent = false
}
provisioner "remote-exec" {
inline = [
"mkdir -p /tmp/terraform/"
]
}
provisioner "file" {
source = "../files/gcp/spinnaker-and-jenkins/"
destination = "/tmp/terraform"
}
provisioner "file" {
source = "../files/lib/"
destination = "/tmp/terraform"
}
provisioner "remote-exec" {
inline = [
"chmod a+x /tmp/terraform/provision.sh",
"chmod a+x /tmp/terraform/create_application.sh",
"sudo /tmp/terraform/provision.sh ${google_compute_network.spinnaker-network.name} ${var.jenkins_admin_username} ${var.jenkins_admin_password}",
"/tmp/terraform/create_application.sh ${var.region} ${var.zone} ${google_compute_network.spinnaker-network.name} ${google_compute_firewall.http-7070.name}"
]
}
provisioner "local-exec" {
command = "ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${var.ssh_private_key_location} ${var.ssh_user}@${google_compute_instance.bastion.network_interface.0.access_config.0.nat_ip} 'sed -i.bak -e \"s/<INTERNAL_DNS>/${google_compute_instance.spinnaker-and-jenkins.network_interface.0.address}/\" /home/${var.ssh_user}/.ssh/config'"
}
provisioner "remote-exec" {
inline = [
"sudo rm -rf /tmp/terraform*"
]
}
}