Skip to content

googleComputeFirewallPolicyRule

Hierarchical firewall policy rules let you create and enforce a consistent firewall policy across your organization. Rules can explicitly allow or deny connections or delegate evaluation to lower level policies.

For more information see the official documentation

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeFirewallPolicyDefault =
  new google.computeFirewallPolicy.ComputeFirewallPolicy(this, "default", {
    description: "Example Resource",
    parent: "organizations/12345",
    short_name: "my-policy",
  });
const googleComputeFirewallPolicyRuleDefault =
  new google.computeFirewallPolicyRule.ComputeFirewallPolicyRule(
    this,
    "default_1",
    {
      action: "allow",
      description: "Example Resource",
      direction: "EGRESS",
      disabled: false,
      enable_logging: true,
      firewall_policy: googleComputeFirewallPolicyDefault.id,
      match: [
        {
          dest_ip_ranges: ["11.100.0.1/32"],
          layer4_configs: [
            {
              ip_protocol: "tcp",
              ports: [80, 8080],
            },
          ],
        },
      ],
      priority: 9000,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeFirewallPolicyRuleDefault.overrideLogicalId("default");

Argument Reference

The following arguments are supported:

  • action - (Required) The Action to perform when the client connection triggers the rule. Can currently be either "allow" or "deny()" where valid values for status are 403, 404, and 502.

  • direction - (Required) The direction in which this rule applies. Possible values: INGRESS, EGRESS

  • firewallPolicy - (Required) The firewall policy of the resource.

  • match - (Required) A match condition that incoming traffic is evaluated against. If it evaluates to true, the corresponding 'action' is enforced. Structure is documented below.

  • priority - (Required) An integer indicating the priority of a rule in the list. The priority must be a positive value between 0 and 2147483647. Rules are evaluated from highest to lowest priority where 0 is the highest priority and 2147483647 is the lowest prority.

The match block supports:

  • destIpRanges - (Optional) CIDR IP address range. Maximum number of destination CIDR IP ranges allowed is 256.

  • layer4Configs - (Required) Pairs of IP protocols and ports that the rule should match. Structure is documented below.

  • srcIpRanges - (Optional) CIDR IP address range. Maximum number of source CIDR IP ranges allowed is 256.

The layer4Configs block supports:

  • ipProtocol - (Required) The IP protocol to which this rule applies. The protocol type is required when creating a firewall rule. This value can either be one of the following well known protocol strings (tcp, udp, icmp, esp, ah, ipip, sctp), or the IP protocol number.

  • ports - (Optional) An optional list of ports to which this rule applies. This field is only applicable for UDP or TCP protocol. Each entry must be either an integer or a range. If not specified, this rule applies to connections through any port. Example inputs include: ``.


  • description - (Optional) An optional description for this resource.

  • disabled - (Optional) Denotes whether the firewall policy rule is disabled. When set to true, the firewall policy rule is not enforced and traffic behaves as if it did not exist. If this is unspecified, the firewall policy rule will be enabled.

  • enableLogging - (Optional) Denotes whether to enable logging for a particular rule. If logging is enabled, logs will be exported to the configured export destination in Stackdriver. Logs may be exported to BigQuery or Pub/Sub. Note: you cannot enable logging on "goto_next" rules.

  • targetResources - (Optional) A list of network resource URLs to which this rule applies. This field allows you to control which network's VMs get this rule. If this field is left blank, all VMs within the organization will receive the rule.

  • targetServiceAccounts - (Optional) A list of service accounts indicating the sets of instances that are applied with this rule.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format locations/global/firewallPolicies/{{firewallPolicy}}/rules/{{priority}}

  • kind - Type of the resource. Always compute#firewallPolicyRule for firewall policy rules

  • ruleTupleCount - Calculation of the complexity of a single firewall policy rule.

Timeouts

This resource provides the following Timeouts configuration options: configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

FirewallPolicyRule can be imported using any of these accepted formats:

$ terraform import google_compute_firewall_policy_rule.default locations/global/firewallPolicies/{{firewall_policy}}/rules/{{priority}}
$ terraform import google_compute_firewall_policy_rule.default {{firewall_policy}}/{{priority}}