Reputation: 2133
Is there any other way to enable these rules directly with terraform without having to create a separate firewall rule in GCP and then attaching tags to compute engine
Currently I am doing this way
resource "google_compute_firewall" "allow_http" {
name = "allow-http-rule"
network = "default"
allow {
ports = ["80"]
protocol = "tcp"
}
target_tags = ["allow-http"]
priority = 1000
}
and then use this tag in
resource "google_compute_instance" "app" {
...
tags = ["allow-http"]
}
Upvotes: 13
Views: 7918
Reputation: 65
We need to have both firewall rules (http, https)in our network. we can able to see that tags in default network.
it works for me
resource "google_compute_instance" "name" {
....
tags = ["http-server","https-server"]
....
}
Upvotes: 1
Reputation: 140
The Argument Reference mentions the option tags. You can use it as follows:
...
tags = ["http-server","https-server"]
...
In this same way, you can edit these values using: gcloud compute instances add-tags as follows:
To add the tags to an existing VM instance, use this gcloud
command:
gcloud compute instances add-tags [YOUR_INSTANCE_NAME] --tags http-server,https-server
To add the tags at the time of the instance creation, include that flag in your statement:
gcloud compute instances create [YOUR_INSTANCE_NAME] --tags http-server,https-server
Upvotes: 3