Reputation: 21
I created a MongoDB GCE instance using Vagrantfile. Then enabled 'Allow HTTP traffic' and added protocol:port tcp:27017 using the console. Everything works fine, but I want to avoid using the console. Can anyone help me enable 'Allow HTTP traffic' and add 'port tcp:27017' with Vagrantfile?
Here is part of my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
google.google_project_id = "projectxx"
google.google_client_email = "[email protected]"
google.google_json_key_location = "~/gcp_service_keys/xx.json"
google.name = "namex"
google.zone = "us-central1-c"
google.image_family = 'ubuntu-1804-lts'
override.ssh.username = "me"
override.ssh.private_key_path = "~/.ssh/gce"
end
config.vm.provision :shell, path: "install.sh"
end
Upvotes: 2
Views: 172
Reputation: 327
you will have to add a firewall rule and add a "target tag" on it e.g. test-1, then on your vagrant file you will have to use this line google.tags = ['test-1']
Vagrant.configure("2") do |config| config.vm.box = "google/gce"
config.ssh.forward_agent = true
config.vm.provider :google do |google, override|
google.google_project_id = "projectxx"
google.google_client_email = "[email protected]"
google.google_json_key_location = "~/gcp_service_keys/xx.json"
google.name = "namex"
google.zone = "us-central1-c"
google.image_family = 'ubuntu-1804-lts'
google.tags = ['test-1'] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
override.ssh.username = "me"
override.ssh.private_key_path = "~/.ssh/gce"
end
config.vm.provision :shell, path: "install.sh"
end
Upvotes: 2
Reputation: 11236
Did you check the vagrant documentation on forwarded ports?
Should be something like:
Vagrant.configure("2") do |config|
config.vm.box = "google/gce"
config.vm.network "forwarded_port", guest: 80, host: 27017
#... rest of your config
end
Upvotes: 0