Skip to main content

google_compute_security_policy resource


A google_compute_security_policy is used to test a Google SecurityPolicy resource

Beta Resource

This resource has beta fields available. To retrieve these fields, include beta: true in the constructor for the resource


describe google_compute_security_policy(project: 'chef-gcp-inspec', name: 'sec-policy') do
  it { should exist }
  its('rules.size') { should cmp 2 }
  its('rules.first.priority') { should cmp '1000' }
  its('rules.first.match.config.src_ip_ranges.first') { should cmp '' }

describe google_compute_security_policy(project: 'chef-gcp-inspec', name: 'nonexistent') do
  it { should_not exist }


Properties that can be accessed from the google_compute_security_policy resource:

Name of the security policy.
The unique identifier for the resource.
A list of rules that belong to this policy. There must always be a default rule (rule with priority 2147483647 and match “*"). If no rules are provided when creating a security policy, a default rule with action “allow” will be added.
A description of the rule.
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 Action to preform when the client connection triggers the rule. Can currently be either “allow” or “deny()” where valid values for status are 403, 404, and 502.
If set to true, the specified action is not enforced.
A match condition that incoming traffic is evaluated against. If it evaluates to true, the corresponding ‘action’ is enforced.

description : A description of the rule.

expr : User defined CEVAL expression. A CEVAL expression is used to specify match criteria such as origin.ip, source.region_code and contents in the request header.

: Textual representation of an expression in Common Expression Language syntax.

: Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression.

: Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.

: Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file.

versioned_expr : Preconfigured versioned expression. If this field is specified, config must also be specified. Available preconfigured expressions along with their requirements are: SRC_IPS_V1 - must specify the corresponding srcIpRange field in config.

config : The configuration options available when specifying versionedExpr. This field must be specified if versionedExpr is specified and cannot be specified if versionedExpr is not specified.

: CIDR IP address range.

GCP Permissions

Ensure the Compute Engine API is enabled for the current project.