I've been referring to this guide: https://cloud.google.com/blog/topics/developers-practitioners/hierarchical-firewall-policy-automation-terraform and, unless I'm reading wrong, it seems to start with the assumption I have a folder setup already.
What I've tried so far is:
- Creating a firewall policy manually via the GCP web console (ie - with a mouse etc)
- Creating a resource block in terraform
- Running terraform import
The resource block:
resource "google_compute_firewall_policy" "fw-policy-name" {
}
The terraform command:
terraform import google_compute_firewall_policy.fw-policy-name fw-policy-name
When I run this I get the following error:
Error: Error when reading or editing ComputeFirewallPolicy "locations/global/firewallPolicies/fw-policy-name": googleapi: Error 400: Invalid value for field 'firewallPolicy': 'firewallPolicies/fw-policy-name'. Must be a match of regex '(firewallPolicies/)?[0-9]{0,20}', invalid
I think (though I'm not sure) that this is suggesting that I use the following for the import command:
terraform import google_compute_firewall_policy.fw-policy-name <FOLDER ID INTEGER>
Is that correct?
I don't know how to either create a new folder, or to check which folder the firewall policy I've created sits within.
Context is I want to have network / firewall settings for compute instance managed via terraform.
The document you reference is talking about setting firewall policies that would apply across a complex multi-project organisation. If you are just wanting to control firewall settings for compute instances, then I'd recommend using network-tags.
When creating instances using the
google_compute_instanceresource type, you would specify one or more network tags using thetagsargument, for exampleweb-server:You then specify firewall rules using the
google_compute_firewallresource: