-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathVagrantfile.multiple_machines
90 lines (80 loc) · 3.07 KB
/
Vagrantfile.multiple_machines
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Copyright 2013 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Usage:
# 1) Launch both instances and then destroy both
# $ vagrant up --provider=google
# $ vagrant destroy
# 2) Launch one instance 'z1c' and then destory the same
# $ vagrant up z1c --provider=google
# $ vagrant destroy z1c
# Customize these global variables
$GOOGLE_PROJECT_ID = "YOUR_GOOGLE_CLOUD_PROJECT_ID"
$GOOGLE_JSON_KEY_LOCATION = "/path/to/your/private-key.json"
$LOCAL_USER = "mitchellh"
$LOCAL_SSH_KEY = "~/.ssh/id_rsa"
# Example Debian provision script
$PROVISION_DEBIAN = <<SCRIPT
uname=$(uname -a)
ver=$(cat /etc/debian_version)
echo "== BEGIN: vagrant provisioning on '${uname}'"
echo "== DEBIAN VERSION: ${ver}"
echo "== UPDATING Debian repositories and packages"
/usr/bin/apt-get update -y -qq > /dev/null 2>&1
/usr/bin/apt-get upgrade -y -qq > /dev/null 2>&1
extip=$(curl -s http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip -H "Metadata-Flavor: Google")
echo "== EXTERNAL IP: ${extip}"
echo "== APPENDING /etc/motd"
d=$(date +%r)
echo "# ${d}" >> /etc/motd
echo "== cat /etc/motd"
cat /etc/motd
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.vm.provision :shell, :inline => $PROVISION_DEBIAN
config.vm.define :z1c do |z1c|
z1c.vm.provider :google do |google, override|
google.google_project_id = $GOOGLE_PROJECT_ID
google.google_json_key_location = $GOOGLE_JSON_KEY_LOCATION
google.zone = "us-central1-c"
override.ssh.username = $LOCAL_USER
override.ssh.private_key_path = $LOCAL_SSH_KEY
google.zone_config "us-central1-c" do |z1c_zone|
z1c_zone.name = "z1c"
z1c_zone.image = "debian-9-stretch-v20180611"
z1c_zone.machine_type = "n1-standard-1"
z1c_zone.zone = "us-central1-c"
z1c_zone.metadata = {"zone" => "US Central 1c"}
end
end
end
config.vm.define :z1f do |z1f|
z1f.vm.provider :google do |google, override|
google.google_project_id = $GOOGLE_PROJECT_ID
google.google_json_key_location = $GOOGLE_JSON_KEY_LOCATION
google.zone = "us-central1-f"
override.ssh.username = $LOCAL_USER
override.ssh.private_key_path = $LOCAL_SSH_KEY
google.zone_config "us-central1-f" do |z1f_zone|
z1f_zone.name = "z1f"
z1f_zone.image = "debian-9-stretch-v20180611"
z1f_zone.machine_type = "n1-standard-2"
z1f_zone.zone = "us-central1-f"
z1f_zone.metadata = {"zone" => "US Central 1f"}
end
end
end
end