interestedparty333
interestedparty333

Reputation: 2536

How do I enable http traffic for GCE instance templates?

When creating an instance template in Google Compute Engine, how do I enable http traffic for instances created from the template?

I was thinking that providing an http tag would work, but it doesn't seem to do so.

Upvotes: 7

Views: 11414

Answers (5)

Afelaia Timur
Afelaia Timur

Reputation: 69

gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80,tcp:443 

This command should do it

Upvotes: 1

docpuneet
docpuneet

Reputation: 1

If the query is allowing this vm as http or https server then I just used successfully:

cloud compute instances add-tags myvm1 --tags=http-server

Upvotes: 0

One potential solution is to enable http traffic for all of your instances >in that project. To do so, from within GCE command line tools, run:

gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80

I try your command but it doesn't work because the command want the name of the instance:

google130505_student@qwiklabs-gcp-286ef104ac93631b:~$ gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80
Creating firewall...failed.
ERROR: (gcloud.compute.firewall-rules.create) Could not fetch resource:
 - Invalid value for field 'resource.name': 'FIREWALL_RULE'. Must be a match of regex '(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)'
google130505_student@qwiklabs-gcp-286ef104ac93631b:~$ gcloud compute firewall-rules create gclab2 --allow tcp:80
Creating firewall.../Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-286ef104ac93631b/global/firewalls/gclab2].
Creating firewall...done.
NAME    NETWORK  DIRECTION  PRIORITY  ALLOW   DENY
gclab2  default  INGRESS    1000      tcp:80

so the correct command is:

gcloud compute firewall-rules create NAME_OF_YOUR_INSTANCE --allow tcp:80

Upvotes: 1

Faizan
Faizan

Reputation: 1967

The default network in the project comes with default firewall rules "default-allow-http" and "default-allow-https" to allow traffic on port 80 and 443. These rules have a target tag setup as "http-server". When setting up the instance template you can check the box "Allow HTTP traffic" and "Allow HTTPS traffic" from your developer console, by doing that the default firewall rules will be applied to the new instances created through this instance template.

Upvotes: 13

interestedparty333
interestedparty333

Reputation: 2536

The following should work in theory, but in practice, it didn't work.

One potential solution is to enable http traffic for all of your instances in that project. To do so, from within GCE command line tools, run:

gcloud compute firewall-rules create FIREWALL_RULE --allow tcp:80

It's not clear to me that setting the rule for a particular instance template is possible, but hopefully someone will correct me if it is.

Upvotes: 2

Related Questions