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"]
}
The Argument Reference mentions the option tags. You can use it as follows:
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:To add the tags at the time of the instance creation, include that flag in your statement: