Google Cloud - google_compute_firewall

Hi guys,

Im use Terraform to create firewall rules in my project in GCP.

But, it’s possible create rules by console GCP, and Terraform can’t delete this rule.

Exist a way delete rules create by console using terraform?

Thanks!

There isn’t a clean way currently to do it in only a single Terraform run. You could import the existing rule into your state first and then terraform destroy it, or you could use a null resource (or something like the gcloud module) to shell out to gcloud to delete it.

1 Like

Hi,

Thanks for u response.

I’ll try to make your suggestion.

Thanks for your help. :star_struck:

How about if I need to use existing ‘google_compute_firewall’ rules into terraform to create a VM instance.

I think when you will import the firewall rule using ‘import’ it will be deleted when you will run destroy command.
My use case is to re-use those existing firewall rules again and again for many purposes.

I tried to use them as data source but getting error as below :-

│ Error: Invalid data source

│ on main.tf line 10, in data “google_compute_firewall” “allow-ssh”:
│ 10: data “google_compute_firewall” “allow-ssh” {

│ The provider hashicorp/google does not support data source “google_compute_firewall”.

│ Did you intend to use the managed resource type “google_compute_firewall”? If so, declare this using a “resource” block instead of a “data” block.